From patchwork Tue Mar 1 12:05:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maurus Cuelenaere X-Patchwork-Id: 598821 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p21C5xvK004106 for ; Tue, 1 Mar 2011 12:05:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756334Ab1CAMF6 (ORCPT ); Tue, 1 Mar 2011 07:05:58 -0500 Received: from mail-ew0-f46.google.com ([209.85.215.46]:45130 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756299Ab1CAMF6 (ORCPT ); Tue, 1 Mar 2011 07:05:58 -0500 Received: by mail-ew0-f46.google.com with SMTP id 6so1618348ewy.19 for ; Tue, 01 Mar 2011 04:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:to:cc:message-id:in-reply-to:references :from:subject; bh=ZUeOTu3+6XUK+ArWKgkjNmnCgkI2oyB5jkfuzaHZ0EI=; b=oeo0yw/W2C7hPoqQY8f7EKpg/01sccPm2KVvjpr5/Ncd93dDc2tUUX+m7ZpCbCcfjB EYZthMISbCmmUJZeLdu3wkf3W0AmWtKzatwCZLAYkk+COxyYA6ov6XRAYZj2ZMfwABEg gNG7ADV4Taaszykg813ZvteW3YLqkyyrdpRz0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:to:cc:message-id:in-reply-to:references:from:subject; b=VyfrDfcpR5jd6k9tyZ8KNELwBuNqRq5YSwNr1Ec4xsCLdIAT1wrbhw5OYlhNQJrC2A Xefwp9ZB9jOAACGzz9Ltupbtv2FNU0NMuFViKK4vtwPQIVB26fMk30fNec7LagPAwlBT lyYB3ssT1TqHoWGV+0Z+R4Kvjl+/EFDA6Ayxg= Received: by 10.213.17.200 with SMTP id t8mr2521947eba.3.1298981157586; Tue, 01 Mar 2011 04:05:57 -0800 (PST) Received: from maurus-desktop (78-22-96-2.access.telenet.be [78.22.96.2]) by mx.google.com with ESMTPS id q53sm405475eeh.16.2011.03.01.04.05.55 (version=SSLv3 cipher=OTHER); Tue, 01 Mar 2011 04:05:57 -0800 (PST) Received: by maurus-desktop (sSMTP sendmail emulation); Tue, 1 Mar 2011 13:05:55 +0100 Date: Tue, 1 Mar 2011 13:05:55 +0100 To: linux-fbdev@vger.kernel.org Cc: Lars-Peter Clausen Message-Id: <7f854ef86a16dd03f415965b3535c607c401941e.1298980528.git.mcuelenaere@gmail.com> In-Reply-To: References: From: Maurus Cuelenaere Subject: [PATCH 1/6] FBDEV: JZ4740: Refactor GPIO pin operations Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 01 Mar 2011 12:05:59 +0000 (UTC) diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c index 7e61e68..65741d0 100644 --- a/drivers/video/jz4740_fb.c +++ b/drivers/video/jz4740_fb.c @@ -178,59 +178,60 @@ static const struct jz_gpio_bulk_request jz_lcd_data_pins[] = { JZ_GPIO_BULK_PIN(LCD_DATA17), }; -static unsigned int jzfb_num_ctrl_pins(struct jzfb *jzfb) +enum jzfb_pin_operation { + REQUEST_PINS, + FREE_PINS, + RESUME_PINS, + SUSPEND_PINS, +}; + +static void jzfb_pins_operation(struct jzfb *jzfb, + enum jzfb_pin_operation operation) { - unsigned int num; + unsigned int ctrl_num = 0, data_num = 0, data_start = 0; switch (jzfb->pdata->lcd_type) { case JZ_LCD_TYPE_GENERIC_16_BIT: - num = 4; + ctrl_num = 4; + data_num = 16; break; case JZ_LCD_TYPE_GENERIC_18_BIT: - num = 4; + ctrl_num = 4; + data_num = 18; break; case JZ_LCD_TYPE_8BIT_SERIAL: - num = 3; + ctrl_num = 3; + data_num = 8; break; case JZ_LCD_TYPE_SPECIAL_TFT_1: case JZ_LCD_TYPE_SPECIAL_TFT_2: case JZ_LCD_TYPE_SPECIAL_TFT_3: - num = 8; - break; - default: - num = 0; + ctrl_num = 8; + if (jzfb->pdata->bpp == 18) + data_num = 18; + else + data_num = 16; break; } - return num; -} -static unsigned int jzfb_num_data_pins(struct jzfb *jzfb) -{ - unsigned int num; - - switch (jzfb->pdata->lcd_type) { - case JZ_LCD_TYPE_GENERIC_16_BIT: - num = 16; + switch (operation) { + case REQUEST_PINS: + jz_gpio_bulk_request(jz_lcd_ctrl_pins, ctrl_num); + jz_gpio_bulk_request(&jz_lcd_data_pins[data_start], data_num); break; - case JZ_LCD_TYPE_GENERIC_18_BIT: - num = 18; + case FREE_PINS: + jz_gpio_bulk_free(jz_lcd_ctrl_pins, ctrl_num); + jz_gpio_bulk_free(&jz_lcd_data_pins[data_start], data_num); break; - case JZ_LCD_TYPE_8BIT_SERIAL: - num = 8; - break; - case JZ_LCD_TYPE_SPECIAL_TFT_1: - case JZ_LCD_TYPE_SPECIAL_TFT_2: - case JZ_LCD_TYPE_SPECIAL_TFT_3: - if (jzfb->pdata->bpp == 18) - num = 18; - else - num = 16; + case RESUME_PINS: + jz_gpio_bulk_resume(jz_lcd_ctrl_pins, ctrl_num); + jz_gpio_bulk_resume(&jz_lcd_data_pins[data_start], data_num); break; - default: - num = 0; + case SUSPEND_PINS: + jz_gpio_bulk_suspend(jz_lcd_ctrl_pins, ctrl_num); + jz_gpio_bulk_suspend(&jz_lcd_data_pins[data_start], data_num); break; } - return num; } /* Based on CNVT_TOHW macro from skeletonfb.c */ @@ -487,8 +488,7 @@ static void jzfb_enable(struct jzfb *jzfb) clk_enable(jzfb->ldclk); - jz_gpio_bulk_resume(jz_lcd_ctrl_pins, jzfb_num_ctrl_pins(jzfb)); - jz_gpio_bulk_resume(jz_lcd_data_pins, jzfb_num_data_pins(jzfb)); + jzfb_pins_operation(jzfb, RESUME_PINS); writel(0, jzfb->base + JZ_REG_LCD_STATE); @@ -511,8 +511,7 @@ static void jzfb_disable(struct jzfb *jzfb) ctrl = readl(jzfb->base + JZ_REG_LCD_STATE); } while (!(ctrl & JZ_LCD_STATE_DISABLED)); - jz_gpio_bulk_suspend(jz_lcd_ctrl_pins, jzfb_num_ctrl_pins(jzfb)); - jz_gpio_bulk_suspend(jz_lcd_data_pins, jzfb_num_data_pins(jzfb)); + jzfb_pins_operation(jzfb, SUSPEND_PINS); clk_disable(jzfb->ldclk); } @@ -715,8 +714,7 @@ static int __devinit jzfb_probe(struct platform_device *pdev) fb->mode = NULL; jzfb_set_par(fb); - jz_gpio_bulk_request(jz_lcd_ctrl_pins, jzfb_num_ctrl_pins(jzfb)); - jz_gpio_bulk_request(jz_lcd_data_pins, jzfb_num_data_pins(jzfb)); + jzfb_pins_operation(jzfb, REQUEST_PINS); ret = register_framebuffer(fb); if (ret) { @@ -729,8 +727,7 @@ static int __devinit jzfb_probe(struct platform_device *pdev) return 0; err_free_devmem: - jz_gpio_bulk_free(jz_lcd_ctrl_pins, jzfb_num_ctrl_pins(jzfb)); - jz_gpio_bulk_free(jz_lcd_data_pins, jzfb_num_data_pins(jzfb)); + jzfb_pins_operation(jzfb, FREE_PINS); fb_dealloc_cmap(&fb->cmap); jzfb_free_devmem(jzfb); @@ -753,8 +750,7 @@ static int __devexit jzfb_remove(struct platform_device *pdev) jzfb_blank(FB_BLANK_POWERDOWN, jzfb->fb); - jz_gpio_bulk_free(jz_lcd_ctrl_pins, jzfb_num_ctrl_pins(jzfb)); - jz_gpio_bulk_free(jz_lcd_data_pins, jzfb_num_data_pins(jzfb)); + jzfb_pins_operation(jzfb, FREE_PINS); iounmap(jzfb->base); release_mem_region(jzfb->mem->start, resource_size(jzfb->mem));