From: Jean Delvare <khali@linux-fr.org>
To: Andrew Armenia <andrew@asquaredlabs.com>
Cc: Ben Dooks <ben-linux@fluff.org>,
Wolfram Sang <w.sang@pengutronix.de>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] i2c-piix4: eliminate global I/O base address
Date: Tue, 12 Jun 2012 13:53:38 +0200 [thread overview]
Message-ID: <20120612135338.48efadcc@endymion.delvare> (raw)
In-Reply-To: <1338860964-10803-2-git-send-email-andrew@asquaredlabs.com>
Hi Andrew,
On Mon, 4 Jun 2012 21:49:22 -0400, Andrew Armenia wrote:
> The i2c-piix4 driver used a global variable to store the base address
> of the piix4 i2c registers. Some chipsets contain multiple sets of
> i2c registers; thus it is desirable to eliminate global state.
>
> i2c_get_adapdata()/i2c_set_adapdata() are used to keep track
> of the IO base address; this is passed into piix4_transaction() as
> an argument, eliminating the global variable.
>
> Signed-off-by: Andrew Armenia <andrew@asquaredlabs.com>
> ---
> drivers/i2c/busses/i2c-piix4.c | 61 ++++++++++++++++++++++++++++++----------
> 1 file changed, 46 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
> index c14d48d..7a5889c 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,16 @@ 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)
> + const struct pci_device_id *id,
> + unsigned short *smba)
You could instead return the smba value, as the return value is
currently only used for errors. This would avoid the extra parameter
and possibly false-positive compiler warnings.
> {
> unsigned char temp;
> + unsigned short piix4_smba;
>
> if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) &&
> (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5))
> @@ -224,12 +229,15 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
> "SMBus Host Controller at 0x%x, revision %d\n",
> piix4_smba, temp);
>
> + *smba = piix4_smba;
> return 0;
> }
>
> static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
> - const struct pci_device_id *id)
> + const struct pci_device_id *id,
> + unsigned short *smba)
> {
> + unsigned short piix4_smba;
> unsigned short smba_idx = 0xcd6;
> u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c;
>
> @@ -288,10 +296,11 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
> "SMBus Host Controller at 0x%x, revision %d\n",
> piix4_smba, i2ccfg >> 4);
>
> + *smba = piix4_smba;
> return 0;
> }
>
> -static int piix4_transaction(void)
> +static int piix4_transaction(unsigned short piix4_smba)
> {
> int temp;
> int result = 0;
> @@ -372,6 +381,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 = (struct i2c_piix4_adapdata *)i2c_get_adapdata(adap);
Useless cast.
> + piix4_smba = adapdata->smba;
>
> switch (size) {
> case I2C_SMBUS_QUICK:
> @@ -426,7 +440,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 +486,10 @@ static struct i2c_adapter piix4_adapter = {
> .algo = &smbus_algorithm,
> };
>
> +static struct i2c_piix4_adapdata piix4_adapter_data = {
> + .smba = 0,
> +};
Useless initialization, 0 is the default.
> +
> 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) },
> @@ -500,15 +518,16 @@ static int __devinit piix4_probe(struct pci_dev *dev,
> const struct pci_device_id *id)
> {
> int retval;
> + unsigned short smba;
>
> if ((dev->vendor == PCI_VENDOR_ID_ATI &&
> dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS &&
> dev->revision >= 0x40) ||
> dev->vendor == PCI_VENDOR_ID_AMD)
> /* base address location etc changed in SB800 */
> - retval = piix4_setup_sb800(dev, id);
> + retval = piix4_setup_sb800(dev, id, &smba);
> else
> - retval = piix4_setup(dev, id);
> + retval = piix4_setup(dev, id, &smba);
>
> if (retval)
> return retval;
> @@ -517,26 +536,38 @@ static int __devinit piix4_probe(struct pci_dev *dev,
> piix4_adapter.dev.parent = &dev->dev;
>
> snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
> - "SMBus PIIX4 adapter at %04x", piix4_smba);
> + "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(piix4_smba, SMBIOSIZE);
> - piix4_smba = 0;
> + release_region(smba, SMBIOSIZE);
> + piix4_adapter_data.smba = 0;
> }
>
> return retval;
> }
>
> -static void __devexit piix4_remove(struct pci_dev *dev)
> +static void piix4_adap_remove(struct i2c_adapter *adap)
Called from a __devinit function so it can be made __devinit too.
> {
> - if (piix4_smba) {
> - i2c_del_adapter(&piix4_adapter);
> - release_region(piix4_smba, SMBIOSIZE);
> - piix4_smba = 0;
> + struct i2c_piix4_adapdata *adapdata;
> +
> + adapdata = (struct i2c_piix4_adapdata *)i2c_get_adapdata(adap);
Useless cast.
> + 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,
--
Jean Delvare
next prev parent reply other threads:[~2012-06-12 11:53 UTC|newest]
Thread overview: 9+ 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 [this message]
2012-06-05 1:49 ` [PATCH 2/3] i2c-piix4: separate registration and probing code Andrew Armenia
2012-06-12 12:10 ` 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
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=20120612135338.48efadcc@endymion.delvare \
--to=khali@linux-fr.org \
--cc=andrew@asquaredlabs.com \
--cc=ben-linux@fluff.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).