]> git.neil.brown.name Git - history.git/commitdiff
i2c: add driver model support to i2c adapter drivers
authorGreg Kroah-Hartman <greg@kroah.com>
Thu, 13 Mar 2003 08:39:40 +0000 (00:39 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Thu, 13 Mar 2003 08:39:40 +0000 (00:39 -0800)
drivers/i2c/busses/i2c-ali15x3.c
drivers/i2c/busses/i2c-amd756.c
drivers/i2c/busses/i2c-amd8111.c
drivers/i2c/busses/i2c-i801.c
drivers/i2c/busses/i2c-piix4.c
drivers/i2c/i2c-core.c
include/linux/i2c.h

index aeb4f55ac54d1b0c7c32a964b6c6995b01107577..8d7f372e109f4243c7c7d9ce7337f0dc6b67cc41 100644 (file)
@@ -531,10 +531,12 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_
                return -ENODEV;
        }
 
+       /* set up the driverfs linkage to our parent device */
+       ali15x3_adapter.dev.parent = &dev->dev;
+
        sprintf(ali15x3_adapter.name, "SMBus ALI15X3 adapter at %04x",
                ali15x3_smba);
-       i2c_add_adapter(&ali15x3_adapter);
-       return 0;
+       return i2c_add_adapter(&ali15x3_adapter);
 }
 
 static void __devexit ali15x3_remove(struct pci_dev *dev)
index b2627572924e09b43e724f64d4b2a5182ec9c636..d4bc60ebac3d2db3bae6ce0833c61a0c14a1b78b 100644 (file)
@@ -375,6 +375,9 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
        printk(KERN_DEBUG DRV_NAME ": AMD756_smba = 0x%X\n", amd756_ioport);
 #endif
 
+       /* set up the driverfs linkage to our parent device */
+       amd756_adapter.dev.parent = &pdev->dev;
+
        sprintf(amd756_adapter.name,
                "SMBus AMD75x adapter at %04x", amd756_ioport);
 
index a3adbe770f8cb2fc6ba5c1e8f9d9cf844de64762..07f22e6e8495d6e2a3ccbfd26d157cb81746e5ef 100644 (file)
@@ -363,6 +363,9 @@ static int __devinit amd8111_probe(struct pci_dev *dev, const struct pci_device_
        smbus->adapter.algo = &smbus_algorithm;
        smbus->adapter.algo_data = smbus;
 
+       /* set up the driverfs linkage to our parent device */
+       smbus->adapter.dev.parent = &dev->dev;
+
        error = i2c_add_adapter(&smbus->adapter);
        if (error)
                goto out_release_region;
@@ -389,7 +392,7 @@ static void __devexit amd8111_remove(struct pci_dev *dev)
 }
 
 static struct pci_driver amd8111_driver = {
-       .name           = "amd8111 smbus 2.0",
+       .name           = "amd8111 smbus",
        .id_table       = amd8111_ids,
        .probe          = amd8111_probe,
        .remove         = __devexit_p(amd8111_remove),
index 6ed5146995943b9cd4c87e004b62af41f4a1d170..b1556e08ce5499819edaf2ed8941257c402fc958 100644 (file)
@@ -672,9 +672,12 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
                return -ENODEV;
        }
 
+       /* set up the driverfs linkage to our parent device */
+       i801_adapter.dev.parent = &dev->dev;
+
        sprintf(i801_adapter.name, "SMBus I801 adapter at %04x",
                i801_smba);
-       i2c_add_adapter(&i801_adapter);
+       return i2c_add_adapter(&i801_adapter);
 }
 
 static void __devexit i801_remove(struct pci_dev *dev)
index 76f9ead0b0a8b710540cf797e0bef444515ae9b9..5acd8211b1d6aa8f40fcc1db5b1d3475726ae574 100644 (file)
@@ -473,6 +473,9 @@ static int __devinit piix4_probe(struct pci_dev *dev, const struct pci_device_id
        if (retval)
                return retval;
 
+       /* set up the driverfs linkage to our parent device */
+       piix4_adapter.dev.parent = &dev->dev;
+
        sprintf(piix4_adapter.name, "SMBus PIIX4 adapter at %04x",
                piix4_smba);
 
index 6165e88a660c7b99f6c70c7458b74e0be903ecdb..004e8e8ef6710fa36ff3e318b5768bec101bde25 100644 (file)
@@ -87,6 +87,16 @@ int i2c_add_adapter(struct i2c_adapter *adap)
        init_MUTEX(&adap->bus);
        init_MUTEX(&adap->list);
 
+       /* Add the adapter to the driver core.
+        * If the parent pointer is not set up,
+        * we add this adapter to the legacy bus.
+        */
+       if (adap->dev.parent == NULL)
+               adap->dev.parent = &legacy_bus;
+       sprintf(adap->dev.bus_id, "i2c-%d", i);
+       strcpy(adap->dev.name, "i2c controller");
+       device_register(&adap->dev);
+
        /* inform drivers of new adapters */
        for (j=0;j<I2C_DRIVER_MAX;j++)
                if (drivers[j]!=NULL && 
@@ -154,6 +164,9 @@ int i2c_del_adapter(struct i2c_adapter *adap)
 
        i2cproc_remove(i);
 
+       /* clean up the sysfs representation */
+       device_unregister(&adap->dev);
+
        adapters[i] = NULL;
 
        DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name));
index 8f86852b16d8fdf43950d3af13a486f9eb6c37a9..a8f482b94ba49008d0c26cb5d9274c85efd4843f 100644 (file)
@@ -231,12 +231,14 @@ struct i2c_adapter {
 
        int timeout;
        int retries;
+       struct device dev;      /* the adapter device */
 
 #ifdef CONFIG_PROC_FS 
        /* No need to set this when you initialize the adapter          */
        int inode;
 #endif /* def CONFIG_PROC_FS */
 };
+#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
 
 /*flags for the driver struct: */
 #define I2C_DF_NOTIFY  0x01            /* notify on bus (de/a)ttaches  */