Skip to contentSkip to conversation

i2c-ali1535: enable SPARC support

PATCH In review corentin.labbe 6 participants 8 messages Nov 24, 2011 – Jan 5, 2012 3 messages not in the archive I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c-ali1535: enable SPARC support

Hello

The i2c-ali1535 driver don't work on SPARC, this is because it assumes that ioport address are 16bits wide (address stored with an unsigned short). But on SPARC arch, ioports are mapped in memory and so are stored with an unsigned long.

This patch corrects this by using pci_resource_start for getting IOMEM base address, then reading the SMBBA of the i2c busse and using together for I/O access.

I like to thanks Jean DELVARE for reviewing of my patch.

Thanks

---

i2c/busses/i2c-ali1535.c renamed from i2c/busses/i2c-ali1535.c.orig +21 -7
@@ -132,7 +132,8 @@
 #define	ALI1535_SMBIO_EN	0x04	/* SMB I/O Space enable		*/
 
 static struct pci_driver ali1535_driver;
-static unsigned short ali1535_smba;
+static unsigned long ali1535_smba;
+static unsigned short ali1535_offset;
 
 /* Detect whether a ALI1535 can be found, and initialize it, where necessary.
    Note the differences between kernels with the old PCI BIOS interface and
@@ -149,15 +150,28 @@ static int __devinit ali1535_setup(struc
 		- We can use the addresses
 	*/
 
+	retval = pci_enable_device(dev);
+	if (retval) {
+		dev_err(&dev->dev, "ALI1535_smb can't enable device\n");
+		goto exit;
+	}
+
 	/* Determine the address of the SMBus area */
-	pci_read_config_word(dev, SMBBA, &ali1535_smba);
-	ali1535_smba &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1));
-	if (ali1535_smba == 0) {
+	pci_read_config_word(dev, SMBBA, &ali1535_offset);
+	dev_info(&dev->dev, "ALI1535_smb is at offset 0x%04x\n", ali1535_offset);
+	ali1535_offset &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1));
+	if (ali1535_offset == 0) {
 		dev_warn(&dev->dev,
 			"ALI1535_smb region uninitialized - upgrade BIOS?\n");
 		goto exit;
 	}
 
+	if ((pci_resource_flags(dev, 0) & IORESOURCE_IO) == 0) {
+		dev_err(&dev->dev, "ALI1535_smb bar 0 is not IORESOURCE_IO\n");
+		goto exit;
+	}
+	ali1535_smba = pci_resource_start(dev, 0) + ali1535_offset;
+	
 	retval = acpi_check_region(ali1535_smba, ALI1535_SMB_IOSIZE,
 				   ali1535_driver.name);
 	if (retval)
@@ -165,7 +179,7 @@ static int __devinit ali1535_setup(struc
 
 	if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
 			    ali1535_driver.name)) {
-		dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n",
+		dev_err(&dev->dev, "ALI1535_smb region 0x%lx already in use!\n",
 			ali1535_smba);
 		goto exit;
 	}
@@ -196,7 +210,7 @@ static int __devinit ali1535_setup(struc
 	*/
 	pci_read_config_byte(dev, SMBREV, &temp);
 	dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp);
-	dev_dbg(&dev->dev, "ALI1535_smba = 0x%X\n", ali1535_smba);
+	dev_dbg(&dev->dev, "ALI1535_smba = 0x%lx\n", ali1535_smba);
 
 	retval = 0;
 exit:
@@ -499,7 +513,7 @@ static int __devinit ali1535_probe(struc
 	ali1535_adapter.dev.parent = &dev->dev;
 
 	snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
-		"SMBus ALI1535 adapter at %04x", ali1535_smba);
+		"SMBus ALI1535 adapter at %04x", ali1535_offset);
 	return i2c_add_adapter(&ali1535_adapter);
 }
 
#1 lore raw
Quoted 4 lines

The i2c-ali1535 driver don't work on SPARC, this is because it assumes that ioport address are 16bits wide (address stored with an unsigned short). But on SPARC arch, ioports are mapped in memory and so are stored with an unsigned long.

This patch corrects this by using pci_resource_start for getting IOMEM base address, then reading the SMBBA of the i2c busse and using together for I/O access.

I tested it on my Sun Blade 100 on top of 3.2-rc3.

It seems to work:

