From patchwork Thu Jul 25 13:05:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 2833393 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C70CDC0319 for ; Thu, 25 Jul 2013 13:07:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5974520201 for ; Thu, 25 Jul 2013 13:07:13 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4280220213 for ; Thu, 25 Jul 2013 13:07:08 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2LFf-0005Ua-PP; Thu, 25 Jul 2013 13:06:41 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2LFY-0000k7-Ve; Thu, 25 Jul 2013 13:06:33 +0000 Received: from mail.free-electrons.com ([94.23.35.102]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2LF5-0000gi-Pw for linux-arm-kernel@lists.infradead.org; Thu, 25 Jul 2013 13:06:08 +0000 Received: by mail.free-electrons.com (Postfix, from userid 106) id 2BF59774; Thu, 25 Jul 2013 15:05:48 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (189.58.26.109.rev.sfr.net [109.26.58.189]) by mail.free-electrons.com (Postfix) with ESMTPSA id 13643BAE; Thu, 25 Jul 2013 15:05:29 +0200 (CEST) From: Maxime Ripard To: plagnioj@jcrosoft.com, tomi.valkeinen@ti.com Subject: [PATCHv2 3/3] fb: backlight: HX8357: Add HX8369 support Date: Thu, 25 Jul 2013 15:05:13 +0200 Message-Id: <1374757513-2253-4-git-send-email-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1374757513-2253-1-git-send-email-maxime.ripard@free-electrons.com> References: <1374757513-2253-1-git-send-email-maxime.ripard@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130725_090604_232279_8962F055 X-CRM114-Status: GOOD ( 17.57 ) X-Spam-Score: -1.9 (-) Cc: linux-fbdev@vger.kernel.org, Thomas Petazzoni , linux-kernel@vger.kernel.org, hector.palacios@digi.com, Alexandre Belloni , Maxime Ripard , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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-Virus-Scanned: ClamAV using ClamSMTP From: Alexandre Belloni Add support for the Himax HX8369 controller as it is quite similar to the hx8357. Signed-off-by: Alexandre Belloni Signed-off-by: Maxime Ripard Acked-by: Jingoo Han --- drivers/video/backlight/hx8357.c | 221 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 206 insertions(+), 15 deletions(-) diff --git a/drivers/video/backlight/hx8357.c b/drivers/video/backlight/hx8357.c index 00614ce..58ed4c1 100644 --- a/drivers/video/backlight/hx8357.c +++ b/drivers/video/backlight/hx8357.c @@ -71,6 +71,18 @@ #define HX8357_SET_POWER_NORMAL 0xd2 #define HX8357_SET_PANEL_RELATED 0xe9 +#define HX8369_SET_DISPLAY_BRIGHTNESS 0x51 +#define HX8369_WRITE_CABC_DISPLAY_VALUE 0x53 +#define HX8369_WRITE_CABC_BRIGHT_CTRL 0x55 +#define HX8369_WRITE_CABC_MIN_BRIGHTNESS 0x5e +#define HX8369_SET_POWER 0xb1 +#define HX8369_SET_DISPLAY_MODE 0xb2 +#define HX8369_SET_DISPLAY_WAVEFORM_CYC 0xb4 +#define HX8369_SET_VCOM 0xb6 +#define HX8369_SET_EXTENSION_COMMAND 0xb9 +#define HX8369_SET_GIP 0xd5 +#define HX8369_SET_GAMMA_CURVE_RELATED 0xe0 + struct hx8357_data { unsigned im_pins[HX8357_NUM_IM_PINS]; unsigned reset; @@ -144,6 +156,61 @@ static u8 hx8357_seq_display_mode[] = { HX8357_SET_DISPLAY_MODE_RGB_INTERFACE, }; +static u8 hx8369_seq_write_CABC_min_brightness[] = { + HX8369_WRITE_CABC_MIN_BRIGHTNESS, 0x00, +}; + +static u8 hx8369_seq_write_CABC_control[] = { + HX8369_WRITE_CABC_DISPLAY_VALUE, 0x24, +}; + +static u8 hx8369_seq_set_display_brightness[] = { + HX8369_SET_DISPLAY_BRIGHTNESS, 0xFF, +}; + +static u8 hx8369_seq_write_CABC_control_setting[] = { + HX8369_WRITE_CABC_BRIGHT_CTRL, 0x02, +}; + +static u8 hx8369_seq_extension_command[] = { + HX8369_SET_EXTENSION_COMMAND, 0xff, 0x83, 0x69, +}; + +static u8 hx8369_seq_display_related[] = { + HX8369_SET_DISPLAY_MODE, 0x00, 0x2b, 0x03, 0x03, 0x70, 0x00, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x01, +}; + +static u8 hx8369_seq_panel_waveform_cycle[] = { + HX8369_SET_DISPLAY_WAVEFORM_CYC, 0x0a, 0x1d, 0x80, 0x06, 0x02, +}; + +static u8 hx8369_seq_set_address_mode[] = { + HX8357_SET_ADDRESS_MODE, 0x00, +}; + +static u8 hx8369_seq_vcom[] = { + HX8369_SET_VCOM, 0x3e, 0x3e, +}; + +static u8 hx8369_seq_gip[] = { + HX8369_SET_GIP, 0x00, 0x01, 0x03, 0x25, 0x01, 0x02, 0x28, 0x70, + 0x11, 0x13, 0x00, 0x00, 0x40, 0x26, 0x51, 0x37, 0x00, 0x00, 0x71, + 0x35, 0x60, 0x24, 0x07, 0x0f, 0x04, 0x04, +}; + +static u8 hx8369_seq_power[] = { + HX8369_SET_POWER, 0x01, 0x00, 0x34, 0x03, 0x00, 0x11, 0x11, 0x32, + 0x2f, 0x3f, 0x3f, 0x01, 0x3a, 0x01, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, +}; + +static u8 hx8369_seq_gamma_curve_related[] = { + HX8369_SET_GAMMA_CURVE_RELATED, 0x00, 0x0d, 0x19, 0x2f, 0x3b, 0x3d, + 0x2e, 0x4a, 0x08, 0x0e, 0x0f, 0x14, 0x16, 0x14, 0x14, 0x14, 0x1e, + 0x00, 0x0d, 0x19, 0x2f, 0x3b, 0x3d, 0x2e, 0x4a, 0x08, 0x0e, 0x0f, + 0x14, 0x16, 0x14, 0x14, 0x14, 0x1e, +}; + static int hx8357_spi_write_then_read(struct lcd_device *lcdev, u8 *txbuf, u16 txlen, u8 *rxbuf, u16 rxlen) @@ -220,6 +287,10 @@ static int hx8357_enter_standby(struct lcd_device *lcdev) if (ret < 0) return ret; + /* + * The controller needs 120ms when entering in sleep mode before we can + * send the command to go off sleep mode + */ msleep(120); return 0; @@ -233,6 +304,10 @@ static int hx8357_exit_standby(struct lcd_device *lcdev) if (ret < 0) return ret; + /* + * The controller needs 120ms when exiting from sleep mode before we + * can send the command to enter in sleep mode + */ msleep(120); ret = hx8357_spi_write_byte(lcdev, HX8357_SET_DISPLAY_ON); @@ -242,6 +317,21 @@ static int hx8357_exit_standby(struct lcd_device *lcdev) return 0; } +static void hx8357_lcd_reset(struct lcd_device *lcdev) +{ + struct hx8357_data *lcd = lcd_get_data(lcdev); + + /* Reset the screen */ + gpio_set_value(lcd->reset, 1); + usleep_range(10000, 12000); + gpio_set_value(lcd->reset, 0); + usleep_range(10000, 12000); + gpio_set_value(lcd->reset, 1); + + /* The controller needs 120ms to recover from reset */ + msleep(120); +} + static int hx8357_lcd_init(struct lcd_device *lcdev) { struct hx8357_data *lcd = lcd_get_data(lcdev); @@ -257,14 +347,6 @@ static int hx8357_lcd_init(struct lcd_device *lcdev) gpio_set_value_cansleep(lcd->im_pins[2], 1); } - /* Reset the screen */ - gpio_set_value(lcd->reset, 1); - usleep_range(10000, 12000); - gpio_set_value(lcd->reset, 0); - usleep_range(10000, 12000); - gpio_set_value(lcd->reset, 1); - msleep(120); - ret = hx8357_spi_write_array(lcdev, hx8357_seq_power, ARRAY_SIZE(hx8357_seq_power)); if (ret < 0) @@ -344,6 +426,9 @@ static int hx8357_lcd_init(struct lcd_device *lcdev) if (ret < 0) return ret; + /* + * The controller needs 120ms to fully recover from exiting sleep mode + */ msleep(120); ret = hx8357_spi_write_byte(lcdev, HX8357_SET_DISPLAY_ON); @@ -359,6 +444,98 @@ static int hx8357_lcd_init(struct lcd_device *lcdev) return 0; } +static int hx8369_lcd_init(struct lcd_device *lcdev) +{ + int ret; + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_extension_command, + ARRAY_SIZE(hx8369_seq_extension_command)); + if (ret < 0) + return ret; + usleep_range(10000, 12000); + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_display_related, + ARRAY_SIZE(hx8369_seq_display_related)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_panel_waveform_cycle, + ARRAY_SIZE(hx8369_seq_panel_waveform_cycle)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_set_address_mode, + ARRAY_SIZE(hx8369_seq_set_address_mode)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_vcom, + ARRAY_SIZE(hx8369_seq_vcom)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_gip, + ARRAY_SIZE(hx8369_seq_gip)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_power, + ARRAY_SIZE(hx8369_seq_power)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_byte(lcdev, HX8357_EXIT_SLEEP_MODE); + if (ret < 0) + return ret; + + /* + * The controller needs 120ms to fully recover from exiting sleep mode + */ + msleep(120); + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_gamma_curve_related, + ARRAY_SIZE(hx8369_seq_gamma_curve_related)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_byte(lcdev, HX8357_EXIT_SLEEP_MODE); + if (ret < 0) + return ret; + usleep_range(1000, 1200); + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_write_CABC_control, + ARRAY_SIZE(hx8369_seq_write_CABC_control)); + if (ret < 0) + return ret; + usleep_range(10000, 12000); + + ret = hx8357_spi_write_array(lcdev, + hx8369_seq_write_CABC_control_setting, + ARRAY_SIZE(hx8369_seq_write_CABC_control_setting)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_array(lcdev, + hx8369_seq_write_CABC_min_brightness, + ARRAY_SIZE(hx8369_seq_write_CABC_min_brightness)); + if (ret < 0) + return ret; + usleep_range(10000, 12000); + + ret = hx8357_spi_write_array(lcdev, hx8369_seq_set_display_brightness, + ARRAY_SIZE(hx8369_seq_set_display_brightness)); + if (ret < 0) + return ret; + + ret = hx8357_spi_write_byte(lcdev, HX8357_SET_DISPLAY_ON); + if (ret < 0) + return ret; + + msleep(100); + + return 0; +} + #define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL) static int hx8357_set_power(struct lcd_device *lcdev, int power) @@ -391,10 +568,24 @@ static struct lcd_ops hx8357_ops = { .get_power = hx8357_get_power, }; +static const struct of_device_id hx8357_dt_ids[] = { + { + .compatible = "himax,hx8357", + .data = hx8357_lcd_init, + }, + { + .compatible = "himax,hx8369", + .data = hx8369_lcd_init, + }, + {}, +}; +MODULE_DEVICE_TABLE(of, hx8357_dt_ids); + static int hx8357_probe(struct spi_device *spi) { struct lcd_device *lcdev; struct hx8357_data *lcd; + const struct of_device_id *match; int i, ret; lcd = devm_kzalloc(&spi->dev, sizeof(*lcd), GFP_KERNEL); @@ -411,6 +602,10 @@ static int hx8357_probe(struct spi_device *spi) lcd->spi = spi; + match = of_match_device(hx8357_dt_ids, &spi->dev); + if (!match || !match->data) + return -EINVAL; + lcd->reset = of_get_named_gpio(spi->dev.of_node, "gpios-reset", 0); if (!gpio_is_valid(lcd->reset)) { dev_err(&spi->dev, "Missing dt property: gpios-reset\n"); @@ -461,7 +656,9 @@ static int hx8357_probe(struct spi_device *spi) } spi_set_drvdata(spi, lcdev); - ret = hx8357_lcd_init(lcdev); + hx8357_lcd_reset(lcdev); + + ret = ((int (*)(struct lcd_device *))match->data)(lcdev); if (ret) { dev_err(&spi->dev, "Couldn't initialize panel\n"); goto init_error; @@ -484,12 +681,6 @@ static int hx8357_remove(struct spi_device *spi) return 0; } -static const struct of_device_id hx8357_dt_ids[] = { - { .compatible = "himax,hx8357" }, - {}, -}; -MODULE_DEVICE_TABLE(of, hx8357_dt_ids); - static struct spi_driver hx8357_driver = { .probe = hx8357_probe, .remove = hx8357_remove,