From patchwork Mon Apr 27 23:55:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 6284861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F1CAE9F1C2 for ; Tue, 28 Apr 2015 00:02:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C40A42037E for ; Tue, 28 Apr 2015 00:02:34 +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 953F120304 for ; Tue, 28 Apr 2015 00:02:33 +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 1Ymsvy-0007pj-Fb; Mon, 27 Apr 2015 23:59:30 +0000 Received: from mail-pd0-x22e.google.com ([2607:f8b0:400e:c02::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ymstv-0006sW-KY for linux-arm-kernel@lists.infradead.org; Mon, 27 Apr 2015 23:57:25 +0000 Received: by pdbqa5 with SMTP id qa5so144729426pdb.1 for ; Mon, 27 Apr 2015 16:57:02 -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=8pptM6NtQHycqSnDLXIxOJBHOAyqSb2mVYWsJdIm8kM=; b=RR6PGMAZ6Sb9ImIECsvnxjFCVTse+wFz54VLqottL2B9KgW6ipgZ4cMqwUWNOGSLmb jQROMqxc2301Dvbo7D+dyHLLqWlvCVrzyAT6leG/9Noehmsy93yW/nlvyNmvyF1WhOKF 1z2FfSArB/Og3wh4WBjeYBEurqsWsvPNNbwQkxgpkX6pqviDPK1cPfq41HQn3zE3DjKC O3nOD+rOYQXV6eD9yityfM+Sk7hnFJwXQdepx8c6yWrQGHP3lqFyjS2BBu/34hMFcLCt OHMb/b5g/D6pEvKW5t+VhpdGGJ7/GKRsPBzNEYkAclO/yziui1opjcD/i6jWikaD89i6 ghDA== X-Received: by 10.70.27.196 with SMTP id v4mr4501595pdg.122.1430179022125; Mon, 27 Apr 2015 16:57:02 -0700 (PDT) Received: from fangorn.rup.mentorg.com (nat-min.mentorg.com. [139.181.32.34]) by mx.google.com with ESMTPSA id pv2sm20428375pbb.12.2015.04.27.16.56.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Apr 2015 16:57:01 -0700 (PDT) From: Dmitry Eremin-Solenikov To: Russell King , Daniel Mack , Robert Jarzmik , Linus Walleij , Alexandre Courbot , Wolfram Sang , Dmitry Torokhov , Bryan Wu , Richard Purdie , Samuel Ortiz , Lee Jones , Mark Brown , Jingoo Han , Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Liam Girdwood , Andrea Adami Subject: [PATCH v2 06/17] video: lcd: add LoCoMo LCD driver Date: Tue, 28 Apr 2015 02:55:43 +0300 Message-Id: <1430178954-11138-7-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430178954-11138-1-git-send-email-dbaryshkov@gmail.com> References: <1430178954-11138-1-git-send-email-dbaryshkov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150427_165723_782315_ABC1DDAA X-CRM114-Status: GOOD ( 17.70 ) X-Spam-Score: -0.8 (/) Cc: linux-arm-kernel@lists.infradead.org, linux-fbdev@vger.kernel.org, alsa-devel@alsa-project.org, linux-spi@vger.kernel.org, linux-gpio@vger.kernel.org, linux-i2c@vger.kernel.org, linux-input@vger.kernel.org, linux-leds@vger.kernel.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=unavailable 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 LoCoMo has some special handling for TFT screens attached to Collie and Poodle. Implement that as a separate driver. Signed-off-by: Dmitry Eremin-Solenikov --- drivers/video/backlight/Kconfig | 10 ++ drivers/video/backlight/Makefile | 1 + drivers/video/backlight/locomo_lcd.c | 285 +++++++++++++++++++++++++++++++++++ 3 files changed, 296 insertions(+) create mode 100644 drivers/video/backlight/locomo_lcd.c diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig index 6c093e2..b2f995c 100644 --- a/drivers/video/backlight/Kconfig +++ b/drivers/video/backlight/Kconfig @@ -48,6 +48,16 @@ config LCD_LMS283GF05 SPI driver for Samsung LMS283GF05. This provides basic support for powering the LCD up/down through a sysfs interface. +config LCD_LOCOMO + tristate "Sharp LOCOMO LCD Driver" + depends on MFD_LOCOMO + select IIO + help + If you have a Sharp Zaurus SL-5500 (Collie) or SL-5600 (Poodle) say y to + enable the LCD driver. The panel starts up in power + off state, so you need this driver in order to see any + output. + config LCD_LTV350QV tristate "Samsung LTV350QV LCD Panel" depends on SPI_MASTER diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile index 2de73d2..686cf1a 100644 --- a/drivers/video/backlight/Makefile +++ b/drivers/video/backlight/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.o obj-$(CONFIG_LCD_LD9040) += ld9040.o obj-$(CONFIG_LCD_LMS283GF05) += lms283gf05.o obj-$(CONFIG_LCD_LMS501KF03) += lms501kf03.o +obj-$(CONFIG_LCD_LOCOMO) += locomo_lcd.o obj-$(CONFIG_LCD_LTV350QV) += ltv350qv.o obj-$(CONFIG_LCD_PLATFORM) += platform_lcd.o obj-$(CONFIG_LCD_S6E63M0) += s6e63m0.o diff --git a/drivers/video/backlight/locomo_lcd.c b/drivers/video/backlight/locomo_lcd.c new file mode 100644 index 0000000..dc316cb --- /dev/null +++ b/drivers/video/backlight/locomo_lcd.c @@ -0,0 +1,285 @@ +/* + * 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 +#include + +struct locomo_lcd { + struct regmap *regmap; + struct platform_device *dev; + struct locomo_lcd_platform_data *data; + int power; + struct iio_channel *comadj; + struct gpio_desc *vsha, *vshd, *vee, *mod; +}; + +static void locomo_lcd_on(struct locomo_lcd *lcd) +{ + gpiod_set_value(lcd->vsha, 1); + usleep_range(2000, 3000); + + gpiod_set_value(lcd->vshd, 1); + usleep_range(2000, 3000); + + iio_write_channel_raw(lcd->comadj, lcd->data->comadj); + usleep_range(5000, 6000); + + gpiod_set_value(lcd->vee, 1); + usleep_range(10000, 11000); + + /* TFTCRST | CPSOUT=0 | CPSEN */ + regmap_write(lcd->regmap, LOCOMO_TC, 0x01); + + /* Set CPSD */ + regmap_write(lcd->regmap, LOCOMO_CPSD, 6); + + /* TFTCRST | CPSOUT=0 | CPSEN */ + regmap_write(lcd->regmap, LOCOMO_TC, 0x04 | 0x01); + usleep_range(10000, 11000); + + gpiod_set_value(lcd->mod, 1); +} + +static void locomo_lcd_off(struct locomo_lcd *lcd) +{ + /* TFTCRST=1 | CPSOUT=1 | CPSEN = 0 */ + regmap_write(lcd->regmap, LOCOMO_TC, 0x06); + usleep_range(1000, 2000); + + gpiod_set_value(lcd->vsha, 0); + msleep(110); + + gpiod_set_value(lcd->vee, 0); + msleep(700); + + iio_write_channel_raw(lcd->comadj, 0); + usleep_range(5000, 6000); + + /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */ + regmap_write(lcd->regmap, LOCOMO_TC, 0); + gpiod_set_value(lcd->mod, 0); + gpiod_set_value(lcd->vshd, 0); +} + +static void locomo_lcd_program_adsync(struct locomo_lcd *lcd) +{ + regmap_write(lcd->regmap, LOCOMO_ASD, + 6 + 8 + 320 + 30 - 10); + regmap_update_bits(lcd->regmap, LOCOMO_ASD, + 0x8000, + 0x8000); + + regmap_write(lcd->regmap, LOCOMO_HSD, + 6 + 8 + 320 + 30 - 10 - 128 + 4); + regmap_update_bits(lcd->regmap, LOCOMO_HSD, + 0x8000, + 0x8000); + + regmap_write(lcd->regmap, LOCOMO_HSC, 128 / 8); + + /* XON */ + regmap_write(lcd->regmap, LOCOMO_TADC, 0x80); + usleep_range(1000, 1100); + + /* CLK9MEN */ + regmap_update_bits(lcd->regmap, LOCOMO_TADC, + 0x10, + 0x10); + usleep_range(100, 200); +} + +static void locomo_lcd_disable_adsync(struct locomo_lcd *lcd) +{ + /* ADSTART */ + regmap_write(lcd->regmap, LOCOMO_ASD, 0x00); + + /* 18MHz clock off*/ + regmap_write(lcd->regmap, LOCOMO_TADC, 0x00); +} + +int locomo_lcd_set_power(struct lcd_device *ldev, int power) +{ + struct locomo_lcd *lcd = lcd_get_data(ldev); + + dev_dbg(&ldev->dev, "LCD power %d (is %d)\n", power, lcd->power); + + if (!power && lcd->power) + locomo_lcd_on(lcd); + + if (power && !lcd->power) + locomo_lcd_off(lcd); + + lcd->power = power; + + return 0; +} + +static int locomo_lcd_get_power(struct lcd_device *ldev) +{ + struct locomo_lcd *lcd = lcd_get_data(ldev); + + return lcd->power; +} + +static struct lcd_ops locomo_lcd_ops = { + .set_power = locomo_lcd_set_power, + .get_power = locomo_lcd_get_power, +}; + +#ifdef CONFIG_PM_SLEEP +static int locomo_lcd_suspend(struct device *dev) +{ + struct lcd_device *ldev = dev_get_drvdata(dev); + struct locomo_lcd *lcd = lcd_get_data(ldev); + + locomo_lcd_off(lcd); + + locomo_lcd_disable_adsync(lcd); + + return 0; +} + +static int locomo_lcd_resume(struct device *dev) +{ + struct lcd_device *ldev = dev_get_drvdata(dev); + struct locomo_lcd *lcd = lcd_get_data(ldev); + + locomo_lcd_program_adsync(lcd); + + if (!lcd->power) + locomo_lcd_on(lcd); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(locomo_lcd_pm, locomo_lcd_suspend, locomo_lcd_resume); +#define LOCOMOLCD_PM (&locomo_lcd_pm) +#else +#define LOCOMOLCD_PM NULL +#endif + +static int locomo_lcd_probe(struct platform_device *dev) +{ + struct lcd_device *lcd_dev; + struct locomo_lcd *lcd; + int rc; + + lcd = devm_kmalloc(&dev->dev, sizeof(struct locomo_lcd), GFP_KERNEL); + if (!lcd) + return -ENOMEM; + + lcd->dev = dev; + lcd->power = FB_BLANK_NORMAL; + + lcd->regmap = dev_get_regmap(dev->dev.parent, NULL); + if (!lcd->regmap) + return -ENODEV; + + lcd->data = dev_get_platdata(&dev->dev); + if (!lcd->data) + return -EINVAL; + + lcd->vsha = devm_gpiod_get(&dev->dev, "VSHA", GPIOD_OUT_LOW); + if (IS_ERR(lcd->vsha)) + return PTR_ERR(lcd->vsha); + + lcd->vshd = devm_gpiod_get(&dev->dev, "VSHD", GPIOD_OUT_LOW); + if (IS_ERR(lcd->vshd)) + return PTR_ERR(lcd->vshd); + + lcd->vee = devm_gpiod_get(&dev->dev, "Vee", GPIOD_OUT_LOW); + if (IS_ERR(lcd->vee)) + return PTR_ERR(lcd->vee); + + lcd->mod = devm_gpiod_get(&dev->dev, "MOD", GPIOD_OUT_LOW); + if (IS_ERR(lcd->mod)) + return PTR_ERR(lcd->mod); + + lcd->comadj = iio_channel_get(&dev->dev, "comadj"); + if (IS_ERR(lcd->comadj)) { + rc = PTR_ERR(lcd->comadj); + if (rc == -ENODEV) + rc = -EPROBE_DEFER; + + return rc; + } + + locomo_lcd_program_adsync(lcd); + + lcd_dev = devm_lcd_device_register(&dev->dev, "locomo", &dev->dev, lcd, + &locomo_lcd_ops); + if (IS_ERR(lcd_dev)) { + rc = PTR_ERR(lcd_dev); + goto err; + } + + platform_set_drvdata(dev, lcd_dev); + + lcd_set_power(lcd_dev, FB_BLANK_UNBLANK); + + return 0; + +err: + locomo_lcd_disable_adsync(lcd); + iio_channel_release(lcd->comadj); + + return rc; +} + +static int locomo_lcd_remove(struct platform_device *dev) +{ + struct lcd_device *ldev = platform_get_drvdata(dev); + struct locomo_lcd *lcd = lcd_get_data(ldev); + + locomo_lcd_off(lcd); + + locomo_lcd_disable_adsync(lcd); + + iio_channel_release(lcd->comadj); + + return 0; +} + +static void locomo_lcd_shutdown(struct platform_device *dev) +{ + struct lcd_device *ldev = platform_get_drvdata(dev); + struct locomo_lcd *lcd = lcd_get_data(ldev); + + locomo_lcd_off(lcd); + + locomo_lcd_disable_adsync(lcd); +} + +static struct platform_driver locomo_lcd_driver = { + .driver = { + .name = "locomo-lcd", + .pm = LOCOMOLCD_PM, + }, + .probe = locomo_lcd_probe, + .remove = locomo_lcd_remove, + .shutdown = locomo_lcd_shutdown, +}; + +module_platform_driver(locomo_lcd_driver); + +MODULE_AUTHOR("John Lenz "); +MODULE_AUTHOR("Pavel Machek "); +MODULE_DESCRIPTION("LoCoMo LCD driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:locomo-lcd");