From 072de836f53be56a70cecf70b43ae43b7ce17376 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Mon, 11 Dec 2023 10:08:36 +0000
Subject: [PATCH] mk-rootfs.sh
---
kernel/drivers/misc/nkio/nk_io_core.c | 126 +++++++++++++++++++++++++++++++++--------
1 files changed, 101 insertions(+), 25 deletions(-)
diff --git a/kernel/drivers/misc/nkio/nk_io_core.c b/kernel/drivers/misc/nkio/nk_io_core.c
index 1e06855..c2f4ae1 100755
--- a/kernel/drivers/misc/nkio/nk_io_core.c
+++ b/kernel/drivers/misc/nkio/nk_io_core.c
@@ -12,15 +12,19 @@
#include <asm/uaccess.h>
#include <linux/string.h>
#include <linux/uaccess.h>
+#include <linux/device.h>
+#include <linux/proc_fs.h>
#define GPIO_FUNCTION_OUTPUT 0
#define GPIO_FUNCTION_INPUT 1
#define GPIO_FUNCTION_RESET 3
-
-static int flash_flag = 0;
+#define HIGH "1"
+#define LOW "0"
+
+//static int flash_flag = 0;
struct ndj_gpio {
- int gpio_num; //gpui num
+ int gpio_num; //gpio num
int action; //gpio flag
int gpio_event; //input only
int send_mode; //input only
@@ -31,13 +35,67 @@
struct ndj_gpio_data {
struct ndj_gpio ndj_gpio_num[20];
- struct input_dev *input;
struct timer_list mytimer;
int gpio_dts_num;
+ unsigned int gpio_op0;
+ unsigned int gpio_op1;
};
-
+
static struct ndj_gpio_data *gpio_data = NULL;
-static int event_flag = 0;
+
+/* creat sysfs gpio api node*/
+#if 0
+static ssize_t gpio_op0_show(struct class *class,struct class_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op0));
+}
+
+static ssize_t gpio_op0_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
+{
+ if(!strncmp(buf, HIGH, strlen(HIGH))) {
+ gpio_set_value(gpio_data->gpio_op0, 1);
+
+ } else if(!strncmp(buf, LOW, strlen(LOW))) {
+ gpio_set_value(gpio_data->gpio_op0, 0);
+ }
+ return size;
+}
+
+static ssize_t gpio_op1_show(struct class *class,struct class_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op1));
+}
+
+static ssize_t gpio_op1_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
+{
+ if(!strncmp(buf, HIGH, strlen(HIGH))) {
+ gpio_set_value(gpio_data->gpio_op1, 1);
+
+ } else if(!strncmp(buf, LOW, strlen(LOW))) {
+ gpio_set_value(gpio_data->gpio_op1, 0);
+ }
+ return size;
+}
+
+static CLASS_ATTR_RW(gpio_op0);
+static CLASS_ATTR_RW(gpio_op1);
+
+static struct attribute *ndj_gpio_attrs[] = {
+ &class_attr_gpio_op0.attr,
+ &class_attr_gpio_op1.attr,
+ NULL,
+};
+
+ATTRIBUTE_GROUPS(ndj_gpio);
+
+/** Device model classes */
+struct class ndj_io_class = {
+ .name = "io_control", //sysfs directory
+ .class_groups = ndj_gpio_groups,
+};
+
+#endif
+//static int event_flag = 0;
static int open_now = 0;
static char* file_name = NULL;
@@ -95,28 +153,21 @@
}
-static const struct file_operations gpio_ops = {
- .owner = THIS_MODULE,
- .open = gpio_open,
- .write = gpio_write,
- .read = gpio_read,
+static const struct proc_ops gpio_ops = {
+ .proc_open = gpio_open,
+ .proc_write = gpio_write,
+ .proc_read = gpio_read,
};
static int ndj_gpio_probe(struct platform_device *pdev) {
struct device_node *np = pdev->dev.of_node;
struct device_node *child_np;
- struct device *dev = &pdev->dev;
static struct proc_dir_entry *root_entry_gpio;
enum of_gpio_flags gpio_flags;
int ret = 0;
int gpio_cnt = 0;
char gpio_name_num[20];
int gpio_in_cnt = 0;
- int cnt =0;
- int lvds_index = 0;
- int gpio0, gpio1, gpio2, gpio3;
- int i=0;
- enum of_gpio_flags flags;
gpio_data = devm_kzalloc(&pdev->dev, sizeof(struct ndj_gpio_data),GFP_KERNEL);
if (!gpio_data) {
@@ -130,6 +181,23 @@
if (gpio_data->gpio_dts_num == 0){
dev_info(&pdev->dev, "no gpio defined\n");
}
+
+ #if 0
+ /*gpio_op0*/
+ ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
+ if (ret < 0) {
+ printk("%s() Can not read property gpio_op0\n", __func__);
+ return -ENODEV;
+ }
+ gpio_data->gpio_op0 = ret;
+ ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
+ if(ret < 0){
+ printk("%s() gpio_op0 request ERROR\n", __func__);
+ return -ENODEV;
+ }
+
+ gpio_direction_output(gpio_data->gpio_op0,!gpio_flags);
+#endif
/* create node */
root_entry_gpio = proc_mkdir("ndj_gpio", NULL);
@@ -161,9 +229,9 @@
gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
//gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
- event_flag = gpio_flags;
- of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
- of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
+ //event_flag = gpio_flags;
+ //of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
+ //of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
gpio_in_cnt++;
}
break;
@@ -200,22 +268,29 @@
gpio_cnt++;
}
- platform_set_drvdata(pdev, gpio_data);
+ platform_set_drvdata(pdev, gpio_data);
+
+#if 0
+ ret= class_register(&ndj_io_class);
+ if(ret < 0) {
+ return -EINVAL;
+ }
+#endif
return 0;
}
static int ndj_gpio_suspend(struct platform_device *pdev, pm_message_t state)
{
- int ret;
- struct nk_io_pdata *pdata;
+// int ret;
+// struct nk_io_pdata *pdata;
printk("nk_suspend !!!!\n");
return 0;
}
static int ndj_gpio_resume(struct platform_device *pdev)
{
- int ret,reset_pin;
+// int ret,reset_pin;
printk("nk_io resume !!!!\n");
return 0;
}
@@ -223,6 +298,7 @@
static int ndj_gpio_remove(struct platform_device *pdev)
{
+// class_unregister(&ndj_io_class);
return 0;
}
@@ -245,4 +321,4 @@
module_platform_driver(ndj_gpio_driver);
MODULE_LICENSE("GPL");
-MODULE_LICENSE("GPL");
\ No newline at end of file
+MODULE_LICENSE("GPL");
--
Gitblit v1.6.2