sysfs class 節點建立
阿新 • • 發佈:2018-12-17
/sys/devices/platform/qc_gpio/acc_detect
diff --git a/drivers/misc/qc_gpio.c b/drivers/misc/qc_gpio.c index e1d0b1a..df9afed 100644 --- a/drivers/misc/qc_gpio.c +++ b/drivers/misc/qc_gpio.c @@ -143,14 +143,6 @@ static ssize_t qc_gpio_write(struct file *file, const char __user *buffer, } } - - if(gpio_get_value(acc_detect_gpio) == CARREVERSE_GPIO_ACTIVE)//檢測到ACC打火 - new_detect_status |= ACC_DETECT_MASK; - else - new_detect_status &= ~ACC_DETECT_MASK; //ACC 關火 - - - if(new_detect_status != detect_status) { detect_status = new_detect_status; @@ -209,16 +201,31 @@ static const struct file_operations qc_gpio_fops = { .llseek = no_llseek, .unlocked_ioctl = qc_gpio_ioctl, }; + + static ssize_t show_acc_detect(struct device *dev, struct device_attribute *attr,char *buf) { + return sprintf(buf, "%u\n", (gpio_get_value(acc_detect_gpio)==1)?0:1); + } + + static DEVICE_ATTR(acc_detect, S_IRUGO | S_IWUSR, show_acc_detect,NULL); + + static struct attribute *qcdev_attrs[] = { + &dev_attr_acc_detect.attr, + NULL, + }; +static struct attribute_group qcdev_attr_grp = { + .attrs = qcdev_attrs, + }; + static irqreturn_t acc_detect_irq_handler(int irq, void *data) { if(acc_detect_status){ - acc_detect_status = 0;//關機/休眠前關 acc_en + acc_detect_status = 0;//enable acc_en //gpio_direction_output(sys_pwren_gpio, 0); gpio_direction_output(acc_en_gpio, 0); } else{ - acc_detect_status = 1;//開機/喚醒前開 acc_en + acc_detect_status = 1;//enable acc_en //gpio_direction_output(sys_pwren_gpio, 1); gpio_direction_output(acc_en_gpio, 1); } @@ -361,6 +368,13 @@ static int qc_gpio_probe(struct platform_device *pdev) goto IRQ_ERR; } + + result=sysfs_create_group(&pdev->dev.kobj,&qcdev_attr_grp); + if (result != 0) { + printk( "Failed to create xxx sysfs files: %d\n", result); + return result; + } + //acc_detect_request_irq(pdev); return 0; --------------------- 作者:阿贊88 來源:CSDN 原文:https://blog.csdn.net/touxiong/article/details/83344111 版權宣告:本文為博主原創文章,轉載請附上博文連結!