Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SPARC]: Port of_device layer and make ebus use it.

Signed-off-by: David S. Miller <davem@davemloft.net>

+359 -2
+1 -1
arch/sparc/kernel/Makefile
··· 12 12 sys_sparc.o sunos_asm.o systbls.o \ 13 13 time.o windows.o cpu.o devices.o sclow.o \ 14 14 tadpole.o tick14.o ptrace.o sys_solaris.o \ 15 - unaligned.o muldiv.o semaphore.o prom.o 15 + unaligned.o muldiv.o semaphore.o prom.o of_device.o 16 16 17 17 obj-$(CONFIG_PCI) += pcic.o 18 18 obj-$(CONFIG_SUN4) += sun4setup.o
+21
arch/sparc/kernel/ebus.c
··· 235 235 } 236 236 } 237 237 238 + dev->ofdev.node = dp; 239 + dev->ofdev.dev.parent = &dev->bus->ofdev.dev; 240 + dev->ofdev.dev.bus = &ebus_bus_type; 241 + strcpy(dev->ofdev.dev.bus_id, dp->path_component_name); 242 + 243 + /* Register with core */ 244 + if (of_device_register(&dev->ofdev) != 0) 245 + printk(KERN_DEBUG "ebus: device registration error for %s!\n", 246 + dev->ofdev.dev.bus_id); 247 + 238 248 if ((dp = dp->child) != NULL) { 239 249 dev->children = (struct linux_ebus_child *) 240 250 ebus_alloc(sizeof(struct linux_ebus_child)); ··· 330 320 addr = regs[reg].phys_lo; 331 321 *base++ = addr; 332 322 } 323 + 324 + ebus->ofdev.node = dp; 325 + ebus->ofdev.dev.parent = &pdev->dev; 326 + ebus->ofdev.dev.bus = &ebus_bus_type; 327 + strcpy(ebus->ofdev.dev.bus_id, dp->path_component_name); 328 + 329 + /* Register with core */ 330 + if (of_device_register(&ebus->ofdev) != 0) 331 + printk(KERN_DEBUG "ebus: device registration error for %s!\n", 332 + ebus->ofdev.dev.bus_id); 333 + 333 334 334 335 nd = dp->child; 335 336 if (!nd)
+268
arch/sparc/kernel/of_device.c
··· 1 + #include <linux/config.h> 2 + #include <linux/string.h> 3 + #include <linux/kernel.h> 4 + #include <linux/init.h> 5 + #include <linux/module.h> 6 + #include <linux/mod_devicetable.h> 7 + #include <linux/slab.h> 8 + 9 + #include <asm/errno.h> 10 + #include <asm/of_device.h> 11 + 12 + /** 13 + * of_match_device - Tell if an of_device structure has a matching 14 + * of_match structure 15 + * @ids: array of of device match structures to search in 16 + * @dev: the of device structure to match against 17 + * 18 + * Used by a driver to check whether an of_device present in the 19 + * system is in its list of supported devices. 20 + */ 21 + const struct of_device_id *of_match_device(const struct of_device_id *matches, 22 + const struct of_device *dev) 23 + { 24 + if (!dev->node) 25 + return NULL; 26 + while (matches->name[0] || matches->type[0] || matches->compatible[0]) { 27 + int match = 1; 28 + if (matches->name[0]) 29 + match &= dev->node->name 30 + && !strcmp(matches->name, dev->node->name); 31 + if (matches->type[0]) 32 + match &= dev->node->type 33 + && !strcmp(matches->type, dev->node->type); 34 + if (matches->compatible[0]) 35 + match &= of_device_is_compatible(dev->node, 36 + matches->compatible); 37 + if (match) 38 + return matches; 39 + matches++; 40 + } 41 + return NULL; 42 + } 43 + 44 + static int of_platform_bus_match(struct device *dev, struct device_driver *drv) 45 + { 46 + struct of_device * of_dev = to_of_device(dev); 47 + struct of_platform_driver * of_drv = to_of_platform_driver(drv); 48 + const struct of_device_id * matches = of_drv->match_table; 49 + 50 + if (!matches) 51 + return 0; 52 + 53 + return of_match_device(matches, of_dev) != NULL; 54 + } 55 + 56 + struct of_device *of_dev_get(struct of_device *dev) 57 + { 58 + struct device *tmp; 59 + 60 + if (!dev) 61 + return NULL; 62 + tmp = get_device(&dev->dev); 63 + if (tmp) 64 + return to_of_device(tmp); 65 + else 66 + return NULL; 67 + } 68 + 69 + void of_dev_put(struct of_device *dev) 70 + { 71 + if (dev) 72 + put_device(&dev->dev); 73 + } 74 + 75 + 76 + static int of_device_probe(struct device *dev) 77 + { 78 + int error = -ENODEV; 79 + struct of_platform_driver *drv; 80 + struct of_device *of_dev; 81 + const struct of_device_id *match; 82 + 83 + drv = to_of_platform_driver(dev->driver); 84 + of_dev = to_of_device(dev); 85 + 86 + if (!drv->probe) 87 + return error; 88 + 89 + of_dev_get(of_dev); 90 + 91 + match = of_match_device(drv->match_table, of_dev); 92 + if (match) 93 + error = drv->probe(of_dev, match); 94 + if (error) 95 + of_dev_put(of_dev); 96 + 97 + return error; 98 + } 99 + 100 + static int of_device_remove(struct device *dev) 101 + { 102 + struct of_device * of_dev = to_of_device(dev); 103 + struct of_platform_driver * drv = to_of_platform_driver(dev->driver); 104 + 105 + if (dev->driver && drv->remove) 106 + drv->remove(of_dev); 107 + return 0; 108 + } 109 + 110 + static int of_device_suspend(struct device *dev, pm_message_t state) 111 + { 112 + struct of_device * of_dev = to_of_device(dev); 113 + struct of_platform_driver * drv = to_of_platform_driver(dev->driver); 114 + int error = 0; 115 + 116 + if (dev->driver && drv->suspend) 117 + error = drv->suspend(of_dev, state); 118 + return error; 119 + } 120 + 121 + static int of_device_resume(struct device * dev) 122 + { 123 + struct of_device * of_dev = to_of_device(dev); 124 + struct of_platform_driver * drv = to_of_platform_driver(dev->driver); 125 + int error = 0; 126 + 127 + if (dev->driver && drv->resume) 128 + error = drv->resume(of_dev); 129 + return error; 130 + } 131 + 132 + #ifdef CONFIG_PCI 133 + struct bus_type ebus_bus_type = { 134 + .name = "ebus", 135 + .match = of_platform_bus_match, 136 + .probe = of_device_probe, 137 + .remove = of_device_remove, 138 + .suspend = of_device_suspend, 139 + .resume = of_device_resume, 140 + }; 141 + #endif 142 + 143 + #ifdef CONFIG_SBUS 144 + struct bus_type sbus_bus_type = { 145 + .name = "sbus", 146 + .match = of_platform_bus_match, 147 + .probe = of_device_probe, 148 + .remove = of_device_remove, 149 + .suspend = of_device_suspend, 150 + .resume = of_device_resume, 151 + }; 152 + #endif 153 + 154 + static int __init of_bus_driver_init(void) 155 + { 156 + int err = 0; 157 + 158 + #ifdef CONFIG_PCI 159 + if (!err) 160 + err = bus_register(&ebus_bus_type); 161 + #endif 162 + #ifdef CONFIG_SBUS 163 + if (!err) 164 + err = bus_register(&sbus_bus_type); 165 + #endif 166 + return 0; 167 + } 168 + 169 + postcore_initcall(of_bus_driver_init); 170 + 171 + int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus) 172 + { 173 + /* initialize common driver fields */ 174 + drv->driver.name = drv->name; 175 + drv->driver.bus = bus; 176 + 177 + /* register with core */ 178 + return driver_register(&drv->driver); 179 + } 180 + 181 + void of_unregister_driver(struct of_platform_driver *drv) 182 + { 183 + driver_unregister(&drv->driver); 184 + } 185 + 186 + 187 + static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) 188 + { 189 + struct of_device *ofdev; 190 + 191 + ofdev = to_of_device(dev); 192 + return sprintf(buf, "%s", ofdev->node->full_name); 193 + } 194 + 195 + static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); 196 + 197 + /** 198 + * of_release_dev - free an of device structure when all users of it are finished. 199 + * @dev: device that's been disconnected 200 + * 201 + * Will be called only by the device core when all users of this of device are 202 + * done. 203 + */ 204 + void of_release_dev(struct device *dev) 205 + { 206 + struct of_device *ofdev; 207 + 208 + ofdev = to_of_device(dev); 209 + 210 + kfree(ofdev); 211 + } 212 + 213 + int of_device_register(struct of_device *ofdev) 214 + { 215 + int rc; 216 + 217 + BUG_ON(ofdev->node == NULL); 218 + 219 + rc = device_register(&ofdev->dev); 220 + if (rc) 221 + return rc; 222 + 223 + device_create_file(&ofdev->dev, &dev_attr_devspec); 224 + 225 + return 0; 226 + } 227 + 228 + void of_device_unregister(struct of_device *ofdev) 229 + { 230 + device_remove_file(&ofdev->dev, &dev_attr_devspec); 231 + device_unregister(&ofdev->dev); 232 + } 233 + 234 + struct of_device* of_platform_device_create(struct device_node *np, 235 + const char *bus_id, 236 + struct device *parent, 237 + struct bus_type *bus) 238 + { 239 + struct of_device *dev; 240 + 241 + dev = kmalloc(sizeof(*dev), GFP_KERNEL); 242 + if (!dev) 243 + return NULL; 244 + memset(dev, 0, sizeof(*dev)); 245 + 246 + dev->dev.parent = parent; 247 + dev->dev.bus = bus; 248 + dev->dev.release = of_release_dev; 249 + 250 + strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE); 251 + 252 + if (of_device_register(dev) != 0) { 253 + kfree(dev); 254 + return NULL; 255 + } 256 + 257 + return dev; 258 + } 259 + 260 + EXPORT_SYMBOL(of_match_device); 261 + EXPORT_SYMBOL(of_register_driver); 262 + EXPORT_SYMBOL(of_unregister_driver); 263 + EXPORT_SYMBOL(of_device_register); 264 + EXPORT_SYMBOL(of_device_unregister); 265 + EXPORT_SYMBOL(of_dev_get); 266 + EXPORT_SYMBOL(of_dev_put); 267 + EXPORT_SYMBOL(of_platform_device_create); 268 + EXPORT_SYMBOL(of_release_dev);
+5
include/asm-sparc/ebus.h
··· 14 14 #endif 15 15 #include <asm/oplib.h> 16 16 #include <asm/prom.h> 17 + #include <asm/of_device.h> 17 18 18 19 struct linux_ebus_child { 19 20 struct linux_ebus_child *next; ··· 28 27 }; 29 28 30 29 struct linux_ebus_device { 30 + struct of_device ofdev; 31 31 struct linux_ebus_device *next; 32 32 struct linux_ebus_child *children; 33 33 struct linux_ebus *bus; ··· 38 36 unsigned int irqs[PROMINTR_MAX]; 39 37 int num_irqs; 40 38 }; 39 + #define to_ebus_device(d) container_of(d, struct linux_ebus_device, ofdev.dev) 41 40 42 41 struct linux_ebus { 42 + struct of_device ofdev; 43 43 struct linux_ebus *next; 44 44 struct linux_ebus_device *devices; 45 45 struct linux_pbm_info *parent; 46 46 struct pci_dev *self; 47 47 struct device_node *prom_node; 48 48 }; 49 + #define to_ebus(d) container_of(d, struct linux_ebus, ofdev.dev) 49 50 50 51 struct linux_ebus_dma { 51 52 unsigned int dcsr;
+63
include/asm-sparc/of_device.h
··· 1 + #ifndef _ASM_SPARC_OF_DEVICE_H 2 + #define _ASM_SPARC_OF_DEVICE_H 3 + #ifdef __KERNEL__ 4 + 5 + #include <linux/device.h> 6 + #include <linux/mod_devicetable.h> 7 + #include <asm/prom.h> 8 + 9 + extern struct bus_type ebus_bus_type; 10 + extern struct bus_type sbus_bus_type; 11 + 12 + /* 13 + * The of_device is a kind of "base class" that is a superset of 14 + * struct device for use by devices attached to an OF node and 15 + * probed using OF properties. 16 + */ 17 + struct of_device 18 + { 19 + struct device_node *node; /* OF device node */ 20 + struct device dev; /* Generic device interface */ 21 + }; 22 + #define to_of_device(d) container_of(d, struct of_device, dev) 23 + 24 + extern const struct of_device_id *of_match_device( 25 + const struct of_device_id *matches, const struct of_device *dev); 26 + 27 + extern struct of_device *of_dev_get(struct of_device *dev); 28 + extern void of_dev_put(struct of_device *dev); 29 + 30 + /* 31 + * An of_platform_driver driver is attached to a basic of_device on 32 + * the ISA, EBUS, and SBUS busses on sparc64. 33 + */ 34 + struct of_platform_driver 35 + { 36 + char *name; 37 + struct of_device_id *match_table; 38 + struct module *owner; 39 + 40 + int (*probe)(struct of_device* dev, const struct of_device_id *match); 41 + int (*remove)(struct of_device* dev); 42 + 43 + int (*suspend)(struct of_device* dev, pm_message_t state); 44 + int (*resume)(struct of_device* dev); 45 + int (*shutdown)(struct of_device* dev); 46 + 47 + struct device_driver driver; 48 + }; 49 + #define to_of_platform_driver(drv) container_of(drv,struct of_platform_driver, driver) 50 + 51 + extern int of_register_driver(struct of_platform_driver *drv, 52 + struct bus_type *bus); 53 + extern void of_unregister_driver(struct of_platform_driver *drv); 54 + extern int of_device_register(struct of_device *ofdev); 55 + extern void of_device_unregister(struct of_device *ofdev); 56 + extern struct of_device *of_platform_device_create(struct device_node *np, 57 + const char *bus_id, 58 + struct device *parent, 59 + struct bus_type *bus); 60 + extern void of_release_dev(struct device *dev); 61 + 62 + #endif /* __KERNEL__ */ 63 + #endif /* _ASM_SPARC_OF_DEVICE_H */
+1 -1
include/asm-sparc64/of_device.h
··· 61 61 extern void of_release_dev(struct device *dev); 62 62 63 63 #endif /* __KERNEL__ */ 64 - #endif /* _ASM_POWERPC_OF_DEVICE_H */ 64 + #endif /* _ASM_SPARC64_OF_DEVICE_H */