Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* [PATCH 3/6] viafb: remove superfluous register unlocking/locking
From: Florian Tobias Schandinat @ 2011-08-05 21:46 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

The locking is done within the viafb_set_*_timing functions so there
is no need to do it here. Move a missing hardware reset into the
modesetting function.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/hw.c              |    7 -------
 drivers/video/via/via_modesetting.c |    4 ++++
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 52d41f0..8b4bdf5 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1507,18 +1507,11 @@ void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
 	crt_reg.ver_sync_end += crt_reg.ver_sync_start;
 	h_addr = crt_reg.hor_addr;
 	v_addr = crt_reg.ver_addr;
-	if (set_iga = IGA1) {
-		viafb_unlock_crt();
-		viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
-	}
-
 	if (set_iga = IGA1)
 		via_set_primary_timing(&crt_reg);
 	else if (set_iga = IGA2)
 		via_set_secondary_timing(&crt_reg);
 
-	viafb_lock_crt();
-	viafb_write_reg_mask(CR17, VIACR, 0x80, BIT7);
 	viafb_load_fetch_count_reg(h_addr, bpp_byte, set_iga);
 
 	/* load FIFO */
diff --git a/drivers/video/via/via_modesetting.c b/drivers/video/via/via_modesetting.c
index 016d457..0e431ae 100644
--- a/drivers/video/via/via_modesetting.c
+++ b/drivers/video/via/via_modesetting.c
@@ -82,6 +82,10 @@ void via_set_primary_timing(const struct display_timing *timing)
 
 	/* lock timing registers */
 	via_write_reg_mask(VIACR, 0x11, 0x80, 0x80);
+
+	/* reset timing control */
+	via_write_reg_mask(VIACR, 0x17, 0x00, 0x80);
+	via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
 }
 
 void via_set_secondary_timing(const struct display_timing *timing)
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 4/6] viafb: remove superfluous mode lookup
From: Florian Tobias Schandinat @ 2011-08-05 21:46 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

As the result is not used anywhere there is no need to perform the
lookup at all.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/viafbdev.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index bddae58..3eaf607 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -1735,7 +1735,6 @@ static struct viafb_pm_hooks viafb_fb_pm_hooks = {
 int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 {
 	u32 default_xres, default_yres;
-	struct VideoModeTable *vmode_entry;
 	struct fb_var_screeninfo default_var;
 	int rc;
 	u32 viafb_par_length;
@@ -1808,7 +1807,6 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 	}
 
 	parse_mode(viafb_mode, &default_xres, &default_yres);
-	vmode_entry = viafb_get_mode(default_xres, default_yres);
 	if (viafb_SAMM_ON = 1)
 		parse_mode(viafb_mode1, &viafb_second_xres,
 			&viafb_second_yres);
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 5/6] viafb: simplify viafb_fill_crtc_timing
From: Florian Tobias Schandinat @ 2011-08-05 21:47 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

As the first argument is just part of the structure passed as the
second argument there is no need for it at all.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/dvi.c |    6 ++----
 drivers/video/via/hw.c  |   12 ++++++------
 drivers/video/via/hw.h  |    4 ++--
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/video/via/dvi.c b/drivers/video/via/dvi.c
index b1f3647..c7ff5c0 100644
--- a/drivers/video/via/dvi.c
+++ b/drivers/video/via/dvi.c
@@ -190,12 +190,10 @@ void viafb_dvi_set_mode(struct VideoModeTable *mode, int mode_bpp,
 	if ((maxPixelClock != 0) && (desirePixelClock > maxPixelClock)) {
 		rb_mode = viafb_get_rb_mode(mode->crtc[0].crtc.hor_addr,
 			mode->crtc[0].crtc.ver_addr);
-		if (rb_mode) {
+		if (rb_mode)
 			mode = rb_mode;
-			pDviTiming = rb_mode->crtc;
-		}
 	}
-	viafb_fill_crtc_timing(pDviTiming, mode, mode_bpp / 8, set_iga);
+	viafb_fill_crtc_timing(mode, mode_bpp / 8, set_iga);
 }
 
 /* Sense DVI Connector */
diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 8b4bdf5..2050fb8 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,9 +1467,10 @@ void viafb_set_vclock(u32 clk, int set_iga)
 	via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
