update
This commit is contained in:
parent
1ef2324dc8
commit
0126dfe8c9
@ -18,15 +18,16 @@
|
||||
static char tx_data[16] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
|
||||
static char rx_data[16] = {0};
|
||||
|
||||
static struct kobject *w25qxx_kobj; //定义一个led_kobj
|
||||
|
||||
struct spi_transfer xfer;
|
||||
struct spi_device *w25qxx_spi; //保存spi设备结构体
|
||||
static ssize_t w25qxx_show(struct kobject* kobjs,struct kobj_attribute *attr,char *buf)
|
||||
|
||||
static ssize_t w25qxx_show(struct device *dev,struct device_attribute *attr,char *buf)
|
||||
{
|
||||
return sprintf(buf,"read status register=%d\n",rx_data[0]);
|
||||
}
|
||||
|
||||
static ssize_t w25qxx_store(struct kobject *kobj, struct kobj_attribute *attr,const char *buf, size_t count)
|
||||
static ssize_t w25qxx_store(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
int erase_addr=0x123456;
|
||||
@ -45,7 +46,7 @@ static ssize_t w25qxx_store(struct kobject *kobj, struct kobj_attribute *attr,co
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct kobj_attribute w25qxx_attr = __ATTR(w25q128_dev,0660,w25qxx_show,w25qxx_store);
|
||||
static DEVICE_ATTR(w25q128, 0660, w25qxx_show, w25qxx_store); //定义文件属性
|
||||
|
||||
static void w25qxx_init(void)
|
||||
{
|
||||
@ -59,13 +60,7 @@ static void w25qxx_init(void)
|
||||
static int w25qxx_probe(struct spi_device *spi)
|
||||
{
|
||||
int ret;
|
||||
w25qxx_kobj = kobject_create_and_add("sys_w25qxx",NULL);
|
||||
if(w25qxx_kobj == NULL)
|
||||
{
|
||||
printk(KERN_INFO"create w25qxx_kobj failed!\n");
|
||||
return -1;
|
||||
}
|
||||
ret = sysfs_create_file(w25qxx_kobj, &w25qxx_attr.attr);
|
||||
ret = device_create_file(&spi->dev,&dev_attr_w25q128);//创建属性文件
|
||||
if(ret != 0)
|
||||
{
|
||||
printk(KERN_INFO"create w25q128_dev file failed!\n");
|
||||
@ -78,8 +73,7 @@ static int w25qxx_probe(struct spi_device *spi)
|
||||
|
||||
static int w25qxx_remove(struct spi_device *spi)
|
||||
{
|
||||
sysfs_remove_file(w25qxx_kobj, &w25qxx_attr.attr); //删除属性
|
||||
kobject_put(w25qxx_kobj); //删除对象
|
||||
device_remove_file(&spi->dev,&dev_attr_w25q128);//删除属性文件
|
||||
printk(KERN_INFO "exit sysfs w25qxx!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -13,10 +13,9 @@
|
||||
#include <linux/sysfs.h> //包含sysfs操作文件函数
|
||||
|
||||
static char recv[16] = {0}; //保存接收数据
|
||||
static struct kobject *at24c02_kobj; //定义一个led_kobj
|
||||
struct i2c_client *at24c02_dev; //定义一个i2c设备结构体指针
|
||||
|
||||
static ssize_t at24c02_show(struct kobject* kobjs,struct kobj_attribute *attr,char *buf)
|
||||
static ssize_t at24c02_show(struct device *dev,struct device_attribute *attr,char *buf)
|
||||
{
|
||||
int ret;
|
||||
ret = i2c_smbus_write_byte(at24c02_dev,0x02); //先发写地址操作
|
||||
@ -28,7 +27,7 @@ static ssize_t at24c02_show(struct kobject* kobjs,struct kobj_attribute *attr,ch
|
||||
return sprintf(buf,"read data = 0x%x\n",recv[0]);
|
||||
}
|
||||
|
||||
static ssize_t at24c02_store(struct kobject *kobj, struct kobj_attribute *attr,const char *buf, size_t count)
|
||||
static ssize_t at24c02_store(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
|
||||
{
|
||||
int ret;
|
||||
char data = 0x2f;
|
||||
@ -40,18 +39,13 @@ static ssize_t at24c02_store(struct kobject *kobj, struct kobj_attribute *attr,c
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct kobj_attribute at24c02_attr = __ATTR(at24c02_dev,0660,at24c02_show,at24c02_store);
|
||||
static DEVICE_ATTR(at24c02, 0660, at24c02_show, at24c02_store); //定义文件属性
|
||||
|
||||
|
||||
static int at24c02_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
int ret;
|
||||
at24c02_kobj = kobject_create_and_add("sys_at24c02",NULL);
|
||||
if(at24c02_kobj == NULL)
|
||||
{
|
||||
printk(KERN_INFO"create at24c02_kobj failed!\n");
|
||||
return -1;
|
||||
}
|
||||
ret = sysfs_create_file(at24c02_kobj, &at24c02_attr.attr);
|
||||
ret = device_create_file(&client->dev,&dev_attr_at24c02);//创建属性文件
|
||||
if(ret != 0)
|
||||
{
|
||||
printk(KERN_INFO"create at24c02_dev file failed!\n");
|
||||
@ -63,8 +57,7 @@ static int at24c02_probe(struct i2c_client *client, const struct i2c_device_id *
|
||||
|
||||
static int at24c02_remove(struct i2c_client *client)
|
||||
{
|
||||
sysfs_remove_file(at24c02_kobj, &at24c02_attr.attr); //删除属性
|
||||
kobject_put(at24c02_kobj); //删除对象
|
||||
device_remove_file(&client->dev,&dev_attr_at24c02);//删除属性文件
|
||||
printk(KERN_INFO "exit sysfs at24c02!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@
|
||||
#include <linux/sysfs.h> //包含sysfs操作文件函数
|
||||
#include <linux/regmap.h>
|
||||
|
||||
static struct kobject *oled_kobj; //定义一个led_kobj
|
||||
|
||||
static struct regmap *oled_regmap;
|
||||
|
||||
@ -126,30 +125,24 @@ static const struct regmap_config oled_config =
|
||||
.volatile_reg = false,
|
||||
};
|
||||
|
||||
static ssize_t oled_show(struct kobject* kobjs,struct kobj_attribute *attr,char *buf)
|
||||
static ssize_t oled_show(struct device *dev,struct device_attribute *attr,char *buf)
|
||||
{
|
||||
oled_off();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ssize_t oled_store(struct kobject *kobj, struct kobj_attribute *attr,const char *buf, size_t count)
|
||||
static ssize_t oled_store(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
|
||||
{
|
||||
oled_fill_screen(*buf);
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct kobj_attribute oled_attr = __ATTR(oled_dev,0660,oled_show,oled_store);
|
||||
static DEVICE_ATTR(oled, 0660, oled_show, oled_store); //定义文件属性
|
||||
|
||||
static int oled_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
int ret;
|
||||
oled_kobj = kobject_create_and_add("sys_oled",NULL);
|
||||
if(oled_kobj == NULL)
|
||||
{
|
||||
printk(KERN_INFO"create oled_kobj failed!\n");
|
||||
return -1;
|
||||
}
|
||||
ret = sysfs_create_file(oled_kobj, &oled_attr.attr);
|
||||
ret = device_create_file(&client->dev,&dev_attr_oled);//创建属性文件
|
||||
if(ret != 0)
|
||||
{
|
||||
printk(KERN_INFO"create oled_dev file failed!\n");
|
||||
@ -162,8 +155,7 @@ static int oled_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
|
||||
static int oled_remove(struct i2c_client *client)
|
||||
{
|
||||
sysfs_remove_file(oled_kobj, &oled_attr.attr); //删除属性
|
||||
kobject_put(oled_kobj); //删除对象
|
||||
device_remove_file(&client->dev,&dev_attr_oled);//删除属性文件
|
||||
regmap_exit(oled_regmap);
|
||||
printk(KERN_INFO "exit sysfs oled!\n");
|
||||
return 0;
|
||||
|
||||
@ -15,15 +15,16 @@
|
||||
#include <linux/string.h>
|
||||
#include <linux/gpio.h> //包含gpio一些宏
|
||||
|
||||
static struct kobject *led_kobj; //定义一个led_kobj
|
||||
|
||||
struct gpio_desc *led_pin; //gpio资源
|
||||
|
||||
static ssize_t led_show(struct kobject* kobjs,struct kobj_attribute *attr,char *buf)
|
||||
|
||||
static ssize_t led_show(struct device *dev,struct device_attribute *attr,char *buf)
|
||||
{
|
||||
return sprintf(buf,"led status=%d\n",gpiod_get_value(led_pin));
|
||||
}
|
||||
|
||||
static ssize_t led_store(struct kobject *kobj, struct kobj_attribute *attr,const char *buf, size_t count)
|
||||
static ssize_t led_store(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
|
||||
{
|
||||
if(0 == memcmp(buf,"on",2))
|
||||
{
|
||||
@ -40,18 +41,13 @@ static ssize_t led_store(struct kobject *kobj, struct kobj_attribute *attr,const
|
||||
return count;
|
||||
}
|
||||
|
||||
static struct kobj_attribute led_attr = __ATTR(led_dev,0660,led_show,led_store);
|
||||
static DEVICE_ATTR(led, 0660, led_show, led_store); //定义文件属性
|
||||
|
||||
|
||||
static int led_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret;
|
||||
led_kobj = kobject_create_and_add("sys_led",NULL);
|
||||
if(led_kobj == NULL)
|
||||
{
|
||||
printk(KERN_INFO"create led_kobj failed!\n");
|
||||
return -1;
|
||||
}
|
||||
ret = sysfs_create_file(led_kobj,&led_attr.attr);
|
||||
ret = device_create_file(&pdev->dev,&dev_attr_led);//创建属性文件
|
||||
if(ret != 0)
|
||||
{
|
||||
printk(KERN_INFO"create w25q128_dev file failed!\n");
|
||||
@ -70,8 +66,7 @@ static int led_probe(struct platform_device *pdev)
|
||||
|
||||
static int led_remove(struct platform_device *pdev)
|
||||
{
|
||||
sysfs_remove_file(led_kobj, &led_attr.attr); //删除属性
|
||||
kobject_put(led_kobj); //删除对象
|
||||
device_remove_file(&pdev->dev,&dev_attr_led);//删除属性文件
|
||||
devm_gpiod_put(&pdev->dev,led_pin);
|
||||
printk(KERN_INFO "exit sysfs sys_led!\n");
|
||||
return 0;
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user