# ls /sys/bus/i2c/devices/i2c-0/
0-0018/        0-0051/        0-0053/        device/        new_device     uevent
0-0050/        0-0052/        delete_device  name           subsystem/
# sensors
adm1023-i2c-0-18
Adapter: SMBus ALI1535 adapter at 0600
temp1:        +35.0°C  (low  = -55.0°C, high = +127.0°C)
temp2:        +75.8°C  (low  = -55.0°C, high = +127.0°C)

and decode-dimms from i2c-tools package displays the SPD eeproms of 0-005* also fine.

One thing that I noticed was these errors in the dmesg - I think they were there even before the patch:

[   64.677130] loop: module loaded
[   64.763143] i2c i2c-0: Error: command never completed
[   64.898968] i2c i2c-0: Error: command never completed
[   64.995848] i2c i2c-0: Error: command never completed
[   65.066294] i2c i2c-0: Error: command never completed
[   65.136705] i2c i2c-0: Error: command never completed
[   65.206817] i2c i2c-0: Error: command never completed
[   65.276818] i2c i2c-0: Error: command never completed
[   65.346817] i2c i2c-0: Error: command never completed
[   65.461240] i2c i2c-0: Error: command never completed
[   65.562828] i2c i2c-0: Error: command never completed
[   65.633312] i2c i2c-0: Error: command never completed
[   65.703706] i2c i2c-0: Error: command never completed

These only ahppened at bootup, no actual use later seems to trigger it.

# cat /sys/bus/i2c/devices/i2c-0/name
SMBus ALI1535 adapter at 0600
# cat /sys/bus/i2c/devices/i2c-1/name
bt878 #0 [sw]

So this is the ALI i2c adapter that emits the errors on startup - some module load perhaps. loop reference is there because this is the contents of my /etc/modules:

loop
adm1021
eeprom

and lsmod shows these mopdules wer loaded together:

# lsmod|head

Module                  Size  Used by
ipv6                  298281  18
eeprom                  2743  0
adm1021                 5987  0
hwmon                   1501  1 adm1021
loop                   15747  0

So it seems adm1021 module loading causes these messages?

Signature · 1 line
Meelis Roos ([email protected])
#2 lore raw
In reply to corentin.labbe

Hi Corentin,

Quoted 8 lines · corentin.labbe

Hello

The i2c-ali1535 driver don't work on SPARC, this is because it assumes that ioport address are 16bits wide (address stored with an unsigned short). But on SPARC arch, ioports are mapped in memory and so are stored with an unsigned long.

This patch corrects this by using pci_resource_start for getting IOMEM base address, then reading the SMBBA of the i2c busse and using together for I/O access.

I like to thanks Jean DELVARE for reviewing of my patch.

Apparently I wasn't good enough, see below :(

Quoted 19 lines

Thanks

---

i2c/busses/i2c-ali1535.c renamed from i2c/busses/i2c-ali1535.c.orig +2 -1
@@ -132,7 +132,8 @@
 #define	ALI1535_SMBIO_EN	0x04	/* SMB I/O Space enable		*/
 
 static struct pci_driver ali1535_driver;
-static unsigned short ali1535_smba;
+static unsigned long ali1535_smba;
+static unsigned short ali1535_offset;
 
 /* Detect whether a ALI1535 can be found, and initialize it, where necessary.
    Note the differences between kernels with the old PCI BIOS interface and

i2c/busses/i2c-ali1535.c static int __devinit ali1535_setup(struc · line 157

Quoted 8 lines
i2c/busses/i2c-ali1535.c renamed from i2c/busses/i2c-ali1535.c.orig +5 -0
@@ -149,15 +150,28 @@ static int __devinit ali1535_setup(struc
 		- We can use the addresses
 	*/
 
+	retval = pci_enable_device(dev);
+	if (retval) {
+		dev_err(&dev->dev, "ALI1535_smb can't enable device\n");
+		goto exit;
+	}

This overrides the initialization of retval to -ENODEV, which other error paths below were relying on. I'm sorry for asking you to return the error value from pci_enable_device(), I did not realize it would have this side effect.

OTOH I am just seeing that the call to acpi_check_region() already broke this months ago... So it needs to be fixed anyway.

