2013-05-13 21:37:28

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 1/5] staging/xgifb: Remove uneccessary/simply if in XGINew_GetXG20DRAMType

Instead of storing the value in a temp variable, anding it with 1 and
assign data conditionally we can assign the value directly.

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/staging/xgifb/vb_init.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index 19ce5a9..9caf12a 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -54,14 +54,12 @@ XGINew_GetXG20DRAMType(struct xgi_hw_device_info *HwDeviceExtension,
udelay(800);
xgifb_reg_or(pVBInfo->P3d4, 0x4A, 0x80); /* Enable GPIOH read */
/* GPIOF 0:DVI 1:DVO */
- temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
+ data = xgifb_reg_get(pVBInfo->P3d4, 0x48);
/* HOTPLUG_SUPPORT */
/* for current XG20 & XG21, GPIOH is floating, driver will
* fix DDR temporarily */
- if (temp & 0x01) /* DVI read GPIOH */
- data = 1; /* DDRII */
- else
- data = 0; /* DDR */
+ /* DVI read GPIOH */
+ data &= 0x01; /* 1=DDRII, 0=DDR */
/* ~HOTPLUG_SUPPORT */
xgifb_reg_or(pVBInfo->P3d4, 0xB4, 0x02);
return data;
--
1.8.1.5


2013-05-13 21:37:34

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 4/5] staging/xgifb: Remove unnecessary binary calculation in GetXG27FPBits

If temp <= 2 no other bits than the lowest two (0x03) can be set anyway
-> this operation can be removed.

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/staging/xgifb/vb_init.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index ba8796f..090c424 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -1177,9 +1177,7 @@ static unsigned char GetXG27FPBits(struct vb_device_info *pVBInfo)
/* enable GPIOA/B/C read */
xgifb_reg_and_or(pVBInfo->P3d4, 0x4A, ~0x03, 0x03);
temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
- if (temp <= 2)
- temp &= 0x03;
- else
+ if (temp > 2)
temp = ((temp & 0x04) >> 1) | ((~temp) & 0x01);

xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
--
1.8.1.5

2013-05-13 21:37:32

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 5/5] staging/xgifb: Fix always false condition in vb_setmode.c (smatch)

Smatch complains:
drivers/staging/xgifb/vb_setmode.c:3181
XGI_SetLockRegs() warn: bitwise AND condition is false here

Since SetNTSCTV is defined as 0 in drivers/video/sis/initdef.h this is
correct.
-> Change the condition to == to fix this.

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/staging/xgifb/vb_setmode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c
index 3adec3f..5fb699d 100644
--- a/drivers/staging/xgifb/vb_setmode.c
+++ b/drivers/staging/xgifb/vb_setmode.c
@@ -3178,7 +3178,7 @@ static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
if (pVBInfo->VBInfo & SetCRT2ToTV) {
if (pVBInfo->TVInfo & TVSimuMode) {
if (ModeNo == 0x50) {
- if (pVBInfo->TVInfo & SetNTSCTV) {
+ if (pVBInfo->TVInfo == SetNTSCTV) {
xgifb_reg_set(pVBInfo->Part1Port,
0x07, 0x30);
xgifb_reg_set(pVBInfo->Part1Port,
--
1.8.1.5

2013-05-13 21:38:11

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 3/5] staging/xgifb: Consolidate function almost identical calls in XGINew_GetXG21Sense

Instead of calling xgifb_reg_and_or with almost identical parameters in
a simple if/else scenario, we assign the changing parameter to a temp
variable and call xgifb_reg_and_or only from one location.

-> Easier to read, easier to understand (especially wrt the line breaks)

(For the if condition we don't need the Temp variable, so we can use the
value directly).

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/staging/xgifb/vb_init.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index ab1706b..ba8796f 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -1115,17 +1115,11 @@ static void XGINew_GetXG21Sense(struct pci_dev *pdev,
xgifb_reg_or(pVBInfo->P3d4, 0x32, LCDSense);
/* Enable read GPIOF */
xgifb_reg_and_or(pVBInfo->P3d4, 0x4A, ~0x20, 0x20);
- Temp = xgifb_reg_get(pVBInfo->P3d4, 0x48) & 0x04;
- if (!Temp)
- xgifb_reg_and_or(pVBInfo->P3d4,
- 0x38,
- ~0xE0,
- 0x80); /* TMDS on chip */
+ if (xgifb_reg_get(pVBInfo->P3d4, 0x48) & 0x04)
+ Temp = 0xA0; /* Only DVO on chip */
else
- xgifb_reg_and_or(pVBInfo->P3d4,
- 0x38,
- ~0xE0,
- 0xA0); /* Only DVO on chip */
+ Temp = 0x80; /* TMDS on chip */
+ xgifb_reg_and_or(pVBInfo->P3d4, 0x38, ~0xE0, Temp);
/* Disable read GPIOF */
xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20);
}
--
1.8.1.5

2013-05-13 21:37:27

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 2/5] staging/xgifb: Remove unnecessary cases in XGINew_SenseLCD

The switch statement sets the temp value to zero for certain cases and
leaves it untouched for other cases -> all these other cases can be
combined in the default case.

Since an empty case containing only a break, it can be removed.

The patch also removes the if statement, as it uses the same value as the switch
for comparison, and includes the code into the switch.

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/staging/xgifb/vb_init.c | 51 ++++++++++++-----------------------------
1 file changed, 15 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index 9caf12a..ab1706b 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -1077,44 +1077,23 @@ static unsigned short XGINew_SenseLCD(struct xgi_hw_device_info
*HwDeviceExtension,
struct vb_device_info *pVBInfo)
{
- unsigned short temp;
-
- /* add lcd sense */
- if (HwDeviceExtension->ulCRT2LCDType == LCD_UNKNOWN) {
+ unsigned short temp = HwDeviceExtension->ulCRT2LCDType;
+
+ switch (HwDeviceExtension->ulCRT2LCDType) {
+ case LCD_640x480:
+ case LCD_1024x600:
+ case LCD_1152x864:
+ case LCD_1280x960:
+ case LCD_1152x768:
+ case LCD_1920x1440:
+ case LCD_2048x1536:
+ temp = 0; /* overwrite used ulCRT2LCDType */
+ break;
+ case LCD_UNKNOWN: /* unknown lcd, do nothing */
return 0;
- } else {
- temp = (unsigned short) HwDeviceExtension->ulCRT2LCDType;
- switch (HwDeviceExtension->ulCRT2LCDType) {
- case LCD_INVALID:
- case LCD_800x600:
- case LCD_1024x768:
- case LCD_1280x1024:
- break;
-
- case LCD_640x480:
- case LCD_1024x600:
- case LCD_1152x864:
- case LCD_1280x960:
- case LCD_1152x768:
- temp = 0;
- break;
-
- case LCD_1400x1050:
- case LCD_1280x768:
- case LCD_1600x1200:
- break;
-
- case LCD_1920x1440:
- case LCD_2048x1536:
- temp = 0;
- break;
-
- default:
- break;
- }
- xgifb_reg_and_or(pVBInfo->P3d4, 0x36, 0xF0, temp);
- return 1;
}
+ xgifb_reg_and_or(pVBInfo->P3d4, 0x36, 0xF0, temp);
+ return 1;
}

static void XGINew_GetXG21Sense(struct pci_dev *pdev,
--
1.8.1.5