linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Armenia <andrew@asquaredlabs.com>
To: Jean Delvare <khali@linux-fr.org>,
	Ben Dooks <ben-linux@fluff.org>,
	Wolfram Sang <w.sang@pengutronix.de>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andrew Armenia <andrew@asquaredlabs.com>
Subject: [PATCH 1/3] i2c-piix4: eliminate piix4_smba global variable
Date: Wed, 13 Jun 2012 12:59:07 -0400	[thread overview]
Message-ID: <1339606749-4578-2-git-send-email-andrew@asquaredlabs.com> (raw)
In-Reply-To: <1339606749-4578-1-git-send-email-andrew@asquaredlabs.com>

Some chipsets have multiple sets of piix4-compatible SMBus registers.
Eliminating the global variable will allow these chipsets to be fully
supported.

Return value from piix4_setup and piix4_sb800_setup now returns the smba
value detected. This is stored in a struct i2c_piix4_adapdata. Thus
the global variable is eliminated.

Signed-off-by: Andrew Armenia <andrew@asquaredlabs.com>
---
 drivers/i2c/busses/i2c-piix4.c |   54 ++++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index c14d48d..61a85c9 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -94,7 +94,6 @@ MODULE_PARM_DESC(force_addr,
 		 "Forcibly enable the PIIX4 at the given address. "
 		 "EXTREMELY DANGEROUS!");
 
-static unsigned short piix4_smba;
 static int srvrworks_csb5_delay;
 static struct pci_driver piix4_driver;
 static struct i2c_adapter piix4_adapter;
@@ -127,10 +126,15 @@ static struct dmi_system_id __devinitdata piix4_dmi_ibm[] = {
 	{ },
 };
 
+struct i2c_piix4_adapdata {
+	unsigned short smba;
+};
+
 static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
 				const struct pci_device_id *id)
 {
 	unsigned char temp;
+	unsigned short piix4_smba;
 
 	if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) &&
 	    (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5))
@@ -206,7 +210,6 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
 			dev_err(&PIIX4_dev->dev,
 				"Host SMBus controller not enabled!\n");
 			release_region(piix4_smba, SMBIOSIZE);
-			piix4_smba = 0;
 			return -ENODEV;
 		}
 	}
@@ -224,12 +227,13 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
 		 "SMBus Host Controller at 0x%x, revision %d\n",
 		 piix4_smba, temp);
 
-	return 0;
+	return piix4_smba;
 }
 
 static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
 				const struct pci_device_id *id)
 {
+	unsigned short piix4_smba;
 	unsigned short smba_idx = 0xcd6;
 	u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c;
 
@@ -273,7 +277,6 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
 		dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region "
 			"0x%x already in use!\n", piix4_smba + i2ccfg_offset);
 		release_region(piix4_smba, SMBIOSIZE);
-		piix4_smba = 0;
 		return -EBUSY;
 	}
 	i2ccfg = inb_p(piix4_smba + i2ccfg_offset);
@@ -288,10 +291,10 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
 		 "SMBus Host Controller at 0x%x, revision %d\n",
 		 piix4_smba, i2ccfg >> 4);
 
-	return 0;
+	return piix4_smba;
 }
 
-static int piix4_transaction(void)
+static int piix4_transaction(unsigned short piix4_smba)
 {
 	int temp;
 	int result = 0;
@@ -372,6 +375,11 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
 {
 	int i, len;
 	int status;
+	unsigned short piix4_smba;
+	struct i2c_piix4_adapdata *adapdata;
+
+	adapdata = i2c_get_adapdata(adap);
+	piix4_smba = adapdata->smba;
 
 	switch (size) {
 	case I2C_SMBUS_QUICK:
@@ -426,7 +434,7 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
 
 	outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
 
-	status = piix4_transaction();
+	status = piix4_transaction(piix4_smba);
 	if (status)
 		return status;
 
@@ -472,6 +480,8 @@ static struct i2c_adapter piix4_adapter = {
 	.algo		= &smbus_algorithm,
 };
 
+static struct i2c_piix4_adapdata piix4_adapter_data;
+
 static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = {
 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3) },
@@ -510,33 +520,45 @@ static int __devinit piix4_probe(struct pci_dev *dev,
 	else
 		retval = piix4_setup(dev, id);
 
-	if (retval)
+	if (retval < 0)
 		return retval;
 
 	/* set up the sysfs linkage to our parent device */
 	piix4_adapter.dev.parent = &dev->dev;
 
+	piix4_adapter_data.smba = retval;
+
 	snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
-		"SMBus PIIX4 adapter at %04x", piix4_smba);
+		"SMBus PIIX4 adapter at %04x", piix4_adapter_data.smba);
+
+	i2c_set_adapdata(&piix4_adapter, &piix4_adapter_data);
 
 	if ((retval = i2c_add_adapter(&piix4_adapter))) {
 		dev_err(&dev->dev, "Couldn't register adapter!\n");
-		release_region(piix4_smba, SMBIOSIZE);
-		piix4_smba = 0;
+		release_region(piix4_adapter_data.smba, SMBIOSIZE);
+		piix4_adapter_data.smba = 0;
 	}
 
 	return retval;
 }
 
-static void __devexit piix4_remove(struct pci_dev *dev)
+static void __devinit piix4_adap_remove(struct i2c_adapter *adap)
 {
-	if (piix4_smba) {
-		i2c_del_adapter(&piix4_adapter);
-		release_region(piix4_smba, SMBIOSIZE);
-		piix4_smba = 0;
+	struct i2c_piix4_adapdata *adapdata;
+
+	adapdata = i2c_get_adapdata(adap);
+	if (adapdata->smba) {
+		i2c_del_adapter(adap);
+		release_region(adapdata->smba, SMBIOSIZE);
+		adapdata->smba = 0;
 	}
 }
 
+static void __devexit piix4_remove(struct pci_dev *dev)
+{
+	piix4_adap_remove(&piix4_adapter);
+}
+
 static struct pci_driver piix4_driver = {
 	.name		= "piix4_smbus",
 	.id_table	= piix4_ids,
-- 
1.7.10

  reply	other threads:[~2012-06-13 16:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-25 22:07 [PATCH] i2c multiplexer driver for Proliant microserver N36L Eddi De Pieri
     [not found] ` <CAKdnbx7xeygkOK=BR+3vUrWT3GEt=PZrxgrEMvEB5nkOfAF0bg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-27 22:55   ` Ben Dooks
     [not found]     ` <20111127225514.GO19115-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2011-12-03 15:31       ` Eddi De Pieri
2011-12-03 16:27         ` [lm-sensors] " Guenter Roeck
     [not found]           ` <20111203162757.GA24302-IzeFyvvaP7pWk0Htik3J/w@public.gmane.org>
2011-12-03 16:42             ` Eddi De Pieri
     [not found]               ` <CAKdnbx54R9t-mS9-EvyT-618wVp-YH0YDO++=m5t-JqR6h=GCw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-03 17:08                 ` Jean Delvare
     [not found]                   ` <20111203180819.2ddbcb3a-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2011-12-05 22:57                     ` Eddi De Pieri
     [not found]                       ` <CAKdnbx5V=qfa5dshRudHx+M3o8Eb6qJXCVG+ZBaBwCeKaoQYNA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-06  8:39                         ` Jean Delvare
     [not found]                           ` <20111206093906.21dccf8d-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2011-12-07 14:57                             ` Eddi De Pieri
2012-02-24 18:56                           ` Thomas Brandon
     [not found]                             ` <loom.20120215T165236-509-eS7Uydv5nfjZ+VzJOa5vwg@public.gmane.org>
2012-02-24 19:04                               ` Thomas Brandon
     [not found]                                 ` <CAM5MpD5R4xde4Li1NCDoErisXs7oRMAgW7swuCwga80MkU3VMw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-27  8:42                                   ` Thomas Brandon
     [not found]                                     ` <CAM5MpD46pT1N2f5yZb0yW1O8CjH7B969TmvxDZztMfwBoyom3g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-14  8:28                                       ` Eddi De Pieri
     [not found]                                         ` <CAKdnbx7tiMaU1c971a+P2vhE_owO_zd8EXhKR7cAwrH=evVQ6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-08-29 17:44                                           ` Jean Delvare
2012-06-13  5:44                                       ` Eddi De Pieri
     [not found]                                         ` <CAKdnbx4MUfU086F7navt52WaoF4q_+3G+DHn7u2qic+FU50OiA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-06-13  7:47                                           ` Jean Delvare
     [not found]                                             ` <20120613094739.360967aa-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-06-13 16:59                                               ` [PATCH 0/3] i2c-piix4: Multiple piix4-compatible SMBus support (revised) Andrew Armenia
2012-06-13 16:59                                                 ` Andrew Armenia [this message]
     [not found]                                                   ` <1339606749-4578-2-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
2012-06-13 19:37                                                     ` [PATCH 1/3] i2c-piix4: eliminate piix4_smba global variable Jean Delvare
     [not found]                                                 ` <1339606749-4578-1-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
2012-06-13 16:59                                                   ` [PATCH 2/3] i2c-piix4: separate registration and probing code Andrew Armenia
     [not found]                                                     ` <1339606749-4578-3-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
2012-06-14 19:38                                                       ` Jean Delvare
2012-06-13 16:59                                                 ` [PATCH 3/3] i2c-piix4: support AMD auxiliary SMBus controller Andrew Armenia
     [not found]                                                   ` <1339606749-4578-4-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
2012-06-15  8:31                                                     ` Jean Delvare
     [not found]                                                       ` <20120615103153.3ea7c009-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-06-15 13:43                                                         ` Andrew Armenia
     [not found]                                                           ` <CA+jCKRVsMNf7Yj7fP4c6+4ff__v5qsea7rYYqHv25XFBi8v9yg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-06-16  6:51                                                             ` Jean Delvare
2012-06-15  9:22                                               ` [PATCH] i2c multiplexer driver for Proliant microserver N36L Jean Delvare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1339606749-4578-2-git-send-email-andrew@asquaredlabs.com \
    --to=andrew@asquaredlabs.com \
    --cc=ben-linux@fluff.org \
    --cc=khali@linux-fr.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=w.sang@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).