Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 849be516 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare
Browse files

i2c-ali1563: Fix device initialization



The i2c-ali1563 initialization looks quite broken to me:
* If the I/O space isn't enabled, we forcibly set 3 bits in
  the PCI configuration space instead of just the one enabling
  the I/O space.
* After that we pretend to check if the write worked, but we
  don't actually read the new value from the register.
* It's probably not a good idea to enable the I/O space if no
  base address has been set.

So I propose the following changes to that part of the driver:
* Merge ali1563_enable() into ali1563_setup().
* Check the base address before the I/O space enabled bit.

Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarRudolf Marek <r.marek@assembler.cz>
parent 69735698
Loading
Loading
Loading
Loading
+18 −23
Original line number Original line Diff line number Diff line
@@ -314,42 +314,37 @@ static u32 ali1563_func(struct i2c_adapter * a)
}
}




static void ali1563_enable(struct pci_dev * dev)
{
	u16 ctrl;

	pci_read_config_word(dev,ALI1563_SMBBA,&ctrl);
	ctrl |= 0x7;
	pci_write_config_word(dev,ALI1563_SMBBA,ctrl);
}

static int __devinit ali1563_setup(struct pci_dev * dev)
static int __devinit ali1563_setup(struct pci_dev * dev)
{
{
	u16 ctrl;
	u16 ctrl;


	pci_read_config_word(dev,ALI1563_SMBBA,&ctrl);
	pci_read_config_word(dev,ALI1563_SMBBA,&ctrl);


	/* Check if device is even enabled first */
	/* SMB I/O Base in high 12 bits and must be aligned with the
	if (!(ctrl & ALI1563_SMB_IOEN)) {
	 * size of the I/O space. */
		dev_warn(&dev->dev,"I/O space not enabled, trying manually\n");
	ali1563_smba = ctrl & ~(ALI1563_SMB_IOSIZE - 1);
		ali1563_enable(dev);
	if (!ali1563_smba) {
	}
		dev_warn(&dev->dev,"ali1563_smba Uninitialized\n");
	if (!(ctrl & ALI1563_SMB_IOEN)) {
		dev_warn(&dev->dev,"I/O space still not enabled, giving up\n");
		goto Err;
		goto Err;
	}
	}

	/* Check if device is enabled */
	if (!(ctrl & ALI1563_SMB_HOSTEN)) {
	if (!(ctrl & ALI1563_SMB_HOSTEN)) {
		dev_warn(&dev->dev, "Host Controller not enabled\n");
		dev_warn(&dev->dev, "Host Controller not enabled\n");
		goto Err;
		goto Err;
	}
	}

	if (!(ctrl & ALI1563_SMB_IOEN)) {
	/* SMB I/O Base in high 12 bits and must be aligned with the
		dev_warn(&dev->dev, "I/O space not enabled, trying manually\n");
	 * size of the I/O space. */
		pci_write_config_word(dev, ALI1563_SMBBA,
	ali1563_smba = ctrl & ~(ALI1563_SMB_IOSIZE - 1);
				      ctrl | ALI1563_SMB_IOEN);
	if (!ali1563_smba) {
		pci_read_config_word(dev, ALI1563_SMBBA, &ctrl);
		dev_warn(&dev->dev,"ali1563_smba Uninitialized\n");
		if (!(ctrl & ALI1563_SMB_IOEN)) {
			dev_err(&dev->dev, "I/O space still not enabled, "
				"giving up\n");
			goto Err;
			goto Err;
		}
		}
	}

	if (!request_region(ali1563_smba, ALI1563_SMB_IOSIZE,
	if (!request_region(ali1563_smba, ALI1563_SMB_IOSIZE,
			    ali1563_pci_driver.name)) {
			    ali1563_pci_driver.name)) {
		dev_err(&dev->dev, "Could not allocate I/O space at 0x%04x\n",
		dev_err(&dev->dev, "Could not allocate I/O space at 0x%04x\n",