建立一個簡單的device_create_file檔案節點
阿新 • • 發佈:2019-02-11
使用的device_create_file 建立的節點在/sys/devices/下; 名字應該是“usb_status”
1. 定義:
static int gpio_number;
2. 定義操作函式:
static ssize_t switch_usb_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%d\n", gpio_get_value(gpio_number)); } static struct device_attribute switch_usb_attr = { .attr = { .name = "usb_status", .mode = 0444, }, .show = switch_usb_show, };
3. 建立節點:
if (device_create_file(dev, &switch_usb_attr))
dev_err(dev, "Unable to create sysfs entry: '%s'\n",
switch_usb_attr.attr.name);