hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/misc/nkio/nk_io_core.c
....@@ -1,613 +1,324 @@
1
-/*
2
- * Copyright (C) 2014 Rockchip Corporation.
3
- *
4
- * This software is licensed under the terms of the GNU General Public
5
- * License version 2, as published by the Free Software Foundation, and
6
- * may be copied, distributed, and modified under those terms.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
13
- */
141 #include <linux/module.h>
15
-#include <linux/moduleparam.h>
16
-#include <linux/init.h>
17
-#include <linux/delay.h>
18
-#include <linux/pm.h>
19
-#include <linux/i2c.h>
20
-#include <linux/spi/spi.h>
21
-#include <linux/platform_device.h>
22
-#include <linux/errno.h>
232 #include <linux/err.h>
24
-#include <linux/debugfs.h>
25
-#include <linux/of_gpio.h>
263 #include <linux/gpio.h>
27
-#include <linux/iio/consumer.h>
28
-#include <linux/of.h>
29
-#include "nkio.h"
4
+#include <linux/kernel.h>
5
+#include <linux/of_gpio.h>
6
+#include <linux/of_platform.h>
7
+#include <linux/delay.h>
8
+#include <linux/input.h>
9
+#include <linux/proc_fs.h>
10
+#include <linux/kernel.h>
11
+#include <linux/init.h>
12
+#include <asm/uaccess.h>
13
+#include <linux/string.h>
14
+#include <linux/uaccess.h>
15
+#include <linux/device.h>
16
+#include <linux/proc_fs.h>
17
+
18
+#define GPIO_FUNCTION_OUTPUT 0
19
+#define GPIO_FUNCTION_INPUT 1
20
+#define GPIO_FUNCTION_RESET 3
21
+#define HIGH "1"
22
+#define LOW "0"
3023
31
-/* Debug */
32
-#if 1
33
-#define DBG(x...) printk(x)
34
-#else
35
-#define DBG(x...) do { } while (0)
36
-#endif
24
+//static int flash_flag = 0;
25
+
26
+struct ndj_gpio {
27
+ int gpio_num; //gpio num
28
+ int action; //gpio flag
29
+ int gpio_event; //input only
30
+ int send_mode; //input only
31
+ int gpio_function; //gpio function,i/o
32
+ int gpio_ctrl;
33
+ char *gpio_name;
34
+};
35
+
36
+struct ndj_gpio_data {
37
+ struct ndj_gpio ndj_gpio_num[20];
38
+ struct timer_list mytimer;
39
+ int gpio_dts_num;
40
+ unsigned int gpio_op0;
41
+ unsigned int gpio_op1;
42
+};
3743
38
-struct nk_io_pdata *NKpdata_info;
39
-u32 op0_enable,op1_enable,op2_enable,op3_enable,op4_enable,op5_enable,mic_enable;
40
-u32 ip0_enable,ip1_enable,ip2_enable,ip3_enable,ip4_enable,ip5_enable;
41
-u32 module_enable;
42
-//static struct class *nk_class;
44
+static struct ndj_gpio_data *gpio_data = NULL;
4345
44
-
45
-
46
-void Audio_SET(int i);
47
-
48
- void Audio_SET(int i)
49
- {
50
- if(i==11){
51
- gpio_direction_output(NKpdata_info->audio_switch_gpio, 1);
52
- printk("Audio_SET ENABLE------andy\n");
53
- }else{
54
- gpio_direction_output(NKpdata_info->audio_switch_gpio, 0);
55
- printk("Audio_SET DISABLE------andy\n");
56
- }
57
- }
58
- EXPORT_SYMBOL_GPL(Audio_SET);
59
-
60
-static int nk_io_control_probe(struct platform_device *pdev)
61
-{
62
- struct device_node *node = pdev->dev.of_node;
63
- struct nk_io_pdata *pdata;
64
- int gpio0, gpio1, gpio2, gpio3, reset_pin, ch342_reset;
65
- int ret;
66
- int lvds_index;
67
- int i=0;
68
- static int lvds_gpio[4] ;
69
-
70
- enum of_gpio_flags flags;
71
-
72
- printk(" #######nk_io_control_probe####### \n");
73
-
74
- pdata = kzalloc(sizeof(struct nk_io_pdata), GFP_KERNEL);
75
- if (pdata == NULL) {
76
- printk("%s failed to allocate driver data\n",__FUNCTION__);
77
- return -ENOMEM;
78
- }
79
- memset(pdata,0,sizeof(struct nk_io_pdata));
80
-
81
- //vcc_5v_io
82
- ret = of_get_named_gpio_flags(node, "vcc_5v_io", 0, &flags);
83
- if (ret < 0) {
84
- printk("%s() Can not read property vcc_5v_io\n", __FUNCTION__);
85
- goto err;
86
- } else {
87
- pdata->vcc_5v_io = ret;
88
- ret = devm_gpio_request(&pdev->dev, pdata->vcc_5v_io, "vcc_5v_io");
89
- if(ret < 0){
90
- printk("%s() devm_gpio_request vcc_5v_io request ERROR\n", __FUNCTION__);
91
- goto err;
92
- }
93
-
94
- ret = gpio_direction_output(pdata->vcc_5v_io,1);
95
- if(ret < 0){
96
- printk("%s() gpio_direction_input vcc_5v_io set ERROR\n", __FUNCTION__);
97
- goto err;
98
- }
99
- }
100
-
101
- //vcc3_io_en_gpio
102
- ret = of_get_named_gpio_flags(node, "vcc3_io_en_gpio", 0, &flags);
103
- if (ret < 0) {
104
- printk("%s() Can not read property vcc3_io_en_gpio\n", __FUNCTION__);
105
- goto err;
106
- } else {
107
- pdata->vcc3_io_en_gpio = ret;
108
- ret = devm_gpio_request(&pdev->dev, pdata->vcc3_io_en_gpio, "vcc3_io_en_gpio");
109
- if(ret < 0){
110
- printk("%s() devm_gpio_request vcc3_io_en_gpio request ERROR\n", __FUNCTION__);
111
- goto err;
112
- }
113
-
114
- ret = gpio_direction_output(pdata->vcc3_io_en_gpio,1);
115
- if(ret < 0){
116
- printk("%s() gpio_direction_output vcc3_io_en_gpio set ERROR\n", __FUNCTION__);
117
- goto err;
118
- }
119
- }
120
-
121
- //vcc_12v_io
122
- ret = of_get_named_gpio_flags(node, "vcc_12v_io", 0, &flags);
123
- if (ret < 0) {
124
- printk("%s() Can not read property vcc_12v_io\n", __FUNCTION__);
125
- goto err;
126
- } else {
127
- pdata->vcc_12v_io = ret;
128
- ret = devm_gpio_request(&pdev->dev, pdata->vcc_12v_io, "vcc_12v_io");
129
- if(ret < 0){
130
- printk("%s() devm_gpio_request vcc_12v_io request ERROR\n", __FUNCTION__);
131
- goto err;
132
- }
133
-
134
- ret = gpio_direction_output(pdata->vcc_12v_io,1);
135
- if(ret < 0){
136
- printk("%s() gpio_direction_input vcc_12v_io set ERROR\n", __FUNCTION__);
137
- goto err;
138
- }
139
- }
140
-
141
-
142
- //hub_host2_5V_rest_gpio
143
- ret = of_get_named_gpio_flags(node, "hub_host2_5V_rest_gpio", 0, &flags);
144
- if (ret < 0) {
145
- printk("%s() Can not read property hub_host2_5V_rest_gpio\n", __FUNCTION__);
146
- goto err;
147
- } else {
148
- pdata->hub_host2_5V_rest_gpio = ret;
149
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host2_5V_rest_gpio, "hub_host2_5V_rest_gpio");
150
- if(ret < 0){
151
- printk("%s() devm_gpio_request hub_host2_5V_rest_gpio request ERROR\n", __FUNCTION__);
152
- goto err;
153
- }
154
-
155
- ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,0);
156
- if(ret < 0){
157
- printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__);
158
- goto err;
159
- }
160
- msleep(800);
161
- ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,1);
162
- if(ret < 0){
163
- printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__);
164
- goto err;
165
- }
166
- }
167
-
168
- //hub_host3_5v_gpio
169
- ret = of_get_named_gpio_flags(node, "hub_host3_5v_gpio", 0, &flags);
170
- if (ret < 0) {
171
- printk("%s() Can not read property hub_host3_5v_gpio\n", __FUNCTION__);
172
- goto err;
173
- } else {
174
- pdata->hub_host3_5v_gpio = ret;
175
- gpio_free(ret);
176
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5v_gpio, "hub_host3_5v_gpio");
177
- if(ret < 0){
178
- printk("%s() devm_gpio_request hub_host3_5v_gpio request ERROR\n", __FUNCTION__);
179
- goto err;
180
- }
181
-
182
- ret = gpio_direction_output(pdata->hub_host3_5v_gpio,1);
183
- if(ret < 0){
184
- printk("%s() gpio_direction_input hub_host3_5v_gpio set ERROR\n", __FUNCTION__);
185
- goto err;
186
- }
187
- }
46
+/* creat sysfs gpio api node*/
18847 #if 0
189
- //hub_host3_5V_rest_gpio
190
- ret = of_get_named_gpio_flags(node, "hub_host3_5V_rest_gpio", 0, &flags);
191
- if (ret < 0) {
192
- printk("%s() Can not read property hub_host3_5V_rest_gpio\n", __FUNCTION__);
193
- goto err;
194
- } else {
195
- pdata->hub_host3_5V_rest_gpio = ret;
196
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5V_rest_gpio, "hub_host3_5V_rest_gpio");
197
- if(ret < 0){
198
- printk("%s() devm_gpio_request hub_host3_5V_rest_gpio request ERROR\n", __FUNCTION__);
199
- goto err;
200
- }
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
+}
20152
202
- ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,0);
203
- if(ret < 0){
204
- printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__);
205
- goto err;
206
- }
207
- msleep(800);
208
- ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,1);
209
- if(ret < 0){
210
- printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__);
211
- goto err;
212
- }
213
- }
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
+
21497 #endif
215
- //wake_4g_gpio
216
- ret = of_get_named_gpio_flags(node, "wake_4g_gpio", 0, &flags);
217
- if (ret < 0) {
218
- printk("%s() Can not read property wake_4g_gpio\n", __FUNCTION__);
219
- } else {
220
- pdata->wake_4g_gpio = ret;
221
-
222
- ret = devm_gpio_request(&pdev->dev, pdata->wake_4g_gpio, "wake_4g_gpio");
223
- if(ret < 0){
224
- printk("%s() devm_gpio_request wake_4g_gpio request ERROR\n", __FUNCTION__);
225
- }
226
- ret = gpio_direction_output(pdata->wake_4g_gpio,0);
227
- if(ret < 0){
228
- printk("%s() gpio_direction_input wake_4g_gpio set ERROR\n", __FUNCTION__);
229
- }
230
- }
231
-
232
-
233
- //reset_4g_gpio
234
- ret = of_get_named_gpio_flags(node, "reset_4g_gpio", 0, &flags);
235
- if (ret < 0) {
236
- printk("%s() Can not read property reset_4g_gpio\n", __FUNCTION__);
237
- } else {
238
- pdata->reset_4g_gpio = ret;
239
-
240
- ret = devm_gpio_request(&pdev->dev, pdata->reset_4g_gpio, "reset_4g_gpio");
241
- if(ret < 0){
242
- printk("%s() devm_gpio_request reset_4g_gpio request ERROR\n", __FUNCTION__);
243
- }
244
- ret = gpio_direction_output(pdata->reset_4g_gpio,1);
245
- if(ret < 0){
246
- printk("%s() gpio_direction_input reset_4g_gpio set ERROR\n", __FUNCTION__);
247
- goto err;
248
- }
249
- msleep(800);
250
- ret = gpio_direction_output(pdata->reset_4g_gpio,0);
251
- if(ret < 0){
252
- printk("%s() gpio_direction_input reset_4g_gpio set ERROR\n", __FUNCTION__);
253
-
254
- }
255
- }
256
-
257
- //en_4g_gpio
258
- ret = of_get_named_gpio_flags(node, "en_4g_gpio", 0, &flags);
259
- if (ret < 0) {
260
- printk("%s() Can not read property en_4g_gpio\n", __FUNCTION__);
261
- } else {
262
- pdata->en_4g_gpio = ret;
263
-
264
- ret = devm_gpio_request(&pdev->dev, pdata->en_4g_gpio, "en_4g_gpio");
265
- if(ret < 0){
266
- printk("%s() devm_gpio_request en_4g_gpio request ERROR\n", __FUNCTION__);
267
- }
268
- ret = gpio_direction_output(pdata->en_4g_gpio,1);
269
- if(ret < 0){
270
- printk("%s() gpio_direction_output en_4g_gpio set ERROR\n", __FUNCTION__);
271
- }
272
- }
273
-
274
- //hp_en_gpio
275
- ret = of_get_named_gpio_flags(node, "hp_en_gpio", 0, &flags);
276
- if (ret < 0) {
277
- printk("%s() Can not read property hp_en_gpio\n", __FUNCTION__);
278
- } else {
279
- pdata->hp_en_gpio = ret;
280
-
281
- ret = devm_gpio_request(&pdev->dev, pdata->hp_en_gpio, "hp_en_gpio");
282
- if(ret < 0){
283
- printk("%s() devm_gpio_request hp_en_gpio request ERROR\n", __FUNCTION__);
284
- }
285
- ret = gpio_direction_output(pdata->hp_en_gpio,1);
286
- if(ret < 0){
287
- printk("%s() gpio_direction_output hp_en_gpio set ERROR\n", __FUNCTION__);
288
- }
289
- }
290
-
291
- //wifi_power_en_gpio
292
- ret = of_get_named_gpio_flags(node, "wifi_power_en_gpio", 0, &flags);
293
- if (ret < 0) {
294
- printk("%s() Can not read property wifi_power_en_gpio\n", __FUNCTION__);
295
- } else {
296
- pdata->wifi_power_en_gpio = ret;
297
-
298
- ret = devm_gpio_request(&pdev->dev, pdata->wifi_power_en_gpio, "wifi_power_en_gpio");
299
- if(ret < 0){
300
- printk("%s() devm_gpio_request wifi_power_en_gpio request ERROR\n", __FUNCTION__);
301
- }
302
- ret = gpio_direction_output(pdata->wifi_power_en_gpio,1);
303
- if(ret < 0){
304
- printk("%s() gpio_direction_output wifi_power_en_gpio set ERROR\n", __FUNCTION__);
305
- }
306
- }
307
-
308
-
309
- //spk_out_gpio
310
- ret = of_get_named_gpio_flags(node, "spk_out_gpio", 0, &flags);
311
- if (ret < 0) {
312
- printk("%s() Can not read property spk_out_gpio\n", __FUNCTION__);
313
- } else {
314
- pdata->spk_out_gpio = ret;
315
-
316
- ret = devm_gpio_request(&pdev->dev, pdata->spk_out_gpio, "spk_out_gpio");
317
- if(ret < 0){
318
- printk("%s() devm_gpio_request spk_out_gpio request ERROR\n", __FUNCTION__);
319
- }
320
- ret = gpio_direction_output(pdata->spk_out_gpio,0);
321
- if(ret < 0){
322
- printk("%s() gpio_direction_output spk_out_gpio set ERROR\n", __FUNCTION__);
323
- }
324
- }
325
- //air_mode_4g_gpio
326
- ret = of_get_named_gpio_flags(node, "air_mode_4g_gpio", 0, &flags);
327
- if (ret < 0) {
328
- printk("%s() Can not read property air_mode_4g_gpio\n", __FUNCTION__);
329
- } else {
330
- pdata->air_mode_4g_gpio = ret;
331
-
332
- ret = devm_gpio_request(&pdev->dev, pdata->air_mode_4g_gpio, "air_mode_4g_gpio");
333
- if(ret < 0){
334
- printk("%s() devm_gpio_request air_mode_4g_gpio request ERROR\n", __FUNCTION__);
335
- }
336
- ret = gpio_direction_output(pdata->air_mode_4g_gpio,0);
337
- if(ret < 0){
338
- printk("%s() gpio_direction_input air_mode_4g_gpio set ERROR\n", __FUNCTION__);
339
- }
340
- }
341
-
342
-
343
-/*
344
- //edp_power_supply_gpio;
345
- ret = of_get_named_gpio_flags(node, "edp_power_supply_gpio", 0, &flags);
346
- if (ret < 0) {
347
- printk("%s() Can not read property edp_power_supply_gpio\n", __FUNCTION__);
348
- } else {
349
- pdata->edp_power_supply_gpio = ret;
350
-
351
- ret = devm_gpio_request(&pdev->dev, pdata->edp_power_supply_gpio, "edp_power_supply_gpio");
352
- if(ret < 0){
353
- printk("%s() devm_gpio_request edp_power_supply_gpio request ERROR\n", __FUNCTION__);
354
- }
355
-
356
- ret = gpio_direction_output(pdata->edp_power_supply_gpio,1);
357
- if(ret < 0){
358
- printk("%s() gpio_direction_input edp_power_supply_gpio set ERROR\n", __FUNCTION__);
359
- }
360
- }
361
-
362
- //edp_enable-gpio;
363
- ret = of_get_named_gpio_flags(node, "edp_enable_gpio", 0, &flags);
364
- if (ret < 0) {
365
- printk("%s() Can not read property edp_enable_gpio\n", __FUNCTION__);
366
- } else {
367
- pdata->edp_enable_gpio = ret;
368
-
369
- ret = devm_gpio_request(&pdev->dev, pdata->edp_enable_gpio, "edp_enable_gpio");
370
- if(ret < 0){
371
- printk("%s() devm_gpio_request edp_enable_gpio request ERROR\n", __FUNCTION__);
372
- }
373
-
374
- ret = gpio_direction_output(pdata->edp_enable_gpio,1);
375
- if(ret < 0){
376
- printk("%s() gpio_direction_input edp_enable_gpio set ERROR\n", __FUNCTION__);
377
- }
378
- }
98
+//static int event_flag = 0;
99
+static int open_now = 0;
100
+static char* file_name = NULL;
101
+
102
+static int gpio_open(struct inode *inode, struct file *file)
103
+{
104
+ struct dentry* dent = file->f_path.dentry;
105
+ int i = 0;
106
+
107
+ file_name = (char*)(dent->d_name.name);
108
+
109
+ for (i = 0; i < gpio_data->gpio_dts_num; i++){
110
+ if(!strcmp(file_name,gpio_data->ndj_gpio_num[i].gpio_name)){
111
+ open_now = i;
112
+ }
113
+ }
114
+ return 0;
115
+}
116
+
117
+static ssize_t gpio_write(struct file *file, const char *buffer,size_t count, loff_t *data)
118
+{
119
+ char buf[2]={0};
120
+ char s1[]="1";
121
+
122
+ if(copy_from_user(&buf[0],buffer,1)){
123
+ printk("failed to copy data to kernel space\n");
124
+ return -EFAULT;
125
+ }
126
+
127
+ if(!strcmp(buf,s1)){
128
+ gpio_direction_output(gpio_data->ndj_gpio_num[open_now].gpio_num,1);
129
+ //printk("%s write 1 succeed\n",gpio_data->ndj_gpio_num[open_now].gpio_name);
130
+ }else{
131
+ gpio_direction_output(gpio_data->ndj_gpio_num[open_now].gpio_num,0);
132
+ //printk("%s write 0 succeed\n",gpio_data->ndj_gpio_num[open_now].gpio_name);
133
+ }
134
+ return count;
135
+}
136
+
137
+
138
+static ssize_t gpio_read(struct file *file, char __user * buffer, size_t count, loff_t *data)
139
+{
140
+ int gpio_val = 0;
141
+ int len = 0;
142
+ char s[10] = {0};
143
+
144
+ if(*data)
145
+ return 0;
146
+
147
+ gpio_val = gpio_get_value(gpio_data->ndj_gpio_num[open_now].gpio_num);
148
+ //printk("get %s value %d\n",gpio_data->ndj_gpio_num[open_now].gpio_name,gpio_val);
149
+
150
+ len = sprintf(s+len, "%d\n",gpio_val);
151
+
152
+ return simple_read_from_buffer(buffer, count, data, s, 2);
153
+}
154
+
155
+
156
+static const struct proc_ops gpio_ops = {
157
+ .proc_open = gpio_open,
158
+ .proc_write = gpio_write,
159
+ .proc_read = gpio_read,
160
+};
161
+
162
+static int ndj_gpio_probe(struct platform_device *pdev) {
163
+ struct device_node *np = pdev->dev.of_node;
164
+ struct device_node *child_np;
165
+ static struct proc_dir_entry *root_entry_gpio;
166
+ enum of_gpio_flags gpio_flags;
167
+ int ret = 0;
168
+ int gpio_cnt = 0;
169
+ char gpio_name_num[20];
170
+ int gpio_in_cnt = 0;
171
+
172
+ gpio_data = devm_kzalloc(&pdev->dev, sizeof(struct ndj_gpio_data),GFP_KERNEL);
173
+ if (!gpio_data) {
174
+ dev_err(&pdev->dev, "failed to allocate memory\n");
175
+ return -ENOMEM;
176
+ }
177
+
178
+ gpio_data->gpio_dts_num = of_get_child_count(np);
179
+// printk("ndj_gpio prepare build %d gpio\n",gpio_data->gpio_dts_num);
180
+
181
+ if (gpio_data->gpio_dts_num == 0){
182
+ dev_info(&pdev->dev, "no gpio defined\n");
183
+ }
379184
380
- //ch342_enable-gpio;
381
- ret = of_get_named_gpio_flags(node, "ch342_power", 0, &flags);
382
- if (ret < 0) {
383
- printk("%s() Can not read property ch342_gpio\n", __FUNCTION__);
384
- } else {
385
- pdata->ch342_power = ret;
386
-
387
- ret = devm_gpio_request(&pdev->dev, pdata->ch342_power, "ch342_power");
388
- if(ret < 0){
389
- printk("%s() devm_gpio_request ch342_power request ERROR\n", __FUNCTION__);
390
- }
391
-
392
- ret = gpio_direction_output(pdata->ch342_power,1);
393
- if(ret < 0){
394
- printk("%s() gpio_direction_input ch342_power set ERROR\n", __FUNCTION__);
395
- }
396
- }
397
-*/
398
-
399
- //edp_set_pixel-s
400
- ret = of_get_named_gpio_flags(node, "edp_reset", 0, &flags);
185
+ #if 0
186
+ /*gpio_op0*/
187
+ ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
401188 if (ret < 0) {
402
- printk("%s() Can not read property edp_reset\n", __FUNCTION__);
403
- goto err;
189
+ printk("%s() Can not read property gpio_op0\n", __func__);
190
+ return -ENODEV;
404191 }
405
-
406
- reset_pin = ret;
407
-
408
-// enable lvds
409
- ret = of_get_named_gpio_flags(node, "edp_gpio0", 0, &flags);
410
- if (ret < 0) {
411
- printk("%s() Can not read property edp_gpio0\n", __FUNCTION__);
412
- goto err;
413
- }
414
- gpio0 = ret;
415
-
416
-
417
-
418
- ret = of_get_named_gpio_flags(node, "edp_gpio1", 0, &flags);
419
- if (ret < 0) {
420
- printk("%s() Can not read property edp_gpio1\n", __FUNCTION__);
421
- goto err;
422
- }
423
-
424
- gpio1 = ret;
425
-
426
- ret = of_get_named_gpio_flags(node, "edp_gpio2", 0, &flags);
427
- if (ret < 0) {
428
- printk("%s() Can not read property edp_gpio2\n", __FUNCTION__);
429
- goto err;
430
- }
431
-
432
- gpio2 = ret;
433
-
434
- ret = of_get_named_gpio_flags(node, "edp_gpio3", 0, &flags);
435
- if (ret < 0) {
436
- printk("%s() Can not read property edp_gpio3\n", __FUNCTION__);
437
- goto err;
438
- }
439
-
440
- gpio3 = ret;
441
-
442
-
443
- ret = devm_gpio_request(&pdev->dev, reset_pin, "edp_reset");
192
+ gpio_data->gpio_op0 = ret;
193
+ ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
444194 if(ret < 0){
445
- printk("%s() devm_gpio_request edp_reset request ERROR\n", __FUNCTION__);
446
- goto err;
447
- }
448
-
449
-
450
- ret = devm_gpio_request(&pdev->dev, gpio0, "edp_gpio0");
451
- if(ret < 0){
452
- printk("%s() devm_gpio_request edp_gpio0 request ERROR\n", __FUNCTION__);
453
- goto err;
454
- }
455
-
456
- ret = devm_gpio_request(&pdev->dev, gpio1, "edp_gpio1");
457
- if(ret < 0){
458
- printk("%s() devm_gpio_request edp_gpio1 request ERROR\n", __FUNCTION__);
459
- goto err;
460
- }
461
-
462
- ret = devm_gpio_request(&pdev->dev, gpio2, "edp_gpio2");
463
- if(ret < 0){
464
- printk("%s() devm_gpio_request edp_gpio2 request ERROR\n", __FUNCTION__);
465
- goto err;
466
- }
467
-
468
- ret = devm_gpio_request(&pdev->dev, gpio3, "edp_gpio3");
469
- if(ret < 0){
470
- printk("%s() devm_gpio_request edp_gpio3 request ERROR\n", __FUNCTION__);
471
- goto err;
195
+ printk("%s() gpio_op0 request ERROR\n", __func__);
196
+ return -ENODEV;
472197 }
473198
474
- ret = of_property_read_u32(node, "nodka_lvds", &lvds_index);
475
- if (ret < 0){
476
- printk("%s() Can not read property nodka_lvds\n", __FUNCTION__);
477
- }
199
+ gpio_direction_output(gpio_data->gpio_op0,!gpio_flags);
200
+#endif
201
+
202
+ /* create node */
203
+ root_entry_gpio = proc_mkdir("ndj_gpio", NULL);
204
+
205
+ for_each_child_of_node(np, child_np)
206
+ {
207
+ /* parse dts */
208
+ gpio_data->ndj_gpio_num[gpio_cnt].gpio_num = of_get_named_gpio_flags(child_np, "gpio_num", 0, &gpio_flags);
209
+ if (!gpio_is_valid(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num)){
210
+ return -1;
211
+ }
212
+
213
+ gpio_data->ndj_gpio_num[gpio_cnt].gpio_name = (char*)child_np -> name;
214
+ gpio_data->ndj_gpio_num[gpio_cnt].action = gpio_flags;
215
+ gpio_data->ndj_gpio_num[gpio_cnt].gpio_ctrl = gpio_cnt;
216
+ of_property_read_u32(child_np, "gpio_function", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_function));
217
+
218
+// printk("ndj_gpio request %s\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
219
+
220
+
221
+ switch(gpio_data->ndj_gpio_num[gpio_cnt].gpio_function) {
222
+ case GPIO_FUNCTION_INPUT : /* init input gpio */
223
+ ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
224
+ if (ret < 0)
225
+ {
226
+ printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
227
+ }else{
228
+ // printk("success request gpio %d in\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
229
+
230
+ gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
231
+ //gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
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));
235
+ gpio_in_cnt++;
236
+ }
237
+ break;
238
+
239
+ case GPIO_FUNCTION_OUTPUT : /* init output gpio */
240
+ ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
241
+ if (ret < 0){
242
+ printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
243
+ //return ret;
244
+ }else{
245
+ gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
246
+ //printk("success request gpio%d out\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
247
+ }
248
+ break;
249
+
250
+ case GPIO_FUNCTION_RESET :
251
+ ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
252
+ if (ret < 0){
253
+ printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
254
+ //return ret;
255
+ }else{
256
+ gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,gpio_data->ndj_gpio_num[gpio_cnt].action);
257
+ //printk("success request gpio%d reset\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
258
+ mdelay(200);
259
+ gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
260
+
261
+// gpio_cnt++;
262
+ }
263
+ break;
264
+ }
265
+
266
+ sprintf(gpio_name_num,gpio_data->ndj_gpio_num[gpio_cnt].gpio_name,gpio_cnt);
267
+ proc_create(gpio_name_num, 0666 , root_entry_gpio , &gpio_ops);
268
+ gpio_cnt++;
269
+ }
270
+
271
+ platform_set_drvdata(pdev, gpio_data);
478272
479
- printk("nodka_lvds_index = %d\n",lvds_index);
480
-
481
- while ( i < 4 ){
482
- if ( lvds_index > 0)
483
- lvds_gpio[i] = lvds_index%2;
484
- else
485
- lvds_gpio[i] = 0;
486
- printk("lvds_gpio[%d]=%d\n",i,lvds_gpio[i]);
487
- lvds_index = lvds_index/2;
488
- i++;
489
- }
490
-
491
- gpio_direction_output(reset_pin, 0);
492
- usleep_range(80000, 100000);
493
- gpio_direction_output(reset_pin, 1);
494
- usleep_range(80000, 100000);
495
-
496
- gpio_direction_output(gpio0, lvds_gpio[0]);
497
- gpio_direction_output(gpio1, lvds_gpio[1]);
498
- gpio_direction_output(gpio2, lvds_gpio[2]);
499
- gpio_direction_output(gpio3, lvds_gpio[3]);
500
-
501
- printk(" #######nk_io_control_probe end####### \n");
502
- return 0;
503
-
504
-err:
505
- kfree(pdata);
506
- return ret;
507
-}
508
-
509
-
510
-static int nk_io_control_remove(struct platform_device *pdev)
511
-{
512
- if(NKpdata_info)
513
- kfree(NKpdata_info);
514
- return 0;
273
+#if 0
274
+ ret= class_register(&ndj_io_class);
275
+ if(ret < 0) {
276
+ return -EINVAL;
277
+ }
278
+#endif
279
+ return 0;
515280 }
516
-
517
-static int nk_io_control_suspend(struct platform_device *pdev, pm_message_t state)
281
+
282
+
283
+static int ndj_gpio_suspend(struct platform_device *pdev, pm_message_t state)
518284 {
519
- int ret;
520
- struct nk_io_pdata *pdata;
521
- printk("nk_suspend !!!!\n");
522
-#if 0
523
- ret = gpio_get_value(8);
524
- printk("vcc12v gpio value : %d\n",ret);
525
- usleep_range(80000, 100000);
526
- gpio_set_value(8,0);
527
- ret = gpio_get_value(8);
528
- printk("vcc12v gpio value : %d\n",ret);
529
-#endif
530
-#if 0
531
- ret = gpio_get_value(21);
532
- printk("hub_host3_5v_gpio value : %d\n",ret);
533
- usleep_range(80000, 100000);
534
- gpio_set_value(21,0);
535
- ret = gpio_get_value(21);
536
- printk("hub_host3_5v_gpio value : %d\n",ret);
537
- //enable = 0;
538
- //LED_SET(0);
539
-#endif
540
- return 0;
285
+// int ret;
286
+// struct nk_io_pdata *pdata;
287
+ printk("nk_suspend !!!!\n");
288
+ return 0;
541289 }
542
-
543
-static int nk_io_control_resume(struct platform_device *pdev)
290
+
291
+static int ndj_gpio_resume(struct platform_device *pdev)
544292 {
545
- int ret,reset_pin;
546
- printk("nk_io resume !!!!\n");
547
- ret = gpio_get_value(120);
548
-
549
-#if 0
550
- gpio_set_value(8,1);
551
- ret = gpio_get_value(8);
552
- printk("vcc12v gpio value : %d\n",ret);
553
-#endif
554
-#if 0
555
- gpio_set_value(15,1);
556
- ret = gpio_get_value(15);
557
- printk("edp_en gpio value : %d\n",ret);
558
- gpio_set_value(21,1);
559
- ret = gpio_get_value(21);
560
- printk("hub_host3_5v_gpio value : %d\n",ret);
561
-#endif
562
-#if 0
563
- usleep_range(80000, 100000);
564
- gpio_set_value(120,0);
565
-// gpio_direction_output(120, 0);
566
- usleep_range(80000, 100000);
567
- ret = gpio_get_value(120);
568
- printk("edp_reset gpio value : %d\n",ret);
569
-// gpio_direction_output(120, 1);
570
- gpio_set_value(120,1);
571
- usleep_range(80000, 100000);
572
- ret = gpio_get_value(120);
573
- printk("edp_reset gpio value : %d\n",ret);
574
-#endif
575
- //enable = 1;
576
- //LED_SET(11);
577
- return 0;
293
+// int ret,reset_pin;
294
+ printk("nk_io resume !!!!\n");
295
+ return 0;
578296 }
579
-
580
-static const struct of_device_id nk_io_control_of_match[] = {
581
- { .compatible = "nk_io_control", },
582
- {},
297
+
298
+
299
+static int ndj_gpio_remove(struct platform_device *pdev)
300
+{
301
+// class_unregister(&ndj_io_class);
302
+ return 0;
303
+}
304
+
305
+
306
+static const struct of_device_id ndj_gpio_of_match[] = {
307
+ { .compatible = "nk_io_control" },
308
+ { }
583309 };
584
-MODULE_DEVICE_TABLE(of, nk_io_control_of_match);
585
-
586
-static struct platform_driver nk_io_control_driver = {
587
- .probe = nk_io_control_probe,
588
- .remove = nk_io_control_remove,
589
- .resume = nk_io_control_resume,
590
- .suspend = nk_io_control_suspend,
591
- .driver = {
592
- .name = "nk_io_control",
593
- .owner = THIS_MODULE,
594
- .of_match_table = of_match_ptr(nk_io_control_of_match),
595
- },
310
+
311
+static struct platform_driver ndj_gpio_driver = {
312
+ .probe = ndj_gpio_probe,
313
+ .remove = ndj_gpio_remove,
314
+ .resume = ndj_gpio_resume,
315
+ .suspend = ndj_gpio_suspend,
316
+ .driver = {
317
+ .name = "nk_io_control",
318
+ .of_match_table = of_match_ptr(ndj_gpio_of_match),
319
+ },
596320 };
597
-
598
-static int __init nk_io_control_init(void)
599
-{
600
- platform_driver_register(&nk_io_control_driver);
601
- return 0;
602
-}
603
-
604
-static void __exit nk_io_control_exit(void)
605
-{
606
- platform_driver_unregister(&nk_io_control_driver);
607
-}
608
-
609
-subsys_initcall(nk_io_control_init);
610
-
611
-//late_initcall(nk_io_control_init);
612
-MODULE_DESCRIPTION("nk io Core Driver");
321
+
322
+module_platform_driver(ndj_gpio_driver);
323
+MODULE_LICENSE("GPL");
613324 MODULE_LICENSE("GPL");