hc
2023-08-30 862c27fc9920c83318c784bfdadf43a65df1ec8f
增加sysfs接口
2 files modified
103 ■■■■■ changed files
kernel/arch/arm64/boot/dts/rockchip/NK-R36S0.dtsi 3 ●●●●● patch | view | raw | blame | history
kernel/drivers/misc/nkio/nk_io_core.c 100 ●●●●● patch | view | raw | blame | history
kernel/arch/arm64/boot/dts/rockchip/NK-R36S0.dtsi
....@@ -93,6 +93,9 @@
9393 compatible = "nk_io_control";
9494 pinctrl-names = "default";
9595 pinctrl-0 = <&nk_io_gpio>;
96
+
97
+ //gpio_op0 = <&gpio1 RK_PD0 GPIO_ACTIVE_HIGH>;
98
+
9699 vcc_5v {
97100 gpio_num = <&gpio1 RK_PA4 GPIO_ACTIVE_HIGH>; //VCC5_IO_EN_GPIO1_A4_3V3
98101 gpio_function = <0>;
kernel/drivers/misc/nkio/nk_io_core.c
....@@ -12,15 +12,18 @@
1212 #include <asm/uaccess.h>
1313 #include <linux/string.h>
1414 #include <linux/uaccess.h>
15
+#include <linux/device.h>
1516
1617 #define GPIO_FUNCTION_OUTPUT 0
1718 #define GPIO_FUNCTION_INPUT 1
1819 #define GPIO_FUNCTION_RESET 3
19
-
20
+#define HIGH "1"
21
+#define LOW "0"
22
+
2023 static int flash_flag = 0;
2124
2225 struct ndj_gpio {
23
- int gpio_num; //gpui num
26
+ int gpio_num; //gpio num
2427 int action; //gpio flag
2528 int gpio_event; //input only
2629 int send_mode; //input only
....@@ -31,12 +34,66 @@
3134
3235 struct ndj_gpio_data {
3336 struct ndj_gpio ndj_gpio_num[20];
34
- struct input_dev *input;
3537 struct timer_list mytimer;
3638 int gpio_dts_num;
39
+ unsigned int gpio_op0;
40
+ unsigned int gpio_op1;
3741 };
38
-
42
+
3943 static struct ndj_gpio_data *gpio_data = NULL;
44
+
45
+/* creat sysfs gpio api node*/
46
+#if 0
47
+static ssize_t gpio_op0_show(struct class *class,struct class_attribute *attr, char *buf)
48
+{
49
+ return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op0));
50
+}
51
+
52
+static ssize_t gpio_op0_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
53
+{
54
+ if(!strncmp(buf, HIGH, strlen(HIGH))) {
55
+ gpio_set_value(gpio_data->gpio_op0, 1);
56
+
57
+ } else if(!strncmp(buf, LOW, strlen(LOW))) {
58
+ gpio_set_value(gpio_data->gpio_op0, 0);
59
+ }
60
+ return size;
61
+}
62
+
63
+static ssize_t gpio_op1_show(struct class *class,struct class_attribute *attr, char *buf)
64
+{
65
+ return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op1));
66
+}
67
+
68
+static ssize_t gpio_op1_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
69
+{
70
+ if(!strncmp(buf, HIGH, strlen(HIGH))) {
71
+ gpio_set_value(gpio_data->gpio_op1, 1);
72
+
73
+ } else if(!strncmp(buf, LOW, strlen(LOW))) {
74
+ gpio_set_value(gpio_data->gpio_op1, 0);
75
+ }
76
+ return size;
77
+}
78
+
79
+static CLASS_ATTR_RW(gpio_op0);
80
+static CLASS_ATTR_RW(gpio_op1);
81
+
82
+static struct attribute *ndj_gpio_attrs[] = {
83
+ &class_attr_gpio_op0.attr,
84
+ &class_attr_gpio_op1.attr,
85
+ NULL,
86
+};
87
+
88
+ATTRIBUTE_GROUPS(ndj_gpio);
89
+
90
+/** Device model classes */
91
+struct class ndj_io_class = {
92
+ .name = "io_control", //sysfs directory
93
+ .class_groups = ndj_gpio_groups,
94
+};
95
+
96
+#endif
4097 static int event_flag = 0;
4198 static int open_now = 0;
4299 static char* file_name = NULL;
....@@ -113,8 +170,6 @@
113170 char gpio_name_num[20];
114171 int gpio_in_cnt = 0;
115172 int cnt =0;
116
- int lvds_index = 0;
117
- int gpio0, gpio1, gpio2, gpio3;
118173 int i=0;
119174 enum of_gpio_flags flags;
120175
....@@ -130,6 +185,23 @@
130185 if (gpio_data->gpio_dts_num == 0){
131186 dev_info(&pdev->dev, "no gpio defined\n");
132187 }
188
+
189
+ #if 0
190
+ /*gpio_op0*/
191
+ ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
192
+ if (ret < 0) {
193
+ printk("%s() Can not read property gpio_op0\n", __func__);
194
+ return -ENODEV;
195
+ }
196
+ gpio_data->gpio_op0 = ret;
197
+ ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
198
+ if(ret < 0){
199
+ printk("%s() gpio_op0 request ERROR\n", __func__);
200
+ return -ENODEV;
201
+ }
202
+
203
+ gpio_direction_output(gpio_data->gpio_op0,!gpio_flags);
204
+#endif
133205
134206 /* create node */
135207 root_entry_gpio = proc_mkdir("ndj_gpio", NULL);
....@@ -161,9 +233,9 @@
161233
162234 gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
163235 //gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
164
- event_flag = gpio_flags;
165
- of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
166
- of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
236
+ //event_flag = gpio_flags;
237
+ //of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
238
+ //of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
167239 gpio_in_cnt++;
168240 }
169241 break;
....@@ -200,7 +272,14 @@
200272 gpio_cnt++;
201273 }
202274
203
- platform_set_drvdata(pdev, gpio_data);
275
+ platform_set_drvdata(pdev, gpio_data);
276
+
277
+#if 0
278
+ ret= class_register(&ndj_io_class);
279
+ if(ret < 0) {
280
+ return -EINVAL;
281
+ }
282
+#endif
204283 return 0;
205284 }
206285
....@@ -223,6 +302,7 @@
223302
224303 static int ndj_gpio_remove(struct platform_device *pdev)
225304 {
305
+// class_unregister(&ndj_io_class);
226306 return 0;
227307 }
228308