Commit be0b9c71 authored by Patrick Mochel's avatar Patrick Mochel

driver model: change struct device::present to enumerated value with multiple states.

Adapted from Greg KH: 

- add multiple possible enumerated states a device can be in: UNINITIALIZED, INITIALIZED,
  REGISTERED, and GONE.
- Check whether device is INITIALIZED or REGISTERED in device_present().
- Change struct device::current_state to ::power_state to better reflect what it is.
parent 6b1febf7
......@@ -33,7 +33,7 @@ int device_add(struct device *dev)
return -EINVAL;
down(&device_sem);
dev->present = 1;
dev->state = DEVICE_REGISTERED;
if (dev->parent) {
list_add_tail(&dev->g_list,&dev->parent->g_list);
list_add_tail(&dev->node,&dev->parent->children);
......@@ -77,6 +77,7 @@ void device_initialize(struct device *dev)
INIT_LIST_HEAD(&dev->intf_list);
spin_lock_init(&dev->lock);
atomic_set(&dev->refcount,1);
dev->state = DEVICE_INITIALIZED;
if (dev->parent)
get_device(dev->parent);
}
......@@ -112,7 +113,7 @@ struct device * get_device(struct device * dev)
{
struct device * ret = dev;
down(&device_sem);
if (dev && dev->present && atomic_read(&dev->refcount) > 0)
if (device_present(dev) && atomic_read(&dev->refcount) > 0)
atomic_inc(&dev->refcount);
else
ret = NULL;
......@@ -135,7 +136,7 @@ void put_device(struct device * dev)
list_del_init(&dev->g_list);
up(&device_sem);
BUG_ON(dev->present);
BUG_ON((dev->state != DEVICE_GONE));
device_del(dev);
}
......@@ -177,7 +178,7 @@ void device_del(struct device * dev)
void device_unregister(struct device * dev)
{
down(&device_sem);
dev->present = 0;
dev->state = DEVICE_GONE;
up(&device_sem);
pr_debug("DEV: Unregistering device. ID = '%s', name = '%s'\n",
......
......@@ -19,7 +19,7 @@ static DEVICE_ATTR(name,S_IRUGO,device_read_name,NULL);
static ssize_t
device_read_power(struct device * dev, char * page, size_t count, loff_t off)
{
return off ? 0 : sprintf(page,"%d\n",dev->current_state);
return off ? 0 : sprintf(page,"%d\n",dev->power_state);
}
static ssize_t
......
......@@ -48,6 +48,13 @@ enum {
RESUME_ENABLE,
};
enum device_state {
DEVICE_UNINITIALIZED = 0,
DEVICE_INITIALIZED = 1,
DEVICE_REGISTERED = 2,
DEVICE_GONE = 3,
};
struct device;
struct device_driver;
struct device_class;
......@@ -288,8 +295,8 @@ struct device {
void *platform_data; /* Platform specific data (e.g. ACPI,
BIOS data relevant to device) */
u32 present;
u32 current_state; /* Current operating state. In
enum device_state state;
u32 power_state; /* Current operating state. In
ACPI-speak, this is D0-D3, D0
being fully functional, and D3
being off. */
......@@ -363,7 +370,7 @@ extern int (*platform_notify_remove)(struct device * dev);
static inline int device_present(struct device * dev)
{
return (dev && dev->present == 1);
return (dev && (dev->state == DEVICE_INITIALIZED || dev->state == DEVICE_REGISTERED));
}
/* device and bus locking helpers.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment