]> err.no Git - linux-2.6/blobdiff - drivers/macintosh/macio_asic.c
Pull ec into release branch
[linux-2.6] / drivers / macintosh / macio_asic.c
index 0137ff239f1352c1461de2f6212cb0e2affdd0a1..431bd37225a13a05be8891b44de545e88b5802c1 100644 (file)
@@ -140,10 +140,9 @@ static int macio_uevent(struct device *dev, char **envp, int num_envp,
 {
        struct macio_dev * macio_dev;
        struct of_device * of;
-       char *scratch, *compat;
+       char *scratch, *compat, *compat2;
        int i = 0;
-       int length = 0;
-       int cplen, seen = 0;
+       int length, cplen, cplen2, seen = 0;
 
        if (!dev)
                return -ENODEV;
@@ -153,23 +152,22 @@ static int macio_uevent(struct device *dev, char **envp, int num_envp,
                return -ENODEV;
 
        of = &macio_dev->ofdev;
-       scratch = buffer;
 
        /* stuff we want to pass to /sbin/hotplug */
-       envp[i++] = scratch;
-       length += scnprintf (scratch, buffer_size - length, "OF_NAME=%s",
-                            of->node->name);
-       if ((buffer_size - length <= 0) || (i >= num_envp))
-               return -ENOMEM;
+       envp[i++] = scratch = buffer;
+       length = scnprintf (scratch, buffer_size, "OF_NAME=%s", of->node->name);
        ++length;
+       buffer_size -= length;
+       if ((buffer_size <= 0) || (i >= num_envp))
+               return -ENOMEM;
        scratch += length;
 
        envp[i++] = scratch;
-       length += scnprintf (scratch, buffer_size - length, "OF_TYPE=%s",
-                            of->node->type);
-       if ((buffer_size - length <= 0) || (i >= num_envp))
-               return -ENOMEM;
+       length = scnprintf (scratch, buffer_size, "OF_TYPE=%s", of->node->type);
        ++length;
+       buffer_size -= length;
+       if ((buffer_size <= 0) || (i >= num_envp))
+               return -ENOMEM;
        scratch += length;
 
         /* Since the compatible field can contain pretty much anything
@@ -177,29 +175,55 @@ static int macio_uevent(struct device *dev, char **envp, int num_envp,
          * up using a number of environment variables instead. */
 
        compat = (char *) get_property(of->node, "compatible", &cplen);
+       compat2 = compat;
+       cplen2= cplen;
        while (compat && cplen > 0) {
-               int l;
                 envp[i++] = scratch;
-               length += scnprintf (scratch, buffer_size - length,
+               length = scnprintf (scratch, buffer_size,
                                     "OF_COMPATIBLE_%d=%s", seen, compat);
-               if ((buffer_size - length <= 0) || (i >= num_envp))
+               ++length;
+               buffer_size -= length;
+               if ((buffer_size <= 0) || (i >= num_envp))
                        return -ENOMEM;
-               length++;
                scratch += length;
-               l = strlen (compat) + 1;
-               compat += l;
-               cplen -= l;
+               length = strlen (compat) + 1;
+               compat += length;
+               cplen -= length;
                seen++;
        }
 
        envp[i++] = scratch;
-       length += scnprintf (scratch, buffer_size - length,
-                            "OF_COMPATIBLE_N=%d", seen);
-       if ((buffer_size - length <= 0) || (i >= num_envp))
-               return -ENOMEM;
+       length = scnprintf (scratch, buffer_size, "OF_COMPATIBLE_N=%d", seen);
        ++length;
+       buffer_size -= length;
+       if ((buffer_size <= 0) || (i >= num_envp))
+               return -ENOMEM;
        scratch += length;
 
+       envp[i++] = scratch;
+       length = scnprintf (scratch, buffer_size, "MODALIAS=of:N%sT%s",
+                       of->node->name, of->node->type);
+       /* overwrite '\0' */
+       buffer_size -= length;
+       if ((buffer_size <= 0) || (i >= num_envp))
+               return -ENOMEM;
+       scratch += length;
+
+       if (!compat2) {
+               compat2 = "";
+               cplen2 = 1;
+       }
+       while (cplen2 > 0) {
+               length = snprintf (scratch, buffer_size, "C%s", compat2);
+               buffer_size -= length;
+               if (buffer_size <= 0)
+                       return -ENOMEM;
+               scratch += length;
+               length = strlen (compat2) + 1;
+               compat2 += length;
+               cplen2 -= length;
+       }
+
        envp[i] = NULL;
 
        return 0;
@@ -211,6 +235,9 @@ struct bus_type macio_bus_type = {
        .name   = "macio",
        .match  = macio_bus_match,
        .uevent = macio_uevent,
+       .probe  = macio_device_probe,
+       .remove = macio_device_remove,
+       .shutdown = macio_device_shutdown,
        .suspend        = macio_device_suspend,
        .resume = macio_device_resume,
        .dev_attrs = macio_dev_attrs,
@@ -256,42 +283,42 @@ static int macio_resource_quirks(struct device_node *np, struct resource *res,
 {
        if (res->flags & IORESOURCE_MEM) {
                /* Grand Central has too large resource 0 on some machines */
-               if (index == 0 && !strcmp(np->name, "gc")) {
-                       np->addrs[0].size = 0x20000;
+               if (index == 0 && !strcmp(np->name, "gc"))
                        res->end = res->start + 0x1ffff;
-               }
+
                /* Airport has bogus resource 2 */
                if (index >= 2 && !strcmp(np->name, "radio"))
                        return 1;
+
+#ifndef CONFIG_PPC64
                /* DBDMAs may have bogus sizes */
-               if ((res->start & 0x0001f000) == 0x00008000) {
-                       np->addrs[index].size = 0x100;
+               if ((res->start & 0x0001f000) == 0x00008000)
                        res->end = res->start + 0xff;
-               }
+#endif /* CONFIG_PPC64 */
+
                /* ESCC parent eats child resources. We could have added a
                 * level of hierarchy, but I don't really feel the need
                 * for it
                 */
                if (!strcmp(np->name, "escc"))
                        return 1;
+
                /* ESCC has bogus resources >= 3 */
                if (index >= 3 && !(strcmp(np->name, "ch-a") &&
                                    strcmp(np->name, "ch-b")))
                        return 1;
+
                /* Media bay has too many resources, keep only first one */
                if (index > 0 && !strcmp(np->name, "media-bay"))
                        return 1;
+
                /* Some older IDE resources have bogus sizes */
                if (!(strcmp(np->name, "IDE") && strcmp(np->name, "ATA") &&
                      strcmp(np->type, "ide") && strcmp(np->type, "ata"))) {
-                       if (index == 0 && np->addrs[0].size > 0x1000) {
-                               np->addrs[0].size = 0x1000;
+                       if (index == 0 && (res->end - res->start) > 0xfff)
                                res->end = res->start + 0xfff;
-                       }
-                       if (index == 1 && np->addrs[1].size > 0x100) {
-                               np->addrs[1].size = 0x100;
+                       if (index == 1 && (res->end - res->start) > 0xff)
                                res->end = res->start + 0xff;
-                       }
                }
        }
        return 0;
@@ -349,7 +376,7 @@ static void macio_setup_resources(struct macio_dev *dev,
                /* Currently, we consider failure as harmless, this may
                 * change in the future, once I've found all the device
                 * tree bugs in older machines & worked around them
-l               */
+                */
                if (insert_resource(parent_res, res)) {
                        printk(KERN_WARNING "Can't request resource "
                               "%d for MacIO device %s\n",
@@ -523,18 +550,12 @@ static void macio_pci_add_devices(struct macio_chip *chip)
  */
 int macio_register_driver(struct macio_driver *drv)
 {
-       int count = 0;
-
        /* initialize common driver fields */
        drv->driver.name = drv->name;
        drv->driver.bus = &macio_bus_type;
-       drv->driver.probe = macio_device_probe;
-       drv->driver.remove = macio_device_remove;
-       drv->driver.shutdown = macio_device_shutdown;
 
        /* register with core */
-       count = driver_register(&drv->driver);
-       return count ? count : 1;
+       return driver_register(&drv->driver);
 }
 
 /**