热门内容

公众号"MAKE1"

获取行业最新资讯

请扫码添加

专业客服企业微信

节点

简介

节点

/*

*

* Use of source code is subject to the terms of the LeadCore license agreement under

* which you licensed source code. If you did not accept the terms of the license agreement,

* you are not authorized to use source code. For the terms of the license, please see the

* license agreement between you and LeadCore.

*

* Copyright (c) 2010-2019 LeadCoreTech Corp.

*

* PURPOSE: This files contains the comip sysfs driver.

*

* CHANGE HISTORY:

*

* Version Date Author Description

* 1.0.0 2012-03-06 zouqiao created

*

*/

 

#include <linux/kernel.h>

#include <linux/init.h>

#include <linux/module.h>

#include <linux/errno.h>

#include <linux/slab.h>

#include <linux/reboot.h>

#include <linux/spinlock.h>

#include <linux/io.h>

#include <linux/delay.h>

#include <linux/gpio.h>

#include <mach/gpio.h>

#include <plat/mfp.h>

#include <plat/bootinfo.h>

#include <plat/comip-pmic.h>

 

//#include <plat/lc1160_codec.h>

 

#define comip_attr(_name, _mode)

static struct kobj_attribute _name##_attr = {

.attr = {

.name = __stringify(_name),

.mode = _mode,

},

.show = _name##_show,

.store = _name##_store,

}

// int flage=0;

/*

Setting value : Voltage(mv)

0 : 0

1 : 1800

2 : 3000

3 : 5000

*/

static ssize_t torch_enable_show(struct kobject *kobj, struct kobj_attribute *attr, char * buf)

{

int ret;

int value;

int voltage = -1;

 

//ret = pmic_voltage_get(PMIC_POWER_USIM, 0, &voltage);

if (ret)

return ret;

 

/*switch(voltage) {

case 0:

value = 0;

break;

case 1800:

value = 1;

break;

case 3000:

value = 2;

break;

case 5000:

default:

return -EINVAL;

}*/

 

return sprintf(buf, "%d", value);

}

 

static ssize_t torch_enable_store(struct kobject *kobj, struct kobj_attribute *attr, const char * buf, size_t n)

{

char *endp;

//int ret;

int value;

 

static int torch_switch= mfp_to_gpio(175);

static int torch_switch_Flash_EN= mfp_to_gpio(211);

static int torch_switch_Flash= mfp_to_gpio(210);

gpio_request(torch_switch, "torch_switch switch");

gpio_request(torch_switch_Flash_EN, "torch_switch Enable");

gpio_request(torch_switch_Flash, "torch_switch Flash");

gpio_direction_output(torch_switch_Flash_EN, 0);

gpio_direction_output(torch_switch_Flash, 0);

value = simple_strtoul(buf, &endp, 0);

printk("[young12]:comip-sysfs-torch.c torch_enable_store!!!n");

printk("[young12]:value %d !!!!n",value);

if (buf == endp)

return -EINVAL;

 

switch(value) {

case 1:

printk("[young12]:hub_torch_tf_switch high!!!!n");

gpio_direction_output(torch_switch_Flash_EN, 1);

gpio_direction_output(torch_switch, 1);

break;

case 2:

printk("[young12]:hub_torch_tf_switch low!!!!n");

gpio_direction_output(torch_switch, 0);

gpio_direction_output(torch_switch_Flash_EN, 0);

break;

default:

return -EINVAL;

}

gpio_free(torch_switch);

gpio_free(torch_switch_Flash);

 

return n;

}

 

/*extern int get_flage_kernel_value()

{

printk("[young]: flage %d!!!!n",flage);

return flage;

}*/

comip_attr(torch_enable, 0644);

 

static struct kobject *comip_kobj = NULL;

 

static struct attribute * comip_attrs[] = {

&torch_enable_attr.attr,

NULL,

};

 

static struct attribute_group comip_attr_group = {

.attrs = comip_attrs,

};

 

static int __init comip_sysfs_init(void)

{

int ret = -ENOMEM;

int event = PMIC_RTC_ALARM_POWEROFF ? PMIC_EVENT_RTC2 : PMIC_EVENT_RTC1;

comip_kobj = kobject_create_and_add("comip_torch", NULL); //节点位置?

if (comip_kobj == NULL) {

printk(KERN_ERR "comip_sysfs_init: kobject_create_and_add failed.n");

goto kobject_create_failed;

}

 

ret = sysfs_create_group(comip_kobj, &comip_attr_group);

if (ret) {

printk(KERN_ERR "comip_sysfs_init: sysfs_create_group failed.n");

goto sysfs_create_failed;

}

 

return ret;

 

sysfs_create_failed:

kobject_del(comip_kobj);

kobject_create_failed:

pmic_callback_mask(event);

pmic_callback_unregister(event);

failed:

return ret;

}

 

static void __exit comip_sysfs_exit(void)

{

int event = PMIC_RTC_ALARM_POWEROFF ? PMIC_EVENT_RTC2 : PMIC_EVENT_RTC1;

 

pmic_callback_mask(event);

pmic_callback_unregister(event);

 

if (comip_kobj) {

sysfs_remove_group(comip_kobj, &comip_attr_group);

kobject_del(comip_kobj);

comip_kobj = NULL;

}

}

module_init(comip_sysfs_init);

module_exit(comip_sysfs_exit);

 

MODULE_AUTHOR("Jimmy <jimm.yang@ifiretech.com>");

MODULE_DESCRIPTION("COMIP sysfs");

MODULE_LICENSE("GPL");

 

0
 条评论
相关内容推荐