-	struct VideoModeTable *video_mode, int bpp_byte, int set_iga)
+void viafb_fill_crtc_timing(struct VideoModeTable *video_mode, int bpp_byte,
+	int set_iga)
 {
+	struct crt_mode_table *crt_table = video_mode->crtc;
 	struct display_timing crt_reg;
 	int i;
 	int index = 0;
@@ -1911,11 +1912,10 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 	if (viafb_CRT_ON) {
 		if (viafb_SAMM_ON &&
 			viaparinfo->shared->iga2_devices & VIA_CRT) {
-			viafb_fill_crtc_timing(crt_timing1, vmode_tbl1,
-				video_bpp1 / 8, IGA2);
+			viafb_fill_crtc_timing(vmode_tbl1, video_bpp1 / 8,
+				IGA2);
 		} else {
-			viafb_fill_crtc_timing(crt_timing, vmode_tbl,
-				video_bpp / 8,
+			viafb_fill_crtc_timing(vmode_tbl, video_bpp / 8,
 				(viaparinfo->shared->iga1_devices & VIA_CRT)
 				? IGA1 : IGA2);
 		}
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 267c669..1fd8d98 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,8 +637,8 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
-	struct VideoModeTable *video_mode, int bpp_byte, int set_iga);
+void viafb_fill_crtc_timing(struct VideoModeTable *video_mode, int bpp_byte,
+	int set_iga);
 
 void viafb_set_vclock(u32 CLK, int set_iga);
 void viafb_load_reg(int timing_value, int viafb_load_reg_num,
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 6/6] viafb: remove 640x480-60 CRT special case
From: Florian Tobias Schandinat @ 2011-08-05 21:47 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

The timing for 640x480-60 was handled different than all others.
This patch changes this by changing the blanking start and end.
The reason for this is that I can't find any reason for the old
behaviour and it was not consistent anyway as the special case for
LCD did not always trigger as the LCD code does not use this
function and it did trigger regardless of whether the display set is
CRT or LCD but only based whether any DVI/LCD device exists.
There are no negative effects observed for CRT or DVI devices.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/hw.c      |   14 --------------
 drivers/video/via/viamode.c |    2 +-
 2 files changed, 1 insertions(+), 15 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 2050fb8..c5e7833 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1488,20 +1488,6 @@ void viafb_fill_crtc_timing(struct VideoModeTable *video_mode, int bpp_byte,
 	}
 
 	crt_reg = crt_table[index].crtc;
-
-	/* Mode 640x480 has border, but LCD/DFP didn't have border. */
-	/* So we would delete border. */
-	if ((viafb_LCD_ON | viafb_DVI_ON)
-	    && video_mode->crtc[0].crtc.hor_addr = 640
-	    && video_mode->crtc[0].crtc.ver_addr = 480
-	    && refresh = 60) {
-		/* The border is 8 pixels. */
-		crt_reg.hor_blank_start = crt_reg.hor_blank_start - 8;
-
-		/* Blanking time should add left and right borders. */
-		crt_reg.hor_blank_end = crt_reg.hor_blank_end + 16;
-	}
-
 	crt_reg.hor_blank_end += crt_reg.hor_blank_start;
 	crt_reg.hor_sync_end += crt_reg.hor_sync_start;
 	crt_reg.ver_blank_end += crt_reg.ver_blank_start;
diff --git a/drivers/video/via/viamode.c b/drivers/video/via/viamode.c
index 58df74e..8a9f4fc 100644
--- a/drivers/video/via/viamode.c
+++ b/drivers/video/via/viamode.c
@@ -281,7 +281,7 @@ static struct crt_mode_table CRTM640x480[] = {
 	/*r_rate,hsp,vsp */
 	/*HT,  HA,  HBS, HBE, HSS, HSE, VT,  VA,  VBS, VBE, VSS, VSE */
 	{REFRESH_60, M640X480_R60_HSP, M640X480_R60_VSP,
-	 {800, 640, 648, 144, 656, 96, 525, 480, 480, 45, 490, 2} },
+	 {800, 640, 640, 160, 656, 96, 525, 480, 480, 45, 490, 2} },
 	{REFRESH_75, M640X480_R75_HSP, M640X480_R75_VSP,
 	 {840, 640, 640, 200, 656, 64, 500, 480, 480, 20, 481, 3} },
 	{REFRESH_85, M640X480_R85_HSP, M640X480_R85_VSP,
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 0/6] viafb modesetting update 1
From: Florian Tobias Schandinat @ 2011-08-05 21:49 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat

Hi all,

this is the first series containing some stable patches of my 
modesetting work. Adding the functions for setting the timing 
parameters in via_modesetting is an important step as well as 
pushing the strange behaviour that sync end and blanking end 
contained the length and not the end value one level up.
Additionally it has some related cleanups.
All this should be relatively stable, is not expected to cause 
regressions and was tested on CLE266, VX800 and VX855. These 
patches will show up in linux-next after the merge window is 
closed.
The next step will be to limit the influence of the modetable 
and hopefully replace parts of it by things provided in the 
subsystem to get rid of some bugs.


Thanks,

Florian Tobias Schandinat


Florian Tobias Schandinat (6):
  viafb: use more compact modesetting functions
  viafb: kill viafb_load_crtc_timing
  viafb: remove superfluous register unlocking/locking
  viafb: remove superfluous mode lookup
  viafb: simplify viafb_fill_crtc_timing
  viafb: remove 640x480-60 CRT special case

 drivers/video/via/dvi.c             |    6 +-
 drivers/video/via/hw.c              |  341 ++---------------------------------
 drivers/video/via/hw.h              |  277 +----------------------------
 drivers/video/via/lcd.c             |   41 ++---
 drivers/video/via/lcd.h             |    2 -
 drivers/video/via/share.h           |   19 +--
 drivers/video/via/via_modesetting.c |  104 +++++++++++
 drivers/video/via/via_modesetting.h |   18 ++
 drivers/video/via/viafbdev.c        |    2 -
 drivers/video/via/viamode.c         |    2 +-
 10 files changed, 161 insertions(+), 651 deletions(-)


^ permalink raw reply

* [PATCH 1/6] viafb: use more compact modesetting functions
From: Florian Tobias Schandinat @ 2011-08-05 21:52 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

This patch replaces the old timing setup code with a redesigned one.
The new code might be slightly faster as it has no conditinals and
does not write the same register multiple times. Also it makes the
comparison to the documentation easier.
Regressions are unlikely but could happen as a lot of hardware is
undocumented.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>

 drivers/video/via/hw.c              |  296 +----------------------------------
 drivers/video/via/hw.h              |  273 --------------------------------
 drivers/video/via/share.h           |   19 +--
 drivers/video/via/via_modesetting.c |  100 ++++++++++++
 drivers/video/via/via_modesetting.h |   18 ++
 5 files changed, 128 insertions(+), 578 deletions(-)
-- 
1.6.3.2


^ permalink raw reply

* [PATCH 2/6] viafb: kill viafb_load_crtc_timing
From: Florian Tobias Schandinat @ 2011-08-05 21:55 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

This patch replaces calls to viafb_load_crtc_timing with the code.
This should make it easier to fix the oddity that in the modetable
the blank and sync end entries contain the length and we need to add
the start values to get those to be written to the hardware.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>

 drivers/video/via/hw.c  |   30 ++++++++----------------------
 drivers/video/via/lcd.c |   41 +++++++++++++++++++----------------------
 drivers/video/via/lcd.h |    2 --
 3 files changed, 27 insertions(+), 46 deletions(-)
-- 
1.6.3.2


^ permalink raw reply

* [PATCH 3/6] viafb: remove superfluous register unlocking/locking
From: Florian Tobias Schandinat @ 2011-08-05 21:55 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

The locking is done within the viafb_set_*_timing functions so there
is no need to do it here. Move a missing hardware reset into the
modesetting function.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>

 drivers/video/via/hw.c              |    7 -------
 drivers/video/via/via_modesetting.c |    4 ++++
 2 files changed, 4 insertions(+), 7 deletions(-)
-- 
1.6.3.2


^ permalink raw reply

* [PATCH 4/6] viafb: remove superfluous mode lookup
From: Florian Tobias Schandinat @ 2011-08-05 21:58 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

As the result is not used anywhere there is no need to perform the
lookup at all.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>

 drivers/video/via/viafbdev.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
-- 
1.6.3.2


^ permalink raw reply

* [PATCH 5/6] viafb: simplify viafb_fill_crtc_timing
From: Florian Tobias Schandinat @ 2011-08-05 21:58 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

As the first argument is just part of the structure passed as the
second argument there is no need for it at all.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>

 drivers/video/via/dvi.c |    6 ++----
 drivers/video/via/hw.c  |   12 ++++++------
 drivers/video/via/hw.h  |    4 ++--
 3 files changed, 10 insertions(+), 12 deletions(-)
-- 
1.6.3.2


^ permalink raw reply

* [PATCH 6/6] viafb: remove 640x480-60 CRT special case
From: Florian Tobias Schandinat @ 2011-08-05 21:59 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312578946.git.FlorianSchandinat@gmx.de>

The timing for 640x480-60 was handled different than all others.
This patch changes this by changing the blanking start and end.
The reason for this is that I can't find any reason for the old
behaviour and it was not consistent anyway as the special case for
LCD did not always trigger as the LCD code does not use this
function and it did trigger regardless of whether the display set is
CRT or LCD but only based whether any DVI/LCD device exists.
There are no negative effects observed for CRT or DVI devices.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>

 drivers/video/via/hw.c      |   14 --------------
 drivers/video/via/viamode.c |    2 +-
 2 files changed, 1 insertions(+), 15 deletions(-)
-- 
1.6.3.2


^ permalink raw reply

* [PATCH] viafb: fix pointer type missmatch
From: stufever @ 2011-08-06 13:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-fbdev, lethal, FlorianSchandinat, Wang Shaoyan

From: Wang Shaoyan <wangshaoyan.pt@taobao.com>

  drivers/video/via/via-core.c: In function 'via_pci_probe':
  drivers/video/via/via-core.c:691: warning: assignment discards qualifiers from pointer target type

Signed-off-by: Wang Shaoyan <wangshaoyan.pt@taobao.com>
---
 drivers/video/via/via-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c
index eb112b6..dd58b53 100644
--- a/drivers/video/via/via-core.c
+++ b/drivers/video/via/via-core.c
@@ -35,7 +35,7 @@ static struct via_port_cfg adap_configs[] = {
  * The OLPC XO-1.5 puts the camera power and reset lines onto
  * GPIO 2C.
  */
-static const struct via_port_cfg olpc_adap_configs[] = {
+static struct via_port_cfg olpc_adap_configs[] = {
 	[VIA_PORT_26]	= { VIA_PORT_I2C,  VIA_MODE_I2C, VIASR, 0x26 },
 	[VIA_PORT_31]	= { VIA_PORT_I2C,  VIA_MODE_I2C, VIASR, 0x31 },
 	[VIA_PORT_25]	= { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x25 },
-- 
1.7.0.4


^ permalink raw reply related

* Re: [PATCH] viafb: fix pointer type missmatch
From: Florian Tobias Schandinat @ 2011-08-06 14:36 UTC (permalink / raw)
  To: stufever; +Cc: linux-kernel, linux-fbdev, lethal, Wang Shaoyan
In-Reply-To: <1312637180-6107-1-git-send-email-wangshaoyan.pt@taobao.com>

Hi,

On 08/06/2011 01:26 PM, stufever@gmail.com wrote:
> From: Wang Shaoyan<wangshaoyan.pt@taobao.com>
>
>    drivers/video/via/via-core.c: In function 'via_pci_probe':
>    drivers/video/via/via-core.c:691: warning: assignment discards qualifiers from pointer target type
>
> Signed-off-by: Wang Shaoyan<wangshaoyan.pt@taobao.com>
> ---
>   drivers/video/via/via-core.c |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c
> index eb112b6..dd58b53 100644
> --- a/drivers/video/via/via-core.c
> +++ b/drivers/video/via/via-core.c
> @@ -35,7 +35,7 @@ static struct via_port_cfg adap_configs[] = {
>    * The OLPC XO-1.5 puts the camera power and reset lines onto
>    * GPIO 2C.
>    */
> -static const struct via_port_cfg olpc_adap_configs[] = {
> +static struct via_port_cfg olpc_adap_configs[] = {

Well the const was there as this object should really not be changed at runtime. 
But as the correct solution is not feasible as it conflicts with the I2C API and 
casting the const away would be evil as well I will accept this patch.
But as I assume you, who sent this email, are not the original author, please 
resent it with your Signed-off-by added. (as keeping track who received the 
patch from whom is one reasons for having those)

>   	[VIA_PORT_26]	= { VIA_PORT_I2C,  VIA_MODE_I2C, VIASR, 0x26 },
>   	[VIA_PORT_31]	= { VIA_PORT_I2C,  VIA_MODE_I2C, VIASR, 0x31 },
>   	[VIA_PORT_25]	= { VIA_PORT_GPIO, VIA_MODE_GPIO, VIASR, 0x25 },

Thanks,

Florian Tobias Schandinat

^ permalink raw reply

* Re: [PATCH] viafb: fix pointer type missmatch
From: Wang Shaoyan @ 2011-08-06 15:03 UTC (permalink / raw)
  To: Florian Tobias Schandinat; +Cc: linux-kernel, linux-fbdev, lethal, Wang Shaoyan
In-Reply-To: <4E3D5154.2040808@gmx.de>

hi, the gmail is just to send patch, I have to use it, because my work
mail server will append some spam information. So my signed-off-by is
right author, that's why I add an obvious "From:". Sorry to trobule
you.

> But as I assume you, who sent this email, are not the original author,
> please resent it with your Signed-off-by added. (as keeping track who
> received the patch from whom is one reasons for having those)


-- 
Wang Shaoyan

^ permalink raw reply

* Re: [PATCH] viafb: fix pointer type missmatch
From: Florian Tobias Schandinat @ 2011-08-06 15:18 UTC (permalink / raw)
  To: Wang Shaoyan; +Cc: linux-kernel, linux-fbdev, lethal, Wang Shaoyan
In-Reply-To: <CANxBZFpxO40BE6iTGw3ad9+685_sAZettg+H6VQfB-X7cFbvhw@mail.gmail.com>

Hi,

okay, it was not obvious that "stufever@gmail.com" is the same person as "Wang 
Shaoyan". Now that I know it it's okay. Maybe you want to adjust your config 
(maybe user.name in git) to give others a hint that they are the same.
I will apply your patch to my tree when linux-next is reopened for new material 
(when -rc1 is released).


Thanks,

Florian Tobias Schandinat

On 08/06/2011 03:03 PM, Wang Shaoyan wrote:
> hi, the gmail is just to send patch, I have to use it, because my work
> mail server will append some spam information. So my signed-off-by is
> right author, that's why I add an obvious "From:". Sorry to trobule
> you.
>
>> But as I assume you, who sent this email, are not the original author,
>> please resent it with your Signed-off-by added. (as keeping track who
>> received the patch from whom is one reasons for having those)
>
>


^ permalink raw reply

* Subject: [PATCH] savagefb: Fix savage4 series video chip detection
From: John Stanley @ 2011-08-06 22:27 UTC (permalink / raw)
  To: linux-fbdev

From: John Stanley <jpsinthemix@verizon.net>

savagefb: Fix typo causing regression in savage4 series video chip detection

Two additional savage4 variants were added, but the S3_SAVAGE4_SERIES 
macro was
incompletely modified, resulting in a false positive detection of a 
savage4 card
regardless of which savage card is actually present. For non-savage4 series
cards, such as a Savage/IX-MV card, this results in garbled video and/or a
hard-hang at boot time. Fix this by changing an '||' to an '&&' in the
S3_SAVAGE4_SERIES macro.

Signed-off-by: John P. Stanley <jpsinthemix@verizon.net>
Reviewed-by: Tormod Volden <debian.tormod@gmail.com>
Cc: stable@kernel.org

---

Specifically, prior to linux-3.0, there were two savage4 variants 
(S3_SAVAGE4
and S3_PROSAVAGE). Hence, S3_SAVAGE4_SERIES was defined as

   S3_SAVAGE4 or S3_PROSAVAGE

In linux-3.0, two additional savage4 variants (S3_TWISTER and 
S3_PROSAVAGEDDR)
have been added. Hence S3_SAVAGE4_SERIES should be defined as

   S3_SAVAGE4, S3_PROSAVAGE, S3_TWISTER, or S3_PROSAVAGEDDR

However, the #define macro for S3_SAVAGE4_SERIES was incompletely 
updated: the
'||' should have been changed to an '&&'.

--- linux-3.0.0/drivers/video/savage/savagefb.h.orig    2011-07-21 
22:17:23.000000000 -0400
+++ linux-3.0.0/drivers/video/savage/savagefb.h 2011-07-31 
05:27:47.314798215 -0400
@@ -55,7 +55,7 @@

  #define S3_SAVAGE3D_SERIES(chip)  ((chip>=S3_SAVAGE3D) && 
(chip<=S3_SAVAGE_MX))

-#define S3_SAVAGE4_SERIES(chip)   ((chip>=S3_SAVAGE4) || 
(chip<=S3_PROSAVAGEDDR))
+#define S3_SAVAGE4_SERIES(chip)   ((chip>=S3_SAVAGE4) && 
(chip<=S3_PROSAVAGEDDR))

  #define S3_SAVAGE_MOBILE_SERIES(chip)  ((chip=S3_SAVAGE_MX) || 
(chip=S3_SUPERSAVAGE))


^ permalink raw reply

* [PATCH] viafb: replace strict_strtoul to kstrtoul and check return value
From: stufever @ 2011-08-07 13:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-fbdev, FlorianSchandinat, lethal, Wang Shaoyan

From: Wang Shaoyan <wangshaoyan.pt@taobao.com>

This commit replace the function strict_strtoul(becasue commit 33ee3b2e), and check the return value to avoid such warning:

  drivers/video/via/viafbdev.c:1992: warning: ignoring return value of 'kstrtoul', declared with attribute warn_unused_result

Signed-off-by: Wang Shaoyan <wangshaoyan.pt@taobao.com>
---
 drivers/video/via/viafbdev.c |  137 ++++++++++++++++++++++++------------------
 1 files changed, 79 insertions(+), 58 deletions(-)

diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index 53aa443..5f638d6 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -1158,7 +1158,8 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,
 	for (i = 0; i < 3; i++) {
 		value = strsep(&pbuf, " ");
 		if (value != NULL) {
-			strict_strtoul(value, 0, (unsigned long *)&reg_val);
+			if (kstrtoul(value, 0, (unsigned long *)&reg_val) < 0)
+				return -EINVAL;
 			DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
 				  reg_val);
 			switch (i) {
@@ -1228,7 +1229,8 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,
 	for (i = 0; i < 3; i++) {
 		value = strsep(&pbuf, " ");
 		if (value != NULL) {
-			strict_strtoul(value, 0, (unsigned long *)&reg_val);
+			if (kstrtoul(value, 0, (unsigned long *)&reg_val) < 0)
+				return -EINVAL;
 			switch (i) {
 			case 0:
 				viafb_write_reg_mask(CR9B, VIACR,
@@ -1286,7 +1288,8 @@ static ssize_t viafb_dfph_proc_write(struct file *file,
 	if (copy_from_user(&buf[0], buffer, length))
 		return -EFAULT;
 	buf[length - 1] = '\0';	/*Ensure end string */
-	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+	if (kstrtoul(&buf[0], 0, (unsigned long *)&reg_val) < 0)
+		return -EINVAL;
 	viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
 	return count;
 }
@@ -1325,7 +1328,8 @@ static ssize_t viafb_dfpl_proc_write(struct file *file,
 	if (copy_from_user(&buf[0], buffer, length))
 		return -EFAULT;
 	buf[length - 1] = '\0';	/*Ensure end string */
-	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+	if (kstrtoul(&buf[0], 0, (unsigned long *)&reg_val) < 0)
+		return -EINVAL;
 	viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
 	return count;
 }
@@ -1394,8 +1398,9 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
 		for (i = 0; i < 2; i++) {
 			value = strsep(&pbuf, " ");
 			if (value != NULL) {
-				strict_strtoul(value, 0,
-					(unsigned long *)&reg_val.Data);
+				if (kstrtoul(value, 0,
+					(unsigned long *)&reg_val.Data) < 0)
+					return -EINVAL;
 				switch (i) {
 				case 0:
 					reg_val.Index = 0x08;
@@ -1431,8 +1436,9 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
 		for (i = 0; i < 2; i++) {
 			value = strsep(&pbuf, " ");
 			if (value != NULL) {
-				strict_strtoul(value, 0,
-					(unsigned long *)&reg_val.Data);
+				if (kstrtoul(value, 0,
+					(unsigned long *)&reg_val.Data) < 0)
+					return -EINVAL;
 				switch (i) {
 				case 0:
 					reg_val.Index = 0x08;
@@ -1950,61 +1956,76 @@ static int __init viafb_setup(void)
 		if (!*this_opt)
 			continue;
 
-		if (!strncmp(this_opt, "viafb_mode1=", 12))
+		if (!strncmp(this_opt, "viafb_mode1=", 12)) {
 			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
-		else if (!strncmp(this_opt, "viafb_mode=", 11))
+		} else if (!strncmp(this_opt, "viafb_mode=", 11)) {
 			viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
-		else if (!strncmp(this_opt, "viafb_bpp1=", 11))
-			strict_strtoul(this_opt + 11, 0,
-				(unsigned long *)&viafb_bpp1);
-		else if (!strncmp(this_opt, "viafb_bpp=", 10))
-			strict_strtoul(this_opt + 10, 0,
-				(unsigned long *)&viafb_bpp);
-		else if (!strncmp(this_opt, "viafb_refresh1=", 15))
-			strict_strtoul(this_opt + 15, 0,
-				(unsigned long *)&viafb_refresh1);
-		else if (!strncmp(this_opt, "viafb_refresh=", 14))
-			strict_strtoul(this_opt + 14, 0,
-				(unsigned long *)&viafb_refresh);
-		else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
-			strict_strtoul(this_opt + 21, 0,
-				(unsigned long *)&viafb_lcd_dsp_method);
-		else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
-			strict_strtoul(this_opt + 19, 0,
-				(unsigned long *)&viafb_lcd_panel_id);
-		else if (!strncmp(this_opt, "viafb_accel=", 12))
-			strict_strtoul(this_opt + 12, 0,
-				(unsigned long *)&viafb_accel);
-		else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
-			strict_strtoul(this_opt + 14, 0,
-				(unsigned long *)&viafb_SAMM_ON);
-		else if (!strncmp(this_opt, "viafb_active_dev=", 17))
+		} else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
+			if (kstrtoul(this_opt + 11, 0,
+				(unsigned long *)&viafb_bpp1) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_bpp=", 10)) {
+			if (kstrtoul(this_opt + 10, 0,
+				(unsigned long *)&viafb_bpp) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_refresh1=", 15)) {
+			if (kstrtoul(this_opt + 15, 0,
+				(unsigned long *)&viafb_refresh1) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_refresh=", 14)) {
+			if (kstrtoul(this_opt + 14, 0,
+				(unsigned long *)&viafb_refresh) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) {
+			if (kstrtoul(this_opt + 21, 0,
+				(unsigned long *)&viafb_lcd_dsp_method) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) {
+			if (kstrtoul(this_opt + 19, 0,
+				(unsigned long *)&viafb_lcd_panel_id) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_accel=", 12)) {
+			if (kstrtoul(this_opt + 12, 0,
+				(unsigned long *)&viafb_accel) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) {
+			if (kstrtoul(this_opt + 14, 0,
+				(unsigned long *)&viafb_SAMM_ON) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
 			viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
-		else if (!strncmp(this_opt,
-			"viafb_display_hardware_layout=", 30))
-			strict_strtoul(this_opt + 30, 0,
-			(unsigned long *)&viafb_display_hardware_layout);
-		else if (!strncmp(this_opt, "viafb_second_size=", 18))
-			strict_strtoul(this_opt + 18, 0,
-				(unsigned long *)&viafb_second_size);
-		else if (!strncmp(this_opt,
-			"viafb_platform_epia_dvi=", 24))
-			strict_strtoul(this_opt + 24, 0,
-				(unsigned long *)&viafb_platform_epia_dvi);
-		else if (!strncmp(this_opt,
-			"viafb_device_lcd_dualedge=", 26))
-			strict_strtoul(this_opt + 26, 0,
-				(unsigned long *)&viafb_device_lcd_dualedge);
-		else if (!strncmp(this_opt, "viafb_bus_width=", 16))
-			strict_strtoul(this_opt + 16, 0,
-				(unsigned long *)&viafb_bus_width);
-		else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
-			strict_strtoul(this_opt + 15, 0,
-				(unsigned long *)&viafb_lcd_mode);
-		else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
+		} else if (!strncmp(this_opt,
+			"viafb_display_hardware_layout=", 30)) {
+			if (kstrtoul(this_opt + 30, 0,
+			(unsigned long *)&viafb_display_hardware_layout) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_second_size=", 18)) {
+			if (kstrtoul(this_opt + 18, 0,
+				(unsigned long *)&viafb_second_size) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt,
+			"viafb_platform_epia_dvi=", 24)) {
+			if ( kstrtoul(this_opt + 24, 0,
+				(unsigned long *)&viafb_platform_epia_dvi) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt,
+			"viafb_device_lcd_dualedge=", 26)) {
+			if (kstrtoul(this_opt + 26, 0,
+				(unsigned long *)&viafb_device_lcd_dualedge) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_bus_width=", 16)) {
+			if (kstrtoul(this_opt + 16, 0,
+				(unsigned long *)&viafb_bus_width) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) {
+			if (kstrtoul(this_opt + 15, 0,
+				(unsigned long *)&viafb_lcd_mode) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
 			viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
-		else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
+		} else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
 			viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
+		}
 	}
 	return 0;
 }
-- 
1.7.0.4


^ permalink raw reply related

* Re: [PATCH] viafb: replace strict_strtoul to kstrtoul and check return
From: Florian Tobias Schandinat @ 2011-08-07 14:20 UTC (permalink / raw)
  To: stufever; +Cc: linux-kernel, linux-fbdev, lethal, Wang Shaoyan
In-Reply-To: <1312723884-21790-1-git-send-email-wangshaoyan.pt@taobao.com>

Hi Wang,

On 08/07/2011 01:31 PM, stufever@gmail.com wrote:
> From: Wang Shaoyan<wangshaoyan.pt@taobao.com>
>
> This commit replace the function strict_strtoul(becasue commit 33ee3b2e), and check the return value to avoid such warning:
>
>    drivers/video/via/viafbdev.c:1992: warning: ignoring return value of 'kstrtoul', declared with attribute warn_unused_result

well I'm not against using the new functions but if you do this change please 
try to have a look why those were introduced.

> Signed-off-by: Wang Shaoyan<wangshaoyan.pt@taobao.com>
> ---
>   drivers/video/via/viafbdev.c |  137 ++++++++++++++++++++++++------------------
>   1 files changed, 79 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
> index 53aa443..5f638d6 100644
> --- a/drivers/video/via/viafbdev.c
> +++ b/drivers/video/via/viafbdev.c
> @@ -1158,7 +1158,8 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,
>   	for (i = 0; i<  3; i++) {
>   		value = strsep(&pbuf, " ");
>   		if (value != NULL) {
> -			strict_strtoul(value, 0, (unsigned long *)&reg_val);
> +			if (kstrtoul(value, 0, (unsigned long *)&reg_val)<  0)
> +				return -EINVAL;

Ugh, the old code was ugly (casting u8* to unsigned long*) but you did not 
really improve it although the new functions were introduced for cases like 
this. You should use kstrtou8() here, I think.
It would also be nice if you could add range checks for the value entered as the 
behavior to -EINVAL on values > 255 but accepting too big values that are <= 255 
is not very consistent. Okay, as I know that doing this right would be difficult 
I'll accept this patch without them or without them being 100% accurate.

>   			DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
>   				  reg_val);
>   			switch (i) {
> @@ -1228,7 +1229,8 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,
>   	for (i = 0; i<  3; i++) {
>   		value = strsep(&pbuf, " ");
>   		if (value != NULL) {
> -			strict_strtoul(value, 0, (unsigned long *)&reg_val);
> +			if (kstrtoul(value, 0, (unsigned long *)&reg_val)<  0)
> +				return -EINVAL;

Same here.

>   			switch (i) {
>   			case 0:
>   				viafb_write_reg_mask(CR9B, VIACR,
> @@ -1286,7 +1288,8 @@ static ssize_t viafb_dfph_proc_write(struct file *file,
>   	if (copy_from_user(&buf[0], buffer, length))
>   		return -EFAULT;
>   	buf[length - 1] = '\0';	/*Ensure end string */
> -	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
> +	if (kstrtoul(&buf[0], 0, (unsigned long *)&reg_val)<  0)
> +		return -EINVAL;

Same here. And the &buf[0] is somewhat misleading, can you please correct it to 
be just buf?

>   	viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
>   	return count;
>   }
> @@ -1325,7 +1328,8 @@ static ssize_t viafb_dfpl_proc_write(struct file *file,
>   	if (copy_from_user(&buf[0], buffer, length))
>   		return -EFAULT;
>   	buf[length - 1] = '\0';	/*Ensure end string */
> -	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
> +	if (kstrtoul(&buf[0], 0, (unsigned long *)&reg_val)<  0)
> +		return -EINVAL;

Same as above.

>   	viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
>   	return count;
>   }
> @@ -1394,8 +1398,9 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
>   		for (i = 0; i<  2; i++) {
>   			value = strsep(&pbuf, " ");
>   			if (value != NULL) {
> -				strict_strtoul(value, 0,
> -					(unsigned long *)&reg_val.Data);
> +				if (kstrtoul(value, 0,
> +					(unsigned long *)&reg_val.Data)<  0)
> +					return -EINVAL;

Again this u8 thing.

>   				switch (i) {
>   				case 0:
>   					reg_val.Index = 0x08;
> @@ -1431,8 +1436,9 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
>   		for (i = 0; i<  2; i++) {
>   			value = strsep(&pbuf, " ");
>   			if (value != NULL) {
> -				strict_strtoul(value, 0,
> -					(unsigned long *)&reg_val.Data);
> +				if (kstrtoul(value, 0,
> +					(unsigned long *)&reg_val.Data)<  0)
> +					return -EINVAL;

And again.

>   				switch (i) {
>   				case 0:
>   					reg_val.Index = 0x08;
> @@ -1950,61 +1956,76 @@ static int __init viafb_setup(void)
>   		if (!*this_opt)
>   			continue;
>
> -		if (!strncmp(this_opt, "viafb_mode1=", 12))
> +		if (!strncmp(this_opt, "viafb_mode1=", 12)) {
>   			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
> -		else if (!strncmp(this_opt, "viafb_mode=", 11))
> +		} else if (!strncmp(this_opt, "viafb_mode=", 11)) {
>   			viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
> -		else if (!strncmp(this_opt, "viafb_bpp1=", 11))
> -			strict_strtoul(this_opt + 11, 0,
> -				(unsigned long *)&viafb_bpp1);
> -		else if (!strncmp(this_opt, "viafb_bpp=", 10))
> -			strict_strtoul(this_opt + 10, 0,
> -				(unsigned long *)&viafb_bpp);
> -		else if (!strncmp(this_opt, "viafb_refresh1=", 15))
> -			strict_strtoul(this_opt + 15, 0,
> -				(unsigned long *)&viafb_refresh1);
> -		else if (!strncmp(this_opt, "viafb_refresh=", 14))
> -			strict_strtoul(this_opt + 14, 0,
> -				(unsigned long *)&viafb_refresh);
> -		else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
> -			strict_strtoul(this_opt + 21, 0,
> -				(unsigned long *)&viafb_lcd_dsp_method);
> -		else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
> -			strict_strtoul(this_opt + 19, 0,
> -				(unsigned long *)&viafb_lcd_panel_id);
> -		else if (!strncmp(this_opt, "viafb_accel=", 12))
> -			strict_strtoul(this_opt + 12, 0,
> -				(unsigned long *)&viafb_accel);
> -		else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
> -			strict_strtoul(this_opt + 14, 0,
> -				(unsigned long *)&viafb_SAMM_ON);
> -		else if (!strncmp(this_opt, "viafb_active_dev=", 17))
> +		} else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
> +			if (kstrtoul(this_opt + 11, 0,
> +				(unsigned long *)&viafb_bpp1)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_bpp=", 10)) {
> +			if (kstrtoul(this_opt + 10, 0,
> +				(unsigned long *)&viafb_bpp)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_refresh1=", 15)) {
> +			if (kstrtoul(this_opt + 15, 0,
> +				(unsigned long *)&viafb_refresh1)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_refresh=", 14)) {
> +			if (kstrtoul(this_opt + 14, 0,
> +				(unsigned long *)&viafb_refresh)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) {
> +			if (kstrtoul(this_opt + 21, 0,
> +				(unsigned long *)&viafb_lcd_dsp_method)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) {
> +			if (kstrtoul(this_opt + 19, 0,
> +				(unsigned long *)&viafb_lcd_panel_id)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_accel=", 12)) {
> +			if (kstrtoul(this_opt + 12, 0,
> +				(unsigned long *)&viafb_accel)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) {
> +			if (kstrtoul(this_opt + 14, 0,
> +				(unsigned long *)&viafb_SAMM_ON)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
>   			viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
> -		else if (!strncmp(this_opt,
> -			"viafb_display_hardware_layout=", 30))
> -			strict_strtoul(this_opt + 30, 0,
> -			(unsigned long *)&viafb_display_hardware_layout);
> -		else if (!strncmp(this_opt, "viafb_second_size=", 18))
> -			strict_strtoul(this_opt + 18, 0,
> -				(unsigned long *)&viafb_second_size);
> -		else if (!strncmp(this_opt,
> -			"viafb_platform_epia_dvi=", 24))
> -			strict_strtoul(this_opt + 24, 0,
> -				(unsigned long *)&viafb_platform_epia_dvi);
> -		else if (!strncmp(this_opt,
> -			"viafb_device_lcd_dualedge=", 26))
> -			strict_strtoul(this_opt + 26, 0,
> -				(unsigned long *)&viafb_device_lcd_dualedge);
> -		else if (!strncmp(this_opt, "viafb_bus_width=", 16))
> -			strict_strtoul(this_opt + 16, 0,
> -				(unsigned long *)&viafb_bus_width);
> -		else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
> -			strict_strtoul(this_opt + 15, 0,
> -				(unsigned long *)&viafb_lcd_mode);
> -		else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
> +		} else if (!strncmp(this_opt,
> +			"viafb_display_hardware_layout=", 30)) {
> +			if (kstrtoul(this_opt + 30, 0,
> +			(unsigned long *)&viafb_display_hardware_layout)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_second_size=", 18)) {
> +			if (kstrtoul(this_opt + 18, 0,
> +				(unsigned long *)&viafb_second_size)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt,
> +			"viafb_platform_epia_dvi=", 24)) {
> +			if ( kstrtoul(this_opt + 24, 0,
> +				(unsigned long *)&viafb_platform_epia_dvi)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt,
> +			"viafb_device_lcd_dualedge=", 26)) {
> +			if (kstrtoul(this_opt + 26, 0,
> +				(unsigned long *)&viafb_device_lcd_dualedge)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_bus_width=", 16)) {
> +			if (kstrtoul(this_opt + 16, 0,
> +				(unsigned long *)&viafb_bus_width)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) {
> +			if (kstrtoul(this_opt + 15, 0,
> +				(unsigned long *)&viafb_lcd_mode)<  0)
> +				return -EINVAL;
> +		} else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
>   			viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
> -		else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
> +		} else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
>   			viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
> +		}
>   	}
>   	return 0;
>   }

Please try to use the correct functions (kstrtoint, ...) here too, basically you 
should no longer have any need for casting pointers.


Thanks,

Florian Tobias Schandinat


^ permalink raw reply

* [PATCH V2] replace strict_strtoul to kstrto[*] and check return value
From: stufever @ 2011-08-07 15:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-fbdev, FlorianSchandinat, lethal, Wang Shaoyan

From: Wang Shaoyan <wangshaoyan.pt@taobao.com>

Change since V1:
  1.use kstrto*, not kstrtoul
  2.replace &buf[0] to buf

This commit replace the function strict_strtoul(becasue commit 33ee3b2e), and check the return value to avoid such warning:

  drivers/video/via/viafbdev.c:1992: warning: ignoring return value of 'kstrtoul', declared with attribute warn_unused_result

Signed-off-by: Wang Shaoyan <wangshaoyan.pt@taobao.com>
---
 drivers/video/via/viafbdev.c |  126 ++++++++++++++++++++++-------------------
 1 files changed, 68 insertions(+), 58 deletions(-)

diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index 53aa443..7074fc7 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -1158,7 +1158,8 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,
 	for (i = 0; i < 3; i++) {
 		value = strsep(&pbuf, " ");
 		if (value != NULL) {
-			strict_strtoul(value, 0, (unsigned long *)&reg_val);
+			if (kstrtou8(value, 0, &reg_val) < 0)
+				return -EINVAL;
 			DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
 				  reg_val);
 			switch (i) {
@@ -1228,7 +1229,8 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,
 	for (i = 0; i < 3; i++) {
 		value = strsep(&pbuf, " ");
 		if (value != NULL) {
-			strict_strtoul(value, 0, (unsigned long *)&reg_val);
+			if (kstrtou8(value, 0, &reg_val) < 0)
+				return -EINVAL;
 			switch (i) {
 			case 0:
 				viafb_write_reg_mask(CR9B, VIACR,
@@ -1286,7 +1288,8 @@ static ssize_t viafb_dfph_proc_write(struct file *file,
 	if (copy_from_user(&buf[0], buffer, length))
 		return -EFAULT;
 	buf[length - 1] = '\0';	/*Ensure end string */
-	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+	if (kstrtou8(buf, 0, &reg_val) < 0)
+		return -EINVAL;
 	viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
 	return count;
 }
@@ -1325,7 +1328,8 @@ static ssize_t viafb_dfpl_proc_write(struct file *file,
 	if (copy_from_user(&buf[0], buffer, length))
 		return -EFAULT;
 	buf[length - 1] = '\0';	/*Ensure end string */
-	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
+	if (kstrtou8(buf, -1, &reg_val) < 0)
+		return -EINVAL;
 	viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
 	return count;
 }
@@ -1394,8 +1398,8 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
 		for (i = 0; i < 2; i++) {
 			value = strsep(&pbuf, " ");
 			if (value != NULL) {
-				strict_strtoul(value, 0,
-					(unsigned long *)&reg_val.Data);
+				if (kstrtou8(value, 0, &reg_val.Data) < 0)
+					return -EINVAL;
 				switch (i) {
 				case 0:
 					reg_val.Index = 0x08;
@@ -1431,8 +1435,8 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,
 		for (i = 0; i < 2; i++) {
 			value = strsep(&pbuf, " ");
 			if (value != NULL) {
-				strict_strtoul(value, 0,
-					(unsigned long *)&reg_val.Data);
+				if (kstrtou8(value, 0, &reg_val.Data) < 0)
+					return -EINVAL;
 				switch (i) {
 				case 0:
 					reg_val.Index = 0x08;
@@ -1950,61 +1954,67 @@ static int __init viafb_setup(void)
 		if (!*this_opt)
 			continue;
 
-		if (!strncmp(this_opt, "viafb_mode1=", 12))
+		if (!strncmp(this_opt, "viafb_mode1=", 12)) {
 			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
-		else if (!strncmp(this_opt, "viafb_mode=", 11))
+		} else if (!strncmp(this_opt, "viafb_mode=", 11)) {
 			viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
-		else if (!strncmp(this_opt, "viafb_bpp1=", 11))
-			strict_strtoul(this_opt + 11, 0,
-				(unsigned long *)&viafb_bpp1);
-		else if (!strncmp(this_opt, "viafb_bpp=", 10))
-			strict_strtoul(this_opt + 10, 0,
-				(unsigned long *)&viafb_bpp);
-		else if (!strncmp(this_opt, "viafb_refresh1=", 15))
-			strict_strtoul(this_opt + 15, 0,
-				(unsigned long *)&viafb_refresh1);
-		else if (!strncmp(this_opt, "viafb_refresh=", 14))
-			strict_strtoul(this_opt + 14, 0,
-				(unsigned long *)&viafb_refresh);
-		else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
-			strict_strtoul(this_opt + 21, 0,
-				(unsigned long *)&viafb_lcd_dsp_method);
-		else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
-			strict_strtoul(this_opt + 19, 0,
-				(unsigned long *)&viafb_lcd_panel_id);
-		else if (!strncmp(this_opt, "viafb_accel=", 12))
-			strict_strtoul(this_opt + 12, 0,
-				(unsigned long *)&viafb_accel);
-		else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
-			strict_strtoul(this_opt + 14, 0,
-				(unsigned long *)&viafb_SAMM_ON);
-		else if (!strncmp(this_opt, "viafb_active_dev=", 17))
+		} else if (!strncmp(this_opt, "viafb_bpp1=", 11)) {
+			if (kstrtouint(this_opt + 11, 0, &viafb_bpp1) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_bpp=", 10)) {
+			if (kstrtouint(this_opt + 10, 0, &viafb_bpp) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_refresh1=", 15)) {
+			if (kstrtoint(this_opt + 15, 0, &viafb_refresh1) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_refresh=", 14)) {
+			if (kstrtoint(this_opt + 14, 0, &viafb_refresh) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) {
+			if (kstrtoint(this_opt + 21, 0, 
+				      &viafb_lcd_dsp_method) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) {
+			if (kstrtoint(this_opt + 19, 0, 
+				      &viafb_lcd_panel_id) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_accel=", 12)) {
+			if (kstrtoint(this_opt + 12, 0, &viafb_accel) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) {
+			if (kstrtoint(this_opt + 14, 0, &viafb_SAMM_ON) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_active_dev=", 17)) {
 			viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
-		else if (!strncmp(this_opt,
-			"viafb_display_hardware_layout=", 30))
-			strict_strtoul(this_opt + 30, 0,
-			(unsigned long *)&viafb_display_hardware_layout);
-		else if (!strncmp(this_opt, "viafb_second_size=", 18))
-			strict_strtoul(this_opt + 18, 0,
-				(unsigned long *)&viafb_second_size);
-		else if (!strncmp(this_opt,
-			"viafb_platform_epia_dvi=", 24))
-			strict_strtoul(this_opt + 24, 0,
-				(unsigned long *)&viafb_platform_epia_dvi);
-		else if (!strncmp(this_opt,
-			"viafb_device_lcd_dualedge=", 26))
-			strict_strtoul(this_opt + 26, 0,
-				(unsigned long *)&viafb_device_lcd_dualedge);
-		else if (!strncmp(this_opt, "viafb_bus_width=", 16))
-			strict_strtoul(this_opt + 16, 0,
-				(unsigned long *)&viafb_bus_width);
-		else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
-			strict_strtoul(this_opt + 15, 0,
-				(unsigned long *)&viafb_lcd_mode);
-		else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
+		} else if (!strncmp(this_opt,
+			"viafb_display_hardware_layout=", 30)) {
+			if (kstrtoint(this_opt + 30, 0, 
+				      &viafb_display_hardware_layout) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_second_size=", 18)) {
+			if (kstrtoint(this_opt + 18, 0, &viafb_second_size) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt,
+			"viafb_platform_epia_dvi=", 24)) {
+			if (kstrtoint(this_opt + 24, 0, 
+				      &viafb_platform_epia_dvi) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt,
+			"viafb_device_lcd_dualedge=", 26)) {
+			if (kstrtoint(this_opt + 26, 0,
+				      &viafb_device_lcd_dualedge) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_bus_width=", 16)) {
+			if (kstrtoint(this_opt + 16, 0, &viafb_bus_width) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) {
+			if (kstrtoint(this_opt + 15, 0, &viafb_lcd_mode) < 0)
+				return -EINVAL;
+		} else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) {
 			viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
-		else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
+		} else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) {
 			viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
+		}
 	}
 	return 0;
 }
-- 
1.7.0.4


^ permalink raw reply related

* [PATCH 0/6] viafb modesetting update 2
From: Florian Tobias Schandinat @ 2011-08-07 15:46 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat

Hi all,

this is the second patch series. It's a little less stable than the 
previous one but it contains some great internal improvements.
We do no longer rely on the modetable structure across all sections 
and we use the values in var directly for CRT and DVI when possible. 
Basically this enables us to allow arbitary modes passed in var. 
That's not implemented yet and probably will never be the default as 
we want to do some sanity checking in check_var for the devices 
connected but would allow overriding buggy information.
Anyway with these patches it will be very simple to avoid the buggy 
modetable we use at the moment.


Best regards,

Florian Tobias Schandinat


Florian Tobias Schandinat (6):
  viafb: add new funcions to select a single mode
  viafb: eliminate viafb_get_pixclock
  viafb: use information in var for modesetting
  viafb: seperate hardware initialization
  viafb: eliminate modetable dependancy of LCD modesetting
  viafb: get rid of the remaining modetable structure assumptions

 drivers/video/via/dvi.c      |   30 ++----
 drivers/video/via/dvi.h      |    3 +-
 drivers/video/via/global.c   |    2 +
 drivers/video/via/global.h   |    2 +
 drivers/video/via/hw.c       |  229 ++++++++++++++++-------------------------
 drivers/video/via/hw.h       |   12 +--
 drivers/video/via/lcd.c      |   12 +--
 drivers/video/via/lcd.h      |    5 +-
 drivers/video/via/share.h    |    4 -
 drivers/video/via/viafbdev.c |   38 +++----
 drivers/video/via/viamode.c  |   58 ++++++++---
 drivers/video/via/viamode.h  |    4 +-
 12 files changed, 177 insertions(+), 222 deletions(-)


^ permalink raw reply

* [PATCH 1/6] viafb: add new funcions to select a single mode
From: Florian Tobias Schandinat @ 2011-08-07 15:49 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312730859.git.FlorianSchandinat@gmx.de>

This patch introduces 2 new functions for selecting a single mode
based on hres, vres and refresh rate and changes some uses to use
those. The advantage is that it is less error prone than doing the
selection based on refresh rate everywhere and allows replacing the
modetable structure. This includes a little change that users may
notice: If a refresh rate was given as module parameters but does
not exist in the modetable prior to this patch a refresh rate of 60
was assumed and after this patch the closest supported refresh rate
to the one provided by the user is used.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/hw.c       |   45 ++++++++-------------------------
 drivers/video/via/hw.h       |    4 +-
 drivers/video/via/viafbdev.c |   24 +++++++++---------
 drivers/video/via/viamode.c  |   56 ++++++++++++++++++++++++++++++++---------
 drivers/video/via/viamode.h  |    2 +
 5 files changed, 70 insertions(+), 61 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index c5e7833..5e69c20 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -2035,40 +2035,24 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 
 int viafb_get_pixclock(int hres, int vres, int vmode_refresh)
 {
-	int i;
 	struct crt_mode_table *best;
-	struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
 
-	if (!vmode)
+	best = viafb_get_best_mode(hres, vres, vmode_refresh);
+	if (!best)
 		return RES_640X480_60HZ_PIXCLOCK;
 
-	best = &vmode->crtc[0];
-	for (i = 1; i < vmode->mode_array; i++) {
-		if (abs(vmode->crtc[i].refresh_rate - vmode_refresh)
-			< abs(best->refresh_rate - vmode_refresh))
-			best = &vmode->crtc[i];
-	}
-
 	return 1000000000 / (best->crtc.hor_total * best->crtc.ver_total)
 		* 1000 / best->refresh_rate;
 }
 
 int viafb_get_refresh(int hres, int vres, u32 long_refresh)
 {
-	int i;
 	struct crt_mode_table *best;
-	struct VideoModeTable *vmode = viafb_get_mode(hres, vres);
 
-	if (!vmode)
+	best = viafb_get_best_mode(hres, vres, long_refresh);
+	if (!best)
 		return 60;
 
-	best = &vmode->crtc[0];
-	for (i = 1; i < vmode->mode_array; i++) {
-		if (abs(vmode->crtc[i].refresh_rate - long_refresh)
-			< abs(best->refresh_rate - long_refresh))
-			best = &vmode->crtc[i];
-	}
-
 	if (abs(best->refresh_rate - long_refresh) > 3) {
 		if (hres = 1200 && vres = 900)
 			return 49; /* OLPC DCON only supports 50 Hz */
@@ -2170,21 +2154,14 @@ void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
 }
 
 /*According var's xres, yres fill var's other timing information*/
-void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
-	struct VideoModeTable *vmode_tbl)
+void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
+	struct crt_mode_table *mode)
 {
-	struct crt_mode_table *crt_timing = NULL;
 	struct display_timing crt_reg;
-	int i = 0, index = 0;
-	crt_timing = vmode_tbl->crtc;
-	for (i = 0; i < vmode_tbl->mode_array; i++) {
-		index = i;
-		if (crt_timing[i].refresh_rate = refresh)
-			break;
-	}
 
-	crt_reg = crt_timing[index].crtc;
-	var->pixclock = viafb_get_pixclock(var->xres, var->yres, refresh);
+	crt_reg = mode->crtc;
+	var->pixclock = viafb_get_pixclock(var->xres, var->yres,
+		mode->refresh_rate);
 	var->left_margin  	    crt_reg.hor_total - (crt_reg.hor_sync_start + crt_reg.hor_sync_end);
 	var->right_margin = crt_reg.hor_sync_start - crt_reg.hor_addr;
@@ -2194,8 +2171,8 @@ void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
 	var->lower_margin = crt_reg.ver_sync_start - crt_reg.ver_addr;
 	var->vsync_len = crt_reg.ver_sync_end;
 	var->sync = 0;
-	if (crt_timing[index].h_sync_polarity = POSITIVE)
+	if (mode->h_sync_polarity = POSITIVE)
 		var->sync |= FB_SYNC_HOR_HIGH_ACT;
-	if (crt_timing[index].v_sync_polarity = POSITIVE)
+	if (mode->v_sync_polarity = POSITIVE)
 		var->sync |= FB_SYNC_VERT_HIGH_ACT;
 }
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 1fd8d98..3b7e149 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -661,8 +661,8 @@ void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
 
 int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 	struct VideoModeTable *vmode_tbl1, int video_bpp1);
-void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
-	struct VideoModeTable *vmode_tbl);
+void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
+	struct crt_mode_table *mode);
 void __devinit viafb_init_chip_info(int chip_type);
 void __devinit viafb_init_dac(int set_iga);
 int viafb_get_pixclock(int hres, int vres, int vmode_refresh);
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index 3eaf607..0c0ef95 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -201,7 +201,6 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
 	struct fb_info *info)
 {
 	int depth, refresh;
-	struct VideoModeTable *vmode_entry;
 	struct viafb_par *ppar = info->par;
 	u32 line;
 
@@ -211,8 +210,10 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
 	if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
 		return -EINVAL;
 
-	vmode_entry = viafb_get_mode(var->xres, var->yres);
-	if (!vmode_entry) {
+	/* the refresh rate is not important here, as we only want to know
+	 * whether the resolution exists
+	 */
+	if (!viafb_get_best_mode(var->xres, var->yres, 60)) {
 		DEBUG_MSG(KERN_INFO
 			  "viafb: Mode %dx%dx%d not supported!!\n",
 			  var->xres, var->yres, var->bits_per_pixel);
@@ -254,7 +255,8 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
 		get_var_refresh(var));
 
 	/* Adjust var according to our driver's own table */
-	viafb_fill_var_timing_info(var, refresh, vmode_entry);
+	viafb_fill_var_timing_info(var,
+		viafb_get_best_mode(var->xres, var->yres, refresh));
 	if (var->accel_flags & FB_ACCELF_TEXT &&
 		!ppar->shared->vdev->engine_mmio)
 		var->accel_flags = 0;
@@ -1816,9 +1818,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 	default_var.xres_virtual = default_xres;
 	default_var.yres_virtual = default_yres;
 	default_var.bits_per_pixel = viafb_bpp;
-	viafb_fill_var_timing_info(&default_var, viafb_get_refresh(
-		default_var.xres, default_var.yres, viafb_refresh),
-		viafb_get_mode(default_var.xres, default_var.yres));
+	viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
+		default_var.xres, default_var.yres, viafb_refresh));
 	viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
 	viafbinfo->var = default_var;
 
@@ -1857,9 +1858,8 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
 		default_var.xres_virtual = viafb_second_xres;
 		default_var.yres_virtual = viafb_second_yres;
 		default_var.bits_per_pixel = viafb_bpp1;
-		viafb_fill_var_timing_info(&default_var, viafb_get_refresh(
-			default_var.xres, default_var.yres, viafb_refresh1),
-			viafb_get_mode(default_var.xres, default_var.yres));
+		viafb_fill_var_timing_info(&default_var, viafb_get_best_mode(
+			default_var.xres, default_var.yres, viafb_refresh1));
 
 		viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
 		viafb_check_var(&default_var, viafbinfo1);
@@ -2032,9 +2032,9 @@ int __init viafb_init(void)
 		return r;
 #endif
 	if (parse_mode(viafb_mode, &dummy_x, &dummy_y)
-		|| !viafb_get_mode(dummy_x, dummy_y)
+		|| !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh)
 		|| parse_mode(viafb_mode1, &dummy_x, &dummy_y)
-		|| !viafb_get_mode(dummy_x, dummy_y)
+		|| !viafb_get_best_mode(dummy_x, dummy_y, viafb_refresh1)
 		|| viafb_bpp < 0 || viafb_bpp > 32
 		|| viafb_bpp1 < 0 || viafb_bpp1 > 32
 		|| parse_active_dev())
diff --git a/drivers/video/via/viamode.c b/drivers/video/via/viamode.c
index 8a9f4fc..88096e5 100644
--- a/drivers/video/via/viamode.c
+++ b/drivers/video/via/viamode.c
@@ -863,26 +863,56 @@ int NUM_TOTAL_CLE266_ModeXregs = ARRAY_SIZE(CLE266_ModeXregs);
 int NUM_TOTAL_PATCH_MODE = ARRAY_SIZE(res_patch_table);
 
 
-struct VideoModeTable *viafb_get_mode(int hres, int vres)
+static struct VideoModeTable *get_modes(struct VideoModeTable *vmt, int n,
+	int hres, int vres)
 {
-	u32 i;
-	for (i = 0; i < ARRAY_SIZE(viafb_modes); i++)
-		if (viafb_modes[i].mode_array &&
-			viafb_modes[i].crtc[0].crtc.hor_addr = hres &&
-			viafb_modes[i].crtc[0].crtc.ver_addr = vres)
+	int i;
+
+	for (i = 0; i < n; i++)
+		if (vmt[i].mode_array &&
+			vmt[i].crtc[0].crtc.hor_addr = hres &&
+			vmt[i].crtc[0].crtc.ver_addr = vres)
 			return &viafb_modes[i];
 
 	return NULL;
 }
 
+static struct crt_mode_table *get_best_mode(struct VideoModeTable *vmt,
+	int refresh)
+{
+	struct crt_mode_table *best;
+	int i;
+
+	if (!vmt)
+		return NULL;
+
+	best = &vmt->crtc[0];
+	for (i = 1; i < vmt->mode_array; i++) {
+		if (abs(vmt->crtc[i].refresh_rate - refresh)
+			< abs(best->refresh_rate - refresh))
+			best = &vmt->crtc[i];
+	}
+
+	return best;
+}
+
+struct VideoModeTable *viafb_get_mode(int hres, int vres)
+{
+	return get_modes(viafb_modes, ARRAY_SIZE(viafb_modes), hres, vres);
+}
+
+struct crt_mode_table *viafb_get_best_mode(int hres, int vres, int refresh)
+{
+	return get_best_mode(viafb_get_mode(hres, vres), refresh);
+}
+
 struct VideoModeTable *viafb_get_rb_mode(int hres, int vres)
 {
-	u32 i;
-	for (i = 0; i < ARRAY_SIZE(viafb_rb_modes); i++)
-		if (viafb_rb_modes[i].mode_array &&
-			viafb_rb_modes[i].crtc[0].crtc.hor_addr = hres &&
-			viafb_rb_modes[i].crtc[0].crtc.ver_addr = vres)
-			return &viafb_rb_modes[i];
+	return get_modes(viafb_rb_modes, ARRAY_SIZE(viafb_rb_modes), hres,
+		vres);
+}
 
-	return NULL;
+struct crt_mode_table *viafb_get_best_rb_mode(int hres, int vres, int refresh)
+{
+	return get_best_mode(viafb_get_rb_mode(hres, vres), refresh);
 }
diff --git a/drivers/video/via/viamode.h b/drivers/video/via/viamode.h
index 3751289..0396581 100644
--- a/drivers/video/via/viamode.h
+++ b/drivers/video/via/viamode.h
@@ -61,6 +61,8 @@ extern struct patch_table res_patch_table[];
 extern struct VPITTable VPIT;
 
 struct VideoModeTable *viafb_get_mode(int hres, int vres);
+struct crt_mode_table *viafb_get_best_mode(int hres, int vres, int refresh);
 struct VideoModeTable *viafb_get_rb_mode(int hres, int vres);
+struct crt_mode_table *viafb_get_best_rb_mode(int hres, int vres, int refresh);
 
 #endif /* __VIAMODE_H__ */
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 2/6] viafb: eliminate viafb_get_pixclock
From: Florian Tobias Schandinat @ 2011-08-07 15:50 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312730859.git.FlorianSchandinat@gmx.de>

As there is only one user we can just insert the formula where
needed. Avoids one lookup in the modetable and
viafb_fill_var_timing_info does no longer depend on the modetable.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/hw.c    |   16 ++--------------
 drivers/video/via/hw.h    |    1 -
 drivers/video/via/share.h |    4 ----
 3 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 5e69c20..d7b9a9f 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -2033,18 +2033,6 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 	return 1;
 }
 
-int viafb_get_pixclock(int hres, int vres, int vmode_refresh)
-{
-	struct crt_mode_table *best;
-
-	best = viafb_get_best_mode(hres, vres, vmode_refresh);
-	if (!best)
-		return RES_640X480_60HZ_PIXCLOCK;
-
-	return 1000000000 / (best->crtc.hor_total * best->crtc.ver_total)
-		* 1000 / best->refresh_rate;
-}
-
 int viafb_get_refresh(int hres, int vres, u32 long_refresh)
 {
 	struct crt_mode_table *best;
@@ -2160,8 +2148,8 @@ void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
 	struct display_timing crt_reg;
 
 	crt_reg = mode->crtc;
-	var->pixclock = viafb_get_pixclock(var->xres, var->yres,
-		mode->refresh_rate);
+	var->pixclock = 1000000000 / (crt_reg.hor_total * crt_reg.ver_total)
+		* 1000 / mode->refresh_rate;
 	var->left_margin  	    crt_reg.hor_total - (crt_reg.hor_sync_start + crt_reg.hor_sync_end);
 	var->right_margin = crt_reg.hor_sync_start - crt_reg.hor_addr;
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 3b7e149..5516b02 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -665,7 +665,6 @@ void viafb_fill_var_timing_info(struct fb_var_screeninfo *var,
 	struct crt_mode_table *mode);
 void __devinit viafb_init_chip_info(int chip_type);
 void __devinit viafb_init_dac(int set_iga);
-int viafb_get_pixclock(int hres, int vres, int vmode_refresh);
 int viafb_get_refresh(int hres, int vres, u32 float_refresh);
 void viafb_update_device_setting(int hres, int vres, int bpp, int flag);
 
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 2906b2d..69d882c 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -636,10 +636,6 @@
 #define V_SYNC_SATRT_SHADOW_INDEX   18
 #define V_SYNC_END_SHADOW_INDEX     19
 
-/* Definition Video Mode Pixel Clock (picoseconds)
-*/
-#define RES_640X480_60HZ_PIXCLOCK    39722
-
 /* LCD display method
 */
 #define     LCD_EXPANDSION              0x00
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 3/6] viafb: use information in var for modesetting
From: Florian Tobias Schandinat @ 2011-08-07 15:51 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312730859.git.FlorianSchandinat@gmx.de>

This patch starts to use the information in var for modesetting for
CRT and DVI devices. This is the right thing as it allows us to use
more generic modes than the ones predefined by VIA. We do not yet
allow more generic modes as check_var still limits them to the
predefined ones but with this patch applied it would be really easy
to do so. A problem was VIAs SAMM mode as it has 2 different modes
but just one frame buffer device. This is solved by creating a
pseudo var which contains enough information to use it for
modesetting. Hopefully one day we can use information in var for all
modes that do not involve hardware scaling.
Well I'd like to say that the chance of regressions is low but it is
quite likely that the behaviour in some cases changed especially
when SAMM is involved. I hope we made it better than before in
particular the DVI frequency check was probably broken before and
hopefully works better now.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/dvi.c |   30 +++++--------
 drivers/video/via/dvi.h |    3 +-
 drivers/video/via/hw.c  |  107 +++++++++++++++++++++--------------------------
 drivers/video/via/hw.h  |    4 +-
 4 files changed, 61 insertions(+), 83 deletions(-)

diff --git a/drivers/video/via/dvi.c b/drivers/video/via/dvi.c
index c7ff5c0..9138e51 100644
--- a/drivers/video/via/dvi.c
+++ b/drivers/video/via/dvi.c
@@ -172,28 +172,20 @@ static int tmds_register_read_bytes(int index, u8 *buff, int buff_len)
 }
 
 /* DVI Set Mode */
-void viafb_dvi_set_mode(struct VideoModeTable *mode, int mode_bpp,
-	int set_iga)
+void viafb_dvi_set_mode(const struct fb_var_screeninfo *var, int iga)
 {
-	struct VideoModeTable *rb_mode;
-	struct crt_mode_table *pDviTiming;
-	unsigned long desirePixelClock, maxPixelClock;
-	pDviTiming = mode->crtc;
-	desirePixelClock = pDviTiming->refresh_rate
-		* pDviTiming->crtc.hor_total * pDviTiming->crtc.ver_total
-		/ 1000000;
-	maxPixelClock = (unsigned long)viaparinfo->
-		tmds_setting_info->max_pixel_clock;
-
-	DEBUG_MSG(KERN_INFO "\nDVI_set_mode!!\n");
-
-	if ((maxPixelClock != 0) && (desirePixelClock > maxPixelClock)) {
-		rb_mode = viafb_get_rb_mode(mode->crtc[0].crtc.hor_addr,
-			mode->crtc[0].crtc.ver_addr);
+	struct fb_var_screeninfo dvi_var = *var;
+	struct crt_mode_table *rb_mode;
+	int maxPixelClock;
+
+	maxPixelClock = viaparinfo->shared->tmds_setting_info.max_pixel_clock;
+	if (maxPixelClock && PICOS2KHZ(var->pixclock) / 1000 > maxPixelClock) {
+		rb_mode = viafb_get_best_rb_mode(var->xres, var->yres, 60);
 		if (rb_mode)
-			mode = rb_mode;
+			viafb_fill_var_timing_info(&dvi_var, rb_mode);
 	}
-	viafb_fill_crtc_timing(mode, mode_bpp / 8, set_iga);
+
+	viafb_fill_crtc_timing(&dvi_var, iga);
 }
 
 /* Sense DVI Connector */
diff --git a/drivers/video/via/dvi.h b/drivers/video/via/dvi.h
index f473dd0..e2116aa 100644
--- a/drivers/video/via/dvi.h
+++ b/drivers/video/via/dvi.h
@@ -59,7 +59,6 @@ void viafb_dvi_enable(void);
 bool __devinit viafb_tmds_trasmitter_identify(void);
 void __devinit viafb_init_dvi_size(struct tmds_chip_information *tmds_chip,
 	struct tmds_setting_information *tmds_setting);
-void viafb_dvi_set_mode(struct VideoModeTable *videoMode, int mode_bpp,
-	int set_iga);
+void viafb_dvi_set_mode(const struct fb_var_screeninfo *var, int iga);
 
 #endif /* __DVI_H__ */
diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index d7b9a9f..6845c82 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,49 +1467,40 @@ void viafb_set_vclock(u32 clk, int set_iga)
 	via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-void viafb_fill_crtc_timing(struct VideoModeTable *video_mode, int bpp_byte,
-	int set_iga)
+static struct display_timing var_to_timing(const struct fb_var_screeninfo *var)
 {
-	struct crt_mode_table *crt_table = video_mode->crtc;
-	struct display_timing crt_reg;
-	int i;
-	int index = 0;
-	int h_addr, v_addr;
-	u32 clock, refresh = viafb_refresh;
-
-	if (viafb_SAMM_ON && set_iga = IGA2)
-		refresh = viafb_refresh1;
-
-	for (i = 0; i < video_mode->mode_array; i++) {
-		index = i;
+	struct display_timing timing;
+
+	timing.hor_addr = var->xres;
+	timing.hor_sync_start = timing.hor_addr + var->right_margin;
+	timing.hor_sync_end = timing.hor_sync_start + var->hsync_len;
+	timing.hor_total = timing.hor_sync_end + var->left_margin;
+	timing.hor_blank_start = timing.hor_addr;
+	timing.hor_blank_end = timing.hor_total;
+	timing.ver_addr = var->yres;
+	timing.ver_sync_start = timing.ver_addr + var->lower_margin;
+	timing.ver_sync_end = timing.ver_sync_start + var->vsync_len;
+	timing.ver_total = timing.ver_sync_end + var->upper_margin;
+	timing.ver_blank_start = timing.ver_addr;
+	timing.ver_blank_end = timing.ver_total;
+	return timing;
+}
 
-		if (crt_table[i].refresh_rate = refresh)
-			break;
-	}
+void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var, int iga)
+{
+	struct display_timing crt_reg = var_to_timing(var);
 
-	crt_reg = crt_table[index].crtc;
-	crt_reg.hor_blank_end += crt_reg.hor_blank_start;
-	crt_reg.hor_sync_end += crt_reg.hor_sync_start;
-	crt_reg.ver_blank_end += crt_reg.ver_blank_start;
-	crt_reg.ver_sync_end += crt_reg.ver_sync_start;
-	h_addr = crt_reg.hor_addr;
-	v_addr = crt_reg.ver_addr;
-	if (set_iga = IGA1)
+	if (iga = IGA1)
 		via_set_primary_timing(&crt_reg);
-	else if (set_iga = IGA2)
+	else if (iga = IGA2)
 		via_set_secondary_timing(&crt_reg);
 
-	viafb_load_fetch_count_reg(h_addr, bpp_byte, set_iga);
-
-	/* load FIFO */
-	if ((viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
-	    && (viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400))
-		viafb_load_FIFO_reg(set_iga, h_addr, v_addr);
-
-	clock = crt_reg.hor_total * crt_reg.ver_total
-		* crt_table[index].refresh_rate;
-	viafb_set_vclock(clock, set_iga);
+	viafb_load_fetch_count_reg(var->xres, var->bits_per_pixel / 8, iga);
+	if (viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266
+		&& viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400)
+		viafb_load_FIFO_reg(iga, var->xres, var->yres);
 
+	viafb_set_vclock(PICOS2KHZ(var->pixclock) * 1000, iga);
 }
 
 void __devinit viafb_init_chip_info(int chip_type)
@@ -1788,6 +1779,7 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 	u8 value, index, mask;
 	struct crt_mode_table *crt_timing;
 	struct crt_mode_table *crt_timing1 = NULL;
+	struct fb_var_screeninfo var2;
 
 	device_screen_off();
 	crt_timing = vmode_tbl->crtc;
@@ -1894,17 +1886,24 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 
 	/* Clear On Screen */
 
+	if (viafb_dual_fb) {
+		var2 = viafbinfo1->var;
+	} else if (viafb_SAMM_ON) {
+		viafb_fill_var_timing_info(&var2, viafb_get_best_mode(
+			vmode_tbl1->crtc->crtc.hor_addr,
+			vmode_tbl1->crtc->crtc.ver_addr, viafb_refresh1));
+		var2.bits_per_pixel = viafbinfo->var.bits_per_pixel;
+	}
+
 	/* CRT set mode */
 	if (viafb_CRT_ON) {
-		if (viafb_SAMM_ON &&
-			viaparinfo->shared->iga2_devices & VIA_CRT) {
-			viafb_fill_crtc_timing(vmode_tbl1, video_bpp1 / 8,
-				IGA2);
-		} else {
-			viafb_fill_crtc_timing(vmode_tbl, video_bpp / 8,
+		if (viaparinfo->shared->iga2_devices & VIA_CRT
+			&& viafb_SAMM_ON)
+			viafb_fill_crtc_timing(&var2, IGA2);
+		else
+			viafb_fill_crtc_timing(&viafbinfo->var,
 				(viaparinfo->shared->iga1_devices & VIA_CRT)
 				? IGA1 : IGA2);
-		}
 
 		/* Patch if set_hres is not 8 alignment (1366) to viafb_setmode
 		to 8 alignment (1368),there is several pixels (2 pixels)
@@ -1918,22 +1917,12 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 	}
 
 	if (viafb_DVI_ON) {
-		if (viafb_SAMM_ON &&
-			(viaparinfo->tmds_setting_info->iga_path = IGA2)) {
-			viafb_dvi_set_mode(viafb_get_mode
-				     (viaparinfo->tmds_setting_info->h_active,
-				      viaparinfo->tmds_setting_info->
-				      v_active),
-				     video_bpp1, viaparinfo->
-				     tmds_setting_info->iga_path);
-		} else {
-			viafb_dvi_set_mode(viafb_get_mode
-				     (viaparinfo->tmds_setting_info->h_active,
-				      viaparinfo->
-				      tmds_setting_info->v_active),
-				     video_bpp, viaparinfo->
-				     tmds_setting_info->iga_path);
-		}
+		if (viaparinfo->shared->tmds_setting_info.iga_path = IGA2
+			&& viafb_SAMM_ON)
+			viafb_dvi_set_mode(&var2, IGA2);
+		else
+			viafb_dvi_set_mode(&viafbinfo->var,
+				viaparinfo->tmds_setting_info->iga_path);
 	}
 
 	if (viafb_LCD_ON) {
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 5516b02..46f65da 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,9 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-void viafb_fill_crtc_timing(struct VideoModeTable *video_mode, int bpp_byte,
-	int set_iga);
-
+void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var, int iga);
 void viafb_set_vclock(u32 CLK, int set_iga);
 void viafb_load_reg(int timing_value, int viafb_load_reg_num,
 	struct io_register *reg,
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 4/6] viafb: seperate hardware initialization
From: Florian Tobias Schandinat @ 2011-08-07 15:51 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312730859.git.FlorianSchandinat@gmx.de>

This patch splits the hardware initialization out of the modesetting
function which will make it easier to make it conditional and not
require starting from scratch for every mode change, which is
especially annoying in dual framebuffer mode.
This required some minor reordering but it should not influence its
functionality.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/hw.c |   48 ++++++++++++++++++++++++++++--------------------
 1 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 6845c82..76fad92 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1769,24 +1769,9 @@ static u8 get_sync(struct fb_info *info)
 	return polarity;
 }
 
-int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
-	struct VideoModeTable *vmode_tbl1, int video_bpp1)
+static void hw_init(void)
 {
-	int i, j;
-	int port;
-	u32 devices = viaparinfo->shared->iga1_devices
-		| viaparinfo->shared->iga2_devices;
-	u8 value, index, mask;
-	struct crt_mode_table *crt_timing;
-	struct crt_mode_table *crt_timing1 = NULL;
-	struct fb_var_screeninfo var2;
-
-	device_screen_off();
-	crt_timing = vmode_tbl->crtc;
-
-	if (viafb_SAMM_ON = 1) {
-		crt_timing1 = vmode_tbl1->crtc;
-	}
+	int i;
 
 	inb(VIAStatus);
 	outb(0x00, VIAAR);
@@ -1825,9 +1810,8 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 		break;
 	}
 
+	/* probably this should go to the scaling code one day */
 	viafb_write_regx(scaling_parameters, ARRAY_SIZE(scaling_parameters));
-	device_off();
-	via_set_state(devices, VIA_STATE_OFF);
 
 	/* Fill VPIT Parameters */
 	/* Write Misc Register */
@@ -1853,6 +1837,31 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 	inb(VIAStatus);
 	outb(0x20, VIAAR);
 
+	load_fix_bit_crtc_reg();
+}
+
+int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
+	struct VideoModeTable *vmode_tbl1, int video_bpp1)
+{
+	int j;
+	int port;
+	u32 devices = viaparinfo->shared->iga1_devices
+		| viaparinfo->shared->iga2_devices;
+	u8 value, index, mask;
+	struct crt_mode_table *crt_timing;
+	struct crt_mode_table *crt_timing1 = NULL;
+	struct fb_var_screeninfo var2;
+
+	device_screen_off();
+	crt_timing = vmode_tbl->crtc;
+	if (viafb_SAMM_ON = 1)
+		crt_timing1 = vmode_tbl1->crtc;
+
+	device_off();
+	via_set_state(devices, VIA_STATE_OFF);
+
+	hw_init();
+
 	/* Update Patch Register */
 
 	if ((viaparinfo->chip_info->gfx_chip_name = UNICHROME_CLE266
@@ -1868,7 +1877,6 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 		}
 	}
 
-	load_fix_bit_crtc_reg();
 	via_set_primary_pitch(viafbinfo->fix.line_length);
 	via_set_secondary_pitch(viafb_dual_fb ? viafbinfo1->fix.line_length
 		: viafbinfo->fix.line_length);
-- 
1.6.3.2


^ permalink raw reply related

* [PATCH 5/6] viafb: eliminate modetable dependancy of LCD modesetting
From: Florian Tobias Schandinat @ 2011-08-07 15:52 UTC (permalink / raw)
  To: linux-fbdev; +Cc: linux-kernel, Florian Tobias Schandinat
In-Reply-To: <cover.1312730859.git.FlorianSchandinat@gmx.de>

This patch removes the need for knowing the modetable structure
within the LCD modesetting function. The magic 60Hz refresh rate was
already there as always the first entry for a resolution was choosen
based on the ascending refresh rate ordering in the modetable.
For all but one this is at least 60Hz, if only higher frequencies
available we choose those like the code before did. The exception is
OLPC but that resolution has only one frequency so we get the same
behaviour there as well.

Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
---
 drivers/video/via/hw.c  |   20 ++++++++------------
 drivers/video/via/lcd.c |   12 +++++-------
 drivers/video/via/lcd.h |    5 ++---
 3 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 76fad92..30668bd 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1937,9 +1937,8 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 		if (viafb_SAMM_ON &&
 			(viaparinfo->lvds_setting_info->iga_path = IGA2)) {
 			viaparinfo->lvds_setting_info->bpp = video_bpp1;
-			viafb_lcd_set_mode(crt_timing1, viaparinfo->
-				lvds_setting_info,
-				     &viaparinfo->chip_info->lvds_chip_info);
+			viafb_lcd_set_mode(viaparinfo->lvds_setting_info,
+				&viaparinfo->chip_info->lvds_chip_info);
 		} else {
 			/* IGA1 doesn't have LCD scaling, so set it center. */
 			if (viaparinfo->lvds_setting_info->iga_path = IGA1) {
@@ -1947,18 +1946,16 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 				    LCD_CENTERING;
 			}
 			viaparinfo->lvds_setting_info->bpp = video_bpp;
-			viafb_lcd_set_mode(crt_timing, viaparinfo->
-				lvds_setting_info,
-				     &viaparinfo->chip_info->lvds_chip_info);
+			viafb_lcd_set_mode(viaparinfo->lvds_setting_info,
+				&viaparinfo->chip_info->lvds_chip_info);
 		}
 	}
 	if (viafb_LCD2_ON) {
 		if (viafb_SAMM_ON &&
 			(viaparinfo->lvds_setting_info2->iga_path = IGA2)) {
 			viaparinfo->lvds_setting_info2->bpp = video_bpp1;
-			viafb_lcd_set_mode(crt_timing1, viaparinfo->
-				lvds_setting_info2,
-				     &viaparinfo->chip_info->lvds_chip_info2);
+			viafb_lcd_set_mode(viaparinfo->lvds_setting_info2,
+				&viaparinfo->chip_info->lvds_chip_info2);
 		} else {
 			/* IGA1 doesn't have LCD scaling, so set it center. */
 			if (viaparinfo->lvds_setting_info2->iga_path = IGA1) {
@@ -1966,9 +1963,8 @@ int viafb_setmode(struct VideoModeTable *vmode_tbl, int video_bpp,
 				    LCD_CENTERING;
 			}
 			viaparinfo->lvds_setting_info2->bpp = video_bpp;
-			viafb_lcd_set_mode(crt_timing, viaparinfo->
-				lvds_setting_info2,
-				     &viaparinfo->chip_info->lvds_chip_info2);
+			viafb_lcd_set_mode(viaparinfo->lvds_setting_info2,
+				&viaparinfo->chip_info->lvds_chip_info2);
 		}
 	}
 
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 0a38e4d..5f3b4e3 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -548,9 +548,8 @@ static void lcd_patch_skew(struct lvds_setting_information
 }
 
 /* LCD Set Mode */
-void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
-		  struct lvds_setting_information *plvds_setting_info,
-		  struct lvds_chip_information *plvds_chip_info)
+void viafb_lcd_set_mode(struct lvds_setting_information *plvds_setting_info,
+	struct lvds_chip_information *plvds_chip_info)
 {
 	int set_iga = plvds_setting_info->iga_path;
 	int mode_bpp = plvds_setting_info->bpp;
@@ -560,15 +559,14 @@ void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
 	int panel_vres = plvds_setting_info->lcd_panel_vres;
 	u32 clock;
 	struct display_timing mode_crt_reg, panel_crt_reg, timing;
-	struct crt_mode_table *panel_crt_table = NULL;
-	struct VideoModeTable *vmode_tbl = viafb_get_mode(panel_hres,
-		panel_vres);
+	struct crt_mode_table *mode_crt_table, *panel_crt_table;
 
 	DEBUG_MSG(KERN_INFO "viafb_lcd_set_mode!!\n");
 	/* Get mode table */
+	mode_crt_table = viafb_get_best_mode(set_hres, set_vres, 60);
 	mode_crt_reg = mode_crt_table->crtc;
 	/* Get panel table Pointer */
-	panel_crt_table = vmode_tbl->crtc;
+	panel_crt_table = viafb_get_best_mode(panel_hres, panel_vres, 60);
 	panel_crt_reg = panel_crt_table->crtc;
 	DEBUG_MSG(KERN_INFO "bellow viafb_lcd_set_mode!!\n");
 	if (VT1636_LVDS = plvds_chip_info->lvds_chip_name)
diff --git a/drivers/video/via/lcd.h b/drivers/video/via/lcd.h
index 3b9e539..77ca7b8 100644
--- a/drivers/video/via/lcd.h
+++ b/drivers/video/via/lcd.h
@@ -76,9 +76,8 @@ void __devinit viafb_init_lvds_output_interface(struct lvds_chip_information
 				*plvds_chip_info,
 				struct lvds_setting_information
 				*plvds_setting_info);
-void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
-		  struct lvds_setting_information *plvds_setting_info,
-		  struct lvds_chip_information *plvds_chip_info);
+void viafb_lcd_set_mode(struct lvds_setting_information *plvds_setting_info,
+	struct lvds_chip_information *plvds_chip_info);
 bool __devinit viafb_lvds_trasmitter_identify(void);
 void viafb_init_lvds_output_interface(struct lvds_chip_information
 				*plvds_chip_info,
-- 
1.6.3.2


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox