From: Andrew Armenia <andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
To: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>,
Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Andrew Armenia <andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
Subject: [PATCH 2/3] i2c-piix4: separate registration and probing code
Date: Mon, 4 Jun 2012 21:49:23 -0400 [thread overview]
Message-ID: <1338860964-10803-3-git-send-email-andrew@asquaredlabs.com> (raw)
In-Reply-To: <1338860964-10803-1-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
Some chipsets have multiple sets of SMBus registers each controlling a
separate SMBus. Supporting these chipsets properly will require registering
multiple I2C adapters for one piix4.
The code to initialize and register the i2c_adapter structure has been
separated from piix4_probe and allows registration of a piix4 adapter
given its base address. Note that the i2c_adapter and piix4_adapdata
structures are now dynamically allocated.
Signed-off-by: Andrew Armenia <andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
---
drivers/i2c/busses/i2c-piix4.c | 79 ++++++++++++++++++++++++++--------------
1 file changed, 51 insertions(+), 28 deletions(-)
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 7a5889c..8a87b3f 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -480,16 +480,6 @@ static const struct i2c_algorithm smbus_algorithm = {
.functionality = piix4_func,
};
-static struct i2c_adapter piix4_adapter = {
- .owner = THIS_MODULE,
- .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
- .algo = &smbus_algorithm,
-};
-
-static struct i2c_piix4_adapdata piix4_adapter_data = {
- .smba = 0,
-};
-
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) },
@@ -514,6 +504,48 @@ static DEFINE_PCI_DEVICE_TABLE(piix4_ids) = {
MODULE_DEVICE_TABLE (pci, piix4_ids);
+static struct i2c_adapter *piix4_main_adapter;
+
+/* register piix4 I2C adapter at the given base address */
+static int piix4_add_adapter(struct pci_dev *dev, unsigned short smba,
+ struct i2c_adapter **padap) {
+ struct i2c_adapter *piix4_adapter;
+ struct i2c_piix4_adapdata *piix4_adapdata;
+ int retval;
+
+ piix4_adapter = kmalloc(sizeof(*piix4_adapter), GFP_KERNEL);
+ memset(piix4_adapter, 0, sizeof(*piix4_adapter));
+ piix4_adapter->owner = THIS_MODULE;
+ piix4_adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
+ piix4_adapter->algo = &smbus_algorithm;
+
+ piix4_adapdata = kmalloc(sizeof(*piix4_adapdata), GFP_KERNEL);
+ memset(piix4_adapdata, 0, sizeof(*piix4_adapdata));
+ piix4_adapdata->smba = smba;
+
+ /* set up the sysfs linkage to our parent device */
+ piix4_adapter->dev.parent = &dev->dev;
+
+ snprintf(piix4_adapter->name, sizeof(piix4_adapter->name),
+ "SMBus PIIX4 adapter at %04x", smba);
+
+ piix4_adapdata->smba = smba;
+
+ i2c_set_adapdata(piix4_adapter, piix4_adapdata);
+
+ retval = i2c_add_adapter(piix4_adapter);
+ if (retval) {
+ dev_err(&dev->dev, "Couldn't register adapter!\n");
+ release_region(smba, SMBIOSIZE);
+ kfree(piix4_adapdata);
+ kfree(piix4_adapter);
+ }
+
+ *padap = piix4_adapter;
+
+ return retval;
+}
+
static int __devinit piix4_probe(struct pci_dev *dev,
const struct pci_device_id *id)
{
@@ -532,25 +564,10 @@ static int __devinit piix4_probe(struct pci_dev *dev,
if (retval)
return retval;
- /* set up the sysfs linkage to our parent device */
- piix4_adapter.dev.parent = &dev->dev;
-
- snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
- "SMBus PIIX4 adapter at %04x", smba);
-
- piix4_adapter_data.smba = 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(smba, SMBIOSIZE);
- piix4_adapter_data.smba = 0;
- }
-
- return retval;
+ return piix4_add_adapter(dev, smba, &piix4_main_adapter);
}
+/* Remove the adapter and its associated IO region */
static void piix4_adap_remove(struct i2c_adapter *adap)
{
struct i2c_piix4_adapdata *adapdata;
@@ -561,11 +578,17 @@ static void piix4_adap_remove(struct i2c_adapter *adap)
release_region(adapdata->smba, SMBIOSIZE);
adapdata->smba = 0;
}
+
+ kfree(adapdata);
+ kfree(adap);
}
static void __devexit piix4_remove(struct pci_dev *dev)
{
- piix4_adap_remove(&piix4_adapter);
+ if (piix4_main_adapter) {
+ piix4_adap_remove(piix4_main_adapter);
+ piix4_main_adapter = NULL;
+ }
}
static struct pci_driver piix4_driver = {
--
1.7.10
next prev parent reply other threads:[~2012-06-05 1:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-01 18:16 [PATCH] i2c-piix4: support multiple PIIX4 SMBus hosts Andrew Armenia
[not found] ` <1338574572-10668-1-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
2012-06-04 7:16 ` Jean Delvare
[not found] ` <20120604091643.208956fe-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-06-05 1:49 ` [PATCH 0/3] Multiple piix4-compatible SMBus support Andrew Armenia
[not found] ` <1338860964-10803-1-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
2012-06-05 1:49 ` [PATCH 1/3] i2c-piix4: eliminate global I/O base address Andrew Armenia
2012-06-12 11:53 ` Jean Delvare
2012-06-05 1:49 ` Andrew Armenia [this message]
2012-06-12 12:10 ` [PATCH 2/3] i2c-piix4: separate registration and probing code Jean Delvare
2012-06-05 1:49 ` [PATCH 3/3] i2c-piix4: support aux SMBus on AMD chipsets Andrew Armenia
[not found] ` <1338860964-10803-4-git-send-email-andrew-Lwj1yN59in/Ib2jZbfQ/kQ@public.gmane.org>
2012-06-12 12:47 ` Jean Delvare
-- strict thread matches above, loose matches on Subject: below --
2012-06-13 7:47 [PATCH] i2c multiplexer driver for Proliant microserver N36L Jean Delvare
2012-06-13 16:59 ` [PATCH 0/3] i2c-piix4: Multiple piix4-compatible SMBus support (revised) Andrew Armenia
[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
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=1338860964-10803-3-git-send-email-andrew@asquaredlabs.com \
--to=andrew-lwj1yn59in/ib2jzbfq/kq@public.gmane.org \
--cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
--cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
/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).