i2c/busses/i2c-ali1535.c static int __devinit ali1535_setup(struc · line 161

Quoted 7 lines
i2c/busses/i2c-ali1535.c renamed from i2c/busses/i2c-ali1535.c.orig +3 -3
+
 	/* Determine the address of the SMBus area */
-	pci_read_config_word(dev, SMBBA, &ali1535_smba);
-	ali1535_smba &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1));
-	if (ali1535_smba == 0) {
+	pci_read_config_word(dev, SMBBA, &ali1535_offset);
+	dev_info(&dev->dev, "ALI1535_smb is at offset 0x%04x\n", ali1535_offset);

Was it really meant as dev_info, not dev_dbg?

Quoted 35 lines
i2c/busses/i2c-ali1535.c renamed from i2c/busses/i2c-ali1535.c.orig +10 -2
+	ali1535_offset &= (0xffff & ~(ALI1535_SMB_IOSIZE - 1));
+	if (ali1535_offset == 0) {
 		dev_warn(&dev->dev,
 			"ALI1535_smb region uninitialized - upgrade BIOS?\n");
 		goto exit;
 	}
 
+	if ((pci_resource_flags(dev, 0) & IORESOURCE_IO) == 0) {
+		dev_err(&dev->dev, "ALI1535_smb bar 0 is not IORESOURCE_IO\n");
+		goto exit;
+	}
+	ali1535_smba = pci_resource_start(dev, 0) + ali1535_offset;
+	
 	retval = acpi_check_region(ali1535_smba, ALI1535_SMB_IOSIZE,
 				   ali1535_driver.name);
 	if (retval)
@@ -165,7 +179,7 @@ static int __devinit ali1535_setup(struc
 
 	if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
 			    ali1535_driver.name)) {
-		dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n",
+		dev_err(&dev->dev, "ALI1535_smb region 0x%lx already in use!\n",
 			ali1535_smba);
 		goto exit;
 	}
@@ -196,7 +210,7 @@ static int __devinit ali1535_setup(struc
 	*/
 	pci_read_config_byte(dev, SMBREV, &temp);
 	dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp);
-	dev_dbg(&dev->dev, "ALI1535_smba = 0x%X\n", ali1535_smba);
+	dev_dbg(&dev->dev, "ALI1535_smba = 0x%lx\n", ali1535_smba);
 
 	retval = 0;
 exit:

i2c/busses/i2c-ali1535.c static int __devinit ali1535_probe(struc · line 519

Quoted 8 lines
i2c/busses/i2c-ali1535.c renamed from i2c/busses/i2c-ali1535.c.orig +1 -1
@@ -499,7 +513,7 @@ static int __devinit ali1535_probe(struc
 	ali1535_adapter.dev.parent = &dev->dev;
 
 	snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
-		"SMBus ALI1535 adapter at %04x", ali1535_smba);
+		"SMBus ALI1535 adapter at %04x", ali1535_offset);
 	return i2c_add_adapter(&ali1535_adapter);
 }
 

Other than this, the code looks OK. I'll fix the retval issue and adjust your patch accordingly.

Signature · 1 line
Jean Delvare
#4 lore raw
In reply to a message not in the archive

From: "corentin.labbe" <[email protected]>
Date: Thu, 24 Nov 2011 12:01:36 +0100

Quoted 10 lines

The i2c-ali1535 driver don't work on SPARC, this is because it assumes that ioport address are 16bits wide (address stored with an unsigned short). But on SPARC arch, ioports are mapped in memory and so are stored with an unsigned long.

This patch corrects this by using pci_resource_start for getting IOMEM base address, then reading the SMBBA of the i2c busse and using together for I/O access.

I like to thanks Jean DELVARE for reviewing of my patch.

Thanks

Jean has asked for some more changes, please follow his suggestions and resubmit, thanks.

#6 lore raw
In reply to a message not in the archive

Hi David,

Quoted 8 lines · David Miller

From: "corentin.labbe" <[email protected]>
Date: Thu, 24 Nov 2011 12:01:36 +0100

Quoted 5 lines

The i2c-ali1535 driver don't work on SPARC, this is because it assumes that ioport address are 16bits wide (address stored with an unsigned short). But on SPARC arch, ioports are mapped in memory and so are stored with an unsigned long.

This patch corrects this by using pci_resource_start for getting IOMEM base address, then reading the SMBBA of the i2c busse and using together for I/O access.

Quoted 8 lines
Quoted 5 lines

I like to thanks Jean DELVARE for reviewing of my patch.

Thanks

Jean has asked for some more changes, please follow his suggestions and resubmit, thanks.

Actually I ended up doing the changes myself, and the patch is queued for 3.3 already:
http://khali.linux-fr.org/devel/linux-3/jdelvare-i2c/i2c-ali1535-enable-sparc-support.patch

Please let me know quickly if you see anything wrong there.

Signature · 1 line
Jean Delvare
#8 lore raw
In reply to a message not in the archive

From: Jean Delvare <[email protected]>
Date: Thu, 5 Jan 2012 20:51:05 +0100

Quoted 17 lines

Hi David,

Quoted 14 lines · David Miller

From: "corentin.labbe" <[email protected]>
Date: Thu, 24 Nov 2011 12:01:36 +0100

Quoted 10 lines

The i2c-ali1535 driver don't work on SPARC, this is because it assumes that ioport address are 16bits wide (address stored with an unsigned short). But on SPARC arch, ioports are mapped in memory and so are stored with an unsigned long.

This patch corrects this by using pci_resource_start for getting IOMEM base address, then reading the SMBBA of the i2c busse and using together for I/O access.

I like to thanks Jean DELVARE for reviewing of my patch.

Thanks

Quoted 8 lines
Quoted 2 lines

Jean has asked for some more changes, please follow his suggestions and resubmit, thanks.

Actually I ended up doing the changes myself, and the patch is queued for 3.3 already:
http://khali.linux-fr.org/devel/linux-3/jdelvare-i2c/i2c-ali1535-enable-sparc-support.patch

Please let me know quickly if you see anything wrong there.

Using the raw PCI config register value in the non-IO case is always wrong and non-portable. You need to ioremap the thing using the PCI resource if it's not IO and therefore MEM.

More easier, if non-IO is really not expected, would be to fail the probe if we don't find IORESOURCE_IO set.

#9 lore raw
Quoted 6 lines · David Miller

From: Jean Delvare <[email protected]>
Date: Thu, 5 Jan 2012 20:51:05 +0100

Quoted 4 lines

Actually I ended up doing the changes myself, and the patch is queued for 3.3 already:
http://khali.linux-fr.org/devel/linux-3/jdelvare-i2c/i2c-ali1535-enable-sparc-support.patch

Quoted 8 lines
Quoted 1 line

Please let me know quickly if you see anything wrong there.

Using the raw PCI config register value in the non-IO case is always wrong and non-portable. You need to ioremap the thing using the PCI resource if it's not IO and therefore MEM.

More easier, if non-IO is really not expected, would be to fail the probe if we don't find IORESOURCE_IO set.

It's indeed not expected, and failing is what Corentin's original patch was doing. I had him change (actually did the change myself with his approval) to limit the risk of regression. I don't expect MEM but maybe no resource type at all (i.e. BAR 0 unused.)

The rationale is that old PC boards use the same PCI chipset and we were not able to find any tester. I have no idea what the PCI resources look like on these machines, but I know the driver used to work OK, so the strategy is to make the new code behave the same as the original code if things don't look as expected.

We can revisit if/when we find a tester with ALI1535 on x86.

Signature · 1 line
Jean Delvare
#10 lore raw

From: Jean Delvare <[email protected]>
Date: Thu, 5 Jan 2012 21:06:00 +0100

Quoted 13 lines · David Miller
Quoted 6 lines

Using the raw PCI config register value in the non-IO case is always wrong and non-portable. You need to ioremap the thing using the PCI resource if it's not IO and therefore MEM.

More easier, if non-IO is really not expected, would be to fail the probe if we don't find IORESOURCE_IO set.

It's indeed not expected, and failing is what Corentin's original patch was doing. I had him change (actually did the change myself with his approval) to limit the risk of regression. I don't expect MEM but maybe no resource type at all (i.e. BAR 0 unused.)

Quoted 7 lines

The rationale is that old PC boards use the same PCI chipset and we were not able to find any tester. I have no idea what the PCI resources look like on these machines, but I know the driver used to work OK, so the strategy is to make the new code behave the same as the original code if things don't look as expected.

We can revisit if/when we find a tester with ALI1535 on x86.

Ok.