From patchwork Wed Feb 13 10:40:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 2135141 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 15398E00C6 for ; Wed, 13 Feb 2013 10:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933734Ab3BMKkn (ORCPT ); Wed, 13 Feb 2013 05:40:43 -0500 Received: from mail.free-electrons.com ([94.23.35.102]:49815 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933702Ab3BMKkj (ORCPT ); Wed, 13 Feb 2013 05:40:39 -0500 Received: by mail.free-electrons.com (Postfix, from userid 106) id 653AD82B; Wed, 13 Feb 2013 11:40:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.3.2 Received: from localhost (col31-4-88-188-83-94.fbx.proxad.net [88.188.83.94]) by mail.free-electrons.com (Postfix) with ESMTPSA id 77C8E81B; Wed, 13 Feb 2013 11:40:37 +0100 (CET) From: Maxime Ripard To: linux-fbdev@vger.kernel.org Cc: joe@perches.com, Andrew Morton , Richard Purdie , Florian Tobias Schandinat , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] fb: hx8357: Use static arrays for LCD configuration Date: Wed, 13 Feb 2013 11:40:28 +0100 Message-Id: <1360752028-7301-6-git-send-email-maxime.ripard@free-electrons.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360752028-7301-1-git-send-email-maxime.ripard@free-electrons.com> References: <1360752028-7301-1-git-send-email-maxime.ripard@free-electrons.com> Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org This allows a smaller and less error-prone code by using static arrays and the ARRAY_SIZE macro. Signed-off-by: Maxime Ripard --- drivers/video/backlight/hx8357.c | 173 +++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 78 deletions(-) diff --git a/drivers/video/backlight/hx8357.c b/drivers/video/backlight/hx8357.c index 6da8ebe..a0482b5 100644 --- a/drivers/video/backlight/hx8357.c +++ b/drivers/video/backlight/hx8357.c @@ -78,6 +78,71 @@ struct hx8357_data { int state; }; +static u8 hx8357_seq_power[] = { + HX8357_SET_POWER, 0x44, 0x41, 0x06, +}; + +static u8 hx8357_seq_vcom[] = { + HX8357_SET_VCOM, 0x40, 0x10, +}; + +static u8 hx8357_seq_power_normal[] = { + HX8357_SET_POWER_NORMAL, 0x05, 0x12, +}; + +static u8 hx8357_seq_panel_driving[] = { + HX8357_SET_PANEL_DRIVING, 0x14, 0x3b, 0x00, 0x02, 0x11, +}; + +static u8 hx8357_seq_display_frame[] = { + HX8357_SET_DISPLAY_FRAME, 0x0c, +}; + +static u8 hx8357_seq_panel_related[] = { + HX8357_SET_PANEL_RELATED, 0x01, +}; + +static u8 hx8357_seq_undefined1[] = { + 0xea, 0x03, 0x00, 0x00, +}; + +static u8 hx8357_seq_undefined2[] = { + 0xeb, 0x40, 0x54, 0x26, 0xdb, +}; + +static u8 hx8357_seq_gamma[] = { + HX8357_SET_GAMMA, 0x00, 0x15, 0x00, 0x22, 0x00, + 0x08, 0x77, 0x26, 0x77, 0x22, 0x04, 0x00, +}; + +static u8 hx8357_seq_address_mode[] = { + HX8357_SET_ADDRESS_MODE, 0xc0, +}; + +static u8 hx8357_seq_pixel_format[] = { + HX8357_SET_PIXEL_FORMAT, + HX8357_SET_PIXEL_FORMAT_DPI_18BIT | + HX8357_SET_PIXEL_FORMAT_DBI_18BIT, +}; + +static u8 hx8357_seq_column_address[] = { + HX8357_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x01, 0x3f, +}; + +static u8 hx8357_seq_page_address[] = { + HX8357_SET_PAGE_ADDRESS, 0x00, 0x00, 0x01, 0xdf, +}; + +static u8 hx8357_seq_rgb[] = { + HX8357_SET_RGB, 0x02, +}; + +static u8 hx8357_seq_display_mode[] = { + HX8357_SET_DISPLAY_MODE, + HX8357_SET_DISPLAY_MODE_RGB_THROUGH | + HX8357_SET_DISPLAY_MODE_RGB_INTERFACE, +}; + static int hx8357_spi_write_then_read(struct lcd_device *lcdev, u8 *txbuf, u16 txlen, u8 *rxbuf, u16 rxlen) @@ -179,7 +244,6 @@ static int hx8357_exit_standby(struct lcd_device *lcdev) static int hx8357_lcd_init(struct lcd_device *lcdev) { struct hx8357_data *lcd = lcd_get_data(lcdev); - u8 buf[16]; int ret; /* @@ -198,125 +262,78 @@ static int hx8357_lcd_init(struct lcd_device *lcdev) gpio_set_value(lcd->reset, 1); msleep(120); - buf[0] = HX8357_SET_POWER; - buf[1] = 0x44; - buf[2] = 0x41; - buf[3] = 0x06; - ret = hx8357_spi_write_array(lcdev, buf, 4); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_power, + ARRAY_SIZE(hx8357_seq_power)); if (ret < 0) return ret; - buf[0] = HX8357_SET_VCOM; - buf[1] = 0x40; - buf[2] = 0x10; - ret = hx8357_spi_write_array(lcdev, buf, 3); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_vcom, + ARRAY_SIZE(hx8357_seq_vcom)); if (ret < 0) return ret; - buf[0] = HX8357_SET_POWER_NORMAL; - buf[1] = 0x05; - buf[2] = 0x12; - ret = hx8357_spi_write_array(lcdev, buf, 3); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_power_normal, + ARRAY_SIZE(hx8357_seq_power_normal)); if (ret < 0) return ret; - buf[0] = HX8357_SET_PANEL_DRIVING; - buf[1] = 0x14; - buf[2] = 0x3b; - buf[3] = 0x00; - buf[4] = 0x02; - buf[5] = 0x11; - ret = hx8357_spi_write_array(lcdev, buf, 6); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_panel_driving, + ARRAY_SIZE(hx8357_seq_panel_driving)); if (ret < 0) return ret; - buf[0] = HX8357_SET_DISPLAY_FRAME; - buf[1] = 0x0c; - ret = hx8357_spi_write_array(lcdev, buf, 2); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_display_frame, + ARRAY_SIZE(hx8357_seq_display_frame)); if (ret < 0) return ret; - buf[0] = HX8357_SET_PANEL_RELATED; - buf[1] = 0x01; - ret = hx8357_spi_write_array(lcdev, buf, 2); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_panel_related, + ARRAY_SIZE(hx8357_seq_panel_related)); if (ret < 0) return ret; - buf[0] = 0xea; - buf[1] = 0x03; - buf[2] = 0x00; - buf[3] = 0x00; - ret = hx8357_spi_write_array(lcdev, buf, 4); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_undefined1, + ARRAY_SIZE(hx8357_seq_undefined1)); if (ret < 0) return ret; - buf[0] = 0xeb; - buf[1] = 0x40; - buf[2] = 0x54; - buf[3] = 0x26; - buf[4] = 0xdb; - ret = hx8357_spi_write_array(lcdev, buf, 5); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_undefined2, + ARRAY_SIZE(hx8357_seq_undefined2)); if (ret < 0) return ret; - buf[0] = HX8357_SET_GAMMA; - buf[1] = 0x00; - buf[2] = 0x15; - buf[3] = 0x00; - buf[4] = 0x22; - buf[5] = 0x00; - buf[6] = 0x08; - buf[7] = 0x77; - buf[8] = 0x26; - buf[9] = 0x77; - buf[10] = 0x22; - buf[11] = 0x04; - buf[12] = 0x00; - ret = hx8357_spi_write_array(lcdev, buf, 13); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_gamma, + ARRAY_SIZE(hx8357_seq_gamma)); if (ret < 0) return ret; - buf[0] = HX8357_SET_ADDRESS_MODE; - buf[1] = 0xc0; - ret = hx8357_spi_write_array(lcdev, buf, 2); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_address_mode, + ARRAY_SIZE(hx8357_seq_address_mode)); if (ret < 0) return ret; - buf[0] = HX8357_SET_PIXEL_FORMAT; - buf[1] = HX8357_SET_PIXEL_FORMAT_DPI_18BIT | - HX8357_SET_PIXEL_FORMAT_DBI_18BIT; - ret = hx8357_spi_write_array(lcdev, buf, 2); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_pixel_format, + ARRAY_SIZE(hx8357_seq_pixel_format)); if (ret < 0) return ret; - buf[0] = HX8357_SET_COLUMN_ADDRESS; - buf[1] = 0x00; - buf[2] = 0x00; - buf[3] = 0x01; - buf[4] = 0x3f; - ret = hx8357_spi_write_array(lcdev, buf, 5); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_column_address, + ARRAY_SIZE(hx8357_seq_column_address)); if (ret < 0) return ret; - buf[0] = HX8357_SET_PAGE_ADDRESS; - buf[1] = 0x00; - buf[2] = 0x00; - buf[3] = 0x01; - buf[4] = 0xdf; - ret = hx8357_spi_write_array(lcdev, buf, 5); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_page_address, + ARRAY_SIZE(hx8357_seq_page_address)); if (ret < 0) return ret; - buf[0] = HX8357_SET_RGB; - buf[1] = 0x02; - ret = hx8357_spi_write_array(lcdev, buf, 2); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_rgb, + ARRAY_SIZE(hx8357_seq_rgb)); if (ret < 0) return ret; - buf[0] = HX8357_SET_DISPLAY_MODE; - buf[1] = HX8357_SET_DISPLAY_MODE_RGB_THROUGH | - HX8357_SET_DISPLAY_MODE_RGB_INTERFACE; - ret = hx8357_spi_write_array(lcdev, buf, 2); + ret = hx8357_spi_write_array(lcdev, hx8357_seq_display_mode, + ARRAY_SIZE(hx8357_seq_display_mode)); if (ret < 0) return ret;