at v2.6.12-rc2 51 lines 1.4 kB view raw
1/* 2 * drivers/base/interface.c - common driverfs interface that's exported to 3 * the world for all devices. 4 * 5 * Copyright (c) 2002-3 Patrick Mochel 6 * Copyright (c) 2002-3 Open Source Development Labs 7 * 8 * This file is released under the GPLv2 9 * 10 */ 11 12#include <linux/device.h> 13#include <linux/err.h> 14#include <linux/stat.h> 15#include <linux/string.h> 16 17/** 18 * detach_state - control the default power state for the device. 19 * 20 * This is the state the device enters when it's driver module is 21 * unloaded. The value is an unsigned integer, in the range of 0-4. 22 * '0' indicates 'On', so no action will be taken when the driver is 23 * unloaded. This is the default behavior. 24 * '4' indicates 'Off', meaning the driver core will call the driver's 25 * shutdown method to quiesce the device. 26 * 1-3 indicate a low-power state for the device to enter via the 27 * driver's suspend method. 28 */ 29 30static ssize_t detach_show(struct device * dev, char * buf) 31{ 32 return sprintf(buf, "%u\n", dev->detach_state); 33} 34 35static ssize_t detach_store(struct device * dev, const char * buf, size_t n) 36{ 37 u32 state; 38 state = simple_strtoul(buf, NULL, 10); 39 if (state > 4) 40 return -EINVAL; 41 dev->detach_state = state; 42 return n; 43} 44 45static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store); 46 47 48struct attribute * dev_default_attrs[] = { 49 &dev_attr_detach_state.attr, 50 NULL, 51};