dev: implement driver objects to organise and identify devices
This commit is contained in:
32
dev/input.c
32
dev/input.c
@@ -21,14 +21,6 @@ struct input_device *input_device_create(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&input_device_ids_lock, &flags);
|
||||
unsigned int id = bitmap_lowest_clear(input_device_ids, INPUT_DEVICE_MAX);
|
||||
bitmap_set(input_device_ids, id);
|
||||
spin_unlock_irqrestore(&input_device_ids_lock, flags);
|
||||
|
||||
input_dev->i_id = id;
|
||||
|
||||
return INPUT_DEVICE(dev);
|
||||
}
|
||||
|
||||
@@ -63,9 +55,27 @@ kern_status_t input_device_read(struct device *dev, void *buf, size_t size, size
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t input_device_generate_name(struct input_device *dev)
|
||||
static kern_status_t generate_name(struct input_device *dev, char out[DEV_NAME_MAX])
|
||||
{
|
||||
struct device *d = input_device_base(dev);
|
||||
snprintf(d->dev_name, sizeof d->dev_name, "input%u", dev->i_id);
|
||||
snprintf(out, DEV_NAME_MAX, "input%u", dev->i_id);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t input_device_register(struct input_device *dev)
|
||||
{
|
||||
unsigned long flags;
|
||||
spin_lock_irqsave(&input_device_ids_lock, &flags);
|
||||
unsigned int id = bitmap_lowest_clear(input_device_ids, INPUT_DEVICE_MAX);
|
||||
bitmap_set(input_device_ids, id);
|
||||
spin_unlock_irqrestore(&input_device_ids_lock, flags);
|
||||
|
||||
dev->i_id = id;
|
||||
|
||||
char name[DEV_NAME_MAX];
|
||||
generate_name(dev, name);
|
||||
char path[OBJECT_PATH_MAX];
|
||||
snprintf(path, sizeof path, "/dev/input/%s", name);
|
||||
|
||||
struct device *base = input_device_base(dev);
|
||||
return object_namespace_create_link(global_namespace(), path, &base->dev_base);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user