/** * bus_add_driver - Add a driver to the bus. * @drv: driver. * */ int bus_add_driver(struct device_driver * drv) { struct bus_type * bus = get_bus(drv->bus); int error = 0; if (bus) { pr_debug("bus %s: add driver %s\n", bus->name, drv->name); error = kobject_set_name(&drv->kobj, "%s", drv->name); if (error) { put_bus(bus); return error; } drv->kobj.kset = &bus->drivers; if ((error = kobject_register(&drv->kobj))) { put_bus(bus); return error; } driver_attach(drv); klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); driver_add_attrs(bus, drv); add_bind_files(drv); } return error; }
/* * Manually attach a device to a driver. * Note: the driver must want to bind to the device, * it is not possible to override the driver's id table. */ static ssize_t driver_bind(struct device_driver *drv, const char *buf, size_t count) { struct bus_type *bus = get_bus(drv->bus); struct device *dev; int err = -ENODEV; dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); if (dev && dev->driver == NULL) { if (dev->parent) /* Needed for USB */ down(&dev->parent->sem); down(&dev->sem); err = driver_probe_device(drv, dev); up(&dev->sem); if (dev->parent) up(&dev->parent->sem); if (err > 0) /* success */ err = count; else if (err == 0) /* driver didn't accept device */ err = -ENODEV; } put_device(dev); put_bus(bus); return err; }
/** * bus_add_device - add device to bus * @dev: device being added * * - Add the device to its bus's list of devices. * - Create link to device's bus. */ int bus_add_device(struct device * dev) { struct bus_type * bus = get_bus(dev->bus); int error = 0; if (bus) { pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); error = device_add_attrs(bus, dev); if (error) goto out_put; error = sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); if (error) goto out_id; error = sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); if (error) goto out_subsys; error = make_deprecated_bus_links(dev); if (error) goto out_deprecated; } return 0; out_deprecated: sysfs_remove_link(&dev->kobj, "subsystem"); out_subsys: sysfs_remove_link(&bus->devices.kobj, dev->bus_id); out_id: device_remove_attrs(bus, dev); out_put: put_bus(dev->bus); return error; }
void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr) { if (get_bus(bus)) { sysfs_remove_file(&bus->subsys.kset.kobj, &attr->attr); put_bus(bus); } }
static void get_parameters(void) { int vid; /* HZ */ boot_params.nucleos_kludge.system_hz = HZ; if (processor == 1586) processor = 686; boot_params.nucleos_kludge.processor = processor; /* bus */ if (get_bus()) boot_params.nucleos_kludge.pc_at = 1; /* video */ vid = get_video(); if (vid == 2 || vid == 3) boot_params.nucleos_kludge.vdu_ega = 1; else boot_params.nucleos_kludge.vdu_vga = 1; /* memory */ memcpy(boot_params.nucleos_kludge.mem, mem, sizeof(boot_params.nucleos_kludge.mem)); return; }
int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) { int error; if (get_bus(bus)) { error = sysfs_create_file(&bus->subsys.kset.kobj, &attr->attr); put_bus(bus); } else error = -EINVAL; return error; }
/** * bus_add_device - add device to bus * @dev: device being added * * - Add the device to its bus's list of devices. * - Create link to device's bus. */ int bus_add_device(struct device * dev) { struct bus_type * bus = get_bus(dev->bus); int error = 0; if (bus) { pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); error = device_add_attrs(bus, dev); if (!error) { sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); } } return error; }
static ssize_t driver_unbind(struct device_driver *drv, const char *buf, size_t count) { struct bus_type *bus = get_bus(drv->bus); struct device *dev; int err = -ENODEV; dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); if (dev && dev->driver == drv) { device_release_driver(dev); err = count; } put_device(dev); put_bus(bus); return err; }
/* * Manually attach a device to a driver. * Note: the driver must want to bind to the device, * it is not possible to override the driver's id table. */ static ssize_t driver_bind(struct device_driver *drv, const char *buf, size_t count) { struct bus_type *bus = get_bus(drv->bus); struct device *dev; int err = -ENODEV; dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); if (dev && dev->driver == NULL) { down(&dev->sem); err = driver_probe_device(drv, dev); up(&dev->sem); } put_device(dev); put_bus(bus); return err; }
static int __bus_for_each_dev(struct bus_type *bus, struct device *start, void *data, int (*fn)(struct device *, void *)) { struct list_head *head; struct device *dev; int error = 0; if (!(bus = get_bus(bus))) return -EINVAL; head = &bus->devices.list; dev = list_prepare_entry(start, head, bus_list); list_for_each_entry_continue(dev, head, bus_list) { get_device(dev); error = fn(dev, data); put_device(dev); if (error) break; }
/** * bus_add_driver - Add a driver to the bus. * @drv: driver. * */ int bus_add_driver(struct device_driver *drv) { struct bus_type * bus = get_bus(drv->bus); int error = 0; if (!bus) return 0; pr_debug("bus %s: add driver %s\n", bus->name, drv->name); error = kobject_set_name(&drv->kobj, "%s", drv->name); if (error) goto out_put_bus; drv->kobj.kset = &bus->drivers; if ((error = kobject_register(&drv->kobj))) goto out_put_bus; error = driver_attach(drv); if (error) goto out_unregister; klist_add_tail(&drv->knode_bus, &bus->klist_drivers); module_add_driver(drv->owner, drv); error = driver_add_attrs(bus, drv); if (error) { /* How the hell do we get out of this pickle? Give up */ printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", __FUNCTION__, drv->name); } error = add_bind_files(drv); if (error) { /* Ditto */ printk(KERN_ERR "%s: add_bind_files(%s) failed\n", __FUNCTION__, drv->name); } return error; out_unregister: kobject_unregister(&drv->kobj); out_put_bus: put_bus(bus); return error; }
static gboolean get_device_info (const char *path, int *vendor_id, int *product_id, char **name, WacomBusType *bus, WacomIntegrationFlags *integration_flags, WacomError *error) { GUdevClient *client; GUdevDevice *device; const char * const subsystems[] = { "input", NULL }; gboolean retval; char *bus_str; const char *devname; #if NEED_G_TYPE_INIT g_type_init(); #endif retval = FALSE; /* The integration flags from device info are unset by default */ *integration_flags = WACOM_DEVICE_INTEGRATED_UNSET; *name = NULL; bus_str = NULL; client = g_udev_client_new (subsystems); device = g_udev_client_query_by_device_file (client, path); if (device == NULL) { libwacom_error_set(error, WERROR_INVALID_PATH, "Could not find device '%s' in udev", path); goto out; } /* Touchpads are only for the "Finger" part of Bamboo devices */ if (!is_tablet_or_touchpad(device)) { GUdevDevice *parent; parent = g_udev_device_get_parent(device); if (!parent || !is_tablet_or_touchpad(parent)) { libwacom_error_set(error, WERROR_INVALID_PATH, "Device '%s' is not a tablet", path); g_object_unref (parent); goto out; } g_object_unref (parent); } /* Is the device integrated in display? */ devname = g_udev_device_get_name (device); if (devname != NULL) { char *sysfs_path, *contents; sysfs_path = g_build_filename ("/sys/class/input", devname, "device/properties", NULL); if (g_file_get_contents (sysfs_path, &contents, NULL, NULL)) { int flag; flag = atoi(contents); flag &= (1 << INPUT_PROP_DIRECT) | (1 << INPUT_PROP_POINTER); /* * To ensure we are dealing with a screen tablet, need * to check that it has DIRECT and non-POINTER (DIRECT * alone is not sufficient since it's set for drawing * tablets as well) */ if (flag == (1 << INPUT_PROP_DIRECT)) *integration_flags = WACOM_DEVICE_INTEGRATED_DISPLAY; else *integration_flags = WACOM_DEVICE_INTEGRATED_NONE; g_free (contents); } g_free (sysfs_path); } *name = g_strdup (g_udev_device_get_sysfs_attr (device, "name")); /* Try getting the name from the parent if that fails */ if (*name == NULL) { GUdevDevice *parent; parent = g_udev_device_get_parent (device); if (!parent) goto out; *name = g_strdup (g_udev_device_get_sysfs_attr (parent, "name")); g_object_unref (parent); } /* Parse the PRODUCT attribute (for Bluetooth, USB, I2C) */ retval = get_bus_vid_pid (device, bus, vendor_id, product_id, error); if (retval) goto out; bus_str = get_bus (device); *bus = bus_from_str (bus_str); if (*bus == WBUSTYPE_SERIAL) { /* The serial bus uses 0:0 as the vid/pid */ *vendor_id = 0; *product_id = 0; retval = TRUE; } else { libwacom_error_set(error, WERROR_UNKNOWN_MODEL, "Unsupported bus '%s'", bus_str); } out: if (bus_str != NULL) g_free (bus_str); if (retval == FALSE) g_free (*name); if (device != NULL) g_object_unref (device); if (client != NULL) g_object_unref (client); return retval; }