forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/misc/nkio/nk_io_core.c
....@@ -12,15 +12,19 @@
1212 #include <asm/uaccess.h>
1313 #include <linux/string.h>
1414 #include <linux/uaccess.h>
15
+#include <linux/device.h>
16
+#include <linux/proc_fs.h>
1517
1618 #define GPIO_FUNCTION_OUTPUT 0
1719 #define GPIO_FUNCTION_INPUT 1
1820 #define GPIO_FUNCTION_RESET 3
19
-
20
-static int flash_flag = 0;
21
+#define HIGH "1"
22
+#define LOW "0"
23
+
24
+//static int flash_flag = 0;
2125
2226 struct ndj_gpio {
23
- int gpio_num; //gpui num
27
+ int gpio_num; //gpio num
2428 int action; //gpio flag
2529 int gpio_event; //input only
2630 int send_mode; //input only
....@@ -31,13 +35,67 @@
3135
3236 struct ndj_gpio_data {
3337 struct ndj_gpio ndj_gpio_num[20];
34
- struct input_dev *input;
3538 struct timer_list mytimer;
3639 int gpio_dts_num;
40
+ unsigned int gpio_op0;
41
+ unsigned int gpio_op1;
3742 };
38
-
43
+
3944 static struct ndj_gpio_data *gpio_data = NULL;
40
-static int event_flag = 0;
45
+
46
+/* creat sysfs gpio api node*/
47
+#if 0
48
+static ssize_t gpio_op0_show(struct class *class,struct class_attribute *attr, char *buf)
49
+{
50
+ return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op0));
51
+}
52
+
53
+static ssize_t gpio_op0_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
54
+{
55
+ if(!strncmp(buf, HIGH, strlen(HIGH))) {
56
+ gpio_set_value(gpio_data->gpio_op0, 1);
57
+
58
+ } else if(!strncmp(buf, LOW, strlen(LOW))) {
59
+ gpio_set_value(gpio_data->gpio_op0, 0);
60
+ }
61
+ return size;
62
+}
63
+
64
+static ssize_t gpio_op1_show(struct class *class,struct class_attribute *attr, char *buf)
65
+{
66
+ return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op1));
67
+}
68
+
69
+static ssize_t gpio_op1_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
70
+{
71
+ if(!strncmp(buf, HIGH, strlen(HIGH))) {
72
+ gpio_set_value(gpio_data->gpio_op1, 1);
73
+
74
+ } else if(!strncmp(buf, LOW, strlen(LOW))) {
75
+ gpio_set_value(gpio_data->gpio_op1, 0);
76
+ }
77
+ return size;
78
+}
79
+
80
+static CLASS_ATTR_RW(gpio_op0);
81
+static CLASS_ATTR_RW(gpio_op1);
82
+
83
+static struct attribute *ndj_gpio_attrs[] = {
84
+ &class_attr_gpio_op0.attr,
85
+ &class_attr_gpio_op1.attr,
86
+ NULL,
87
+};
88
+
89
+ATTRIBUTE_GROUPS(ndj_gpio);
90
+
91
+/** Device model classes */
92
+struct class ndj_io_class = {
93
+ .name = "io_control", //sysfs directory
94
+ .class_groups = ndj_gpio_groups,
95
+};
96
+
97
+#endif
98
+//static int event_flag = 0;
4199 static int open_now = 0;
42100 static char* file_name = NULL;
43101
....@@ -95,28 +153,21 @@
95153 }
96154
97155
98
-static const struct file_operations gpio_ops = {
99
- .owner = THIS_MODULE,
100
- .open = gpio_open,
101
- .write = gpio_write,
102
- .read = gpio_read,
156
+static const struct proc_ops gpio_ops = {
157
+ .proc_open = gpio_open,
158
+ .proc_write = gpio_write,
159
+ .proc_read = gpio_read,
103160 };
104161
105162 static int ndj_gpio_probe(struct platform_device *pdev) {
106163 struct device_node *np = pdev->dev.of_node;
107164 struct device_node *child_np;
108
- struct device *dev = &pdev->dev;
109165 static struct proc_dir_entry *root_entry_gpio;
110166 enum of_gpio_flags gpio_flags;
111167 int ret = 0;
112168 int gpio_cnt = 0;
113169 char gpio_name_num[20];
114170 int gpio_in_cnt = 0;
115
- int cnt =0;
116
- int lvds_index = 0;
117
- int gpio0, gpio1, gpio2, gpio3;
118
- int i=0;
119
- enum of_gpio_flags flags;
120171
121172 gpio_data = devm_kzalloc(&pdev->dev, sizeof(struct ndj_gpio_data),GFP_KERNEL);
122173 if (!gpio_data) {
....@@ -130,6 +181,23 @@
130181 if (gpio_data->gpio_dts_num == 0){
131182 dev_info(&pdev->dev, "no gpio defined\n");
132183 }
184
+
185
+ #if 0
186
+ /*gpio_op0*/
187
+ ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
188
+ if (ret < 0) {
189
+ printk("%s() Can not read property gpio_op0\n", __func__);
190
+ return -ENODEV;
191
+ }
192
+ gpio_data->gpio_op0 = ret;
193
+ ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
194
+ if(ret < 0){
195
+ printk("%s() gpio_op0 request ERROR\n", __func__);
196
+ return -ENODEV;
197
+ }
198
+
199
+ gpio_direction_output(gpio_data->gpio_op0,!gpio_flags);
200
+#endif
133201
134202 /* create node */
135203 root_entry_gpio = proc_mkdir("ndj_gpio", NULL);
....@@ -161,9 +229,9 @@
161229
162230 gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
163231 //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));
232
+ //event_flag = gpio_flags;
233
+ //of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
234
+ //of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
167235 gpio_in_cnt++;
168236 }
169237 break;
....@@ -200,22 +268,29 @@
200268 gpio_cnt++;
201269 }
202270
203
- platform_set_drvdata(pdev, gpio_data);
271
+ platform_set_drvdata(pdev, gpio_data);
272
+
273
+#if 0
274
+ ret= class_register(&ndj_io_class);
275
+ if(ret < 0) {
276
+ return -EINVAL;
277
+ }
278
+#endif
204279 return 0;
205280 }
206281
207282
208283 static int ndj_gpio_suspend(struct platform_device *pdev, pm_message_t state)
209284 {
210
- int ret;
211
- struct nk_io_pdata *pdata;
285
+// int ret;
286
+// struct nk_io_pdata *pdata;
212287 printk("nk_suspend !!!!\n");
213288 return 0;
214289 }
215290
216291 static int ndj_gpio_resume(struct platform_device *pdev)
217292 {
218
- int ret,reset_pin;
293
+// int ret,reset_pin;
219294 printk("nk_io resume !!!!\n");
220295 return 0;
221296 }
....@@ -223,6 +298,7 @@
223298
224299 static int ndj_gpio_remove(struct platform_device *pdev)
225300 {
301
+// class_unregister(&ndj_io_class);
226302 return 0;
227303 }
228304
....@@ -245,4 +321,4 @@
245321
246322 module_platform_driver(ndj_gpio_driver);
247323 MODULE_LICENSE("GPL");
248
-MODULE_LICENSE("GPL");
324
+MODULE_LICENSE("GPL");