hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/misc/nkio/nk_io_core.c
....@@ -1,622 +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
-void MODULE_SET(int i)
46
-{
47
- if(i==11){
48
- gpio_direction_output(NKpdata_info->en_4g_gpio, 1);
49
- }else{
50
- gpio_direction_output(NKpdata_info->en_4g_gpio, 0);
51
- }
52
-}
53
-
54
-EXPORT_SYMBOL_GPL(MODULE_SET);
55
-
56
-
57
-void LED_SET(int i)
58
-{
59
- if(i==11){
60
- gpio_direction_output(NKpdata_info->led_gpio, 1);
61
- }else{
62
- gpio_direction_output(NKpdata_info->led_gpio, 0);
63
- }
64
-}
65
-
66
-EXPORT_SYMBOL_GPL(LED_SET);
67
-
68
-
69
-void Audio_SET(int i);
70
-
71
- void Audio_SET(int i)
72
- {
73
- if(i==11){
74
- gpio_direction_output(NKpdata_info->audio_switch_gpio, 1);
75
- printk("Audio_SET ENABLE------andy\n");
76
- }else{
77
- gpio_direction_output(NKpdata_info->audio_switch_gpio, 0);
78
- printk("Audio_SET DISABLE------andy\n");
79
- }
80
- }
81
- EXPORT_SYMBOL_GPL(Audio_SET);
82
-
83
-static int nk_io_control_probe(struct platform_device *pdev)
84
-{
85
- struct device_node *node = pdev->dev.of_node;
86
- struct nk_io_pdata *pdata;
87
- int gpio0, gpio1, gpio2, gpio3, reset_pin, ch342_reset;
88
- int ret;
89
- int lvds_index;
90
- int i=0;
91
- static int lvds_gpio[4] ;
92
-
93
- enum of_gpio_flags flags;
94
-
95
- printk(" #######nk_io_control_probe####### \n");
96
-
97
- pdata = kzalloc(sizeof(struct nk_io_pdata), GFP_KERNEL);
98
- if (pdata == NULL) {
99
- printk("%s failed to allocate driver data\n",__FUNCTION__);
100
- return -ENOMEM;
101
- }
102
- memset(pdata,0,sizeof(struct nk_io_pdata));
103
-
104
- //vcc_5v_io
105
- ret = of_get_named_gpio_flags(node, "vcc_5v_io", 0, &flags);
106
- if (ret < 0) {
107
- printk("%s() Can not read property vcc_5v_io\n", __FUNCTION__);
108
- goto err;
109
- } else {
110
- pdata->vcc_5v_io = ret;
111
- ret = devm_gpio_request(&pdev->dev, pdata->vcc_5v_io, "vcc_5v_io");
112
- if(ret < 0){
113
- printk("%s() devm_gpio_request vcc_5v_io request ERROR\n", __FUNCTION__);
114
- goto err;
115
- }
116
-
117
- ret = gpio_direction_output(pdata->vcc_5v_io,1);
118
- if(ret < 0){
119
- printk("%s() gpio_direction_input vcc_5v_io set ERROR\n", __FUNCTION__);
120
- goto err;
121
- }
122
- }
123
-
124
- //vcc3_io_en_gpio
125
- ret = of_get_named_gpio_flags(node, "vcc3_io_en_gpio", 0, &flags);
126
- if (ret < 0) {
127
- printk("%s() Can not read property tp_enable\n", __FUNCTION__);
128
- goto err;
129
- } else {
130
- pdata->vcc3_io_en_gpio = ret;
131
- ret = devm_gpio_request(&pdev->dev, pdata->vcc3_io_en_gpio, "vcc3_io_en_gpio");
132
- if(ret < 0){
133
- printk("%s() devm_gpio_request vcc3_io_en_gpio request ERROR\n", __FUNCTION__);
134
- goto err;
135
- }
136
-
137
- ret = gpio_direction_output(pdata->vcc3_io_en_gpio,1);
138
- if(ret < 0){
139
- printk("%s() gpio_direction_output vcc3_io_en_gpio set ERROR\n", __FUNCTION__);
140
- goto err;
141
- }
142
- }
143
-
144
- //vcc_12v_io
145
- ret = of_get_named_gpio_flags(node, "vcc_12v_io", 0, &flags);
146
- if (ret < 0) {
147
- printk("%s() Can not read property vcc_12v_io\n", __FUNCTION__);
148
- goto err;
149
- } else {
150
- pdata->vcc_12v_io = ret;
151
- ret = devm_gpio_request(&pdev->dev, pdata->vcc_12v_io, "vcc_12v_io");
152
- if(ret < 0){
153
- printk("%s() devm_gpio_request vcc_12v_io request ERROR\n", __FUNCTION__);
154
- goto err;
155
- }
156
-
157
- ret = gpio_direction_output(pdata->vcc_12v_io,1);
158
- if(ret < 0){
159
- printk("%s() gpio_direction_input vcc_12v_io set ERROR\n", __FUNCTION__);
160
- goto err;
161
- }
162
- }
163
-
164
-
165
-
166
- //hub_host2_5v_gpio
167
- ret = of_get_named_gpio_flags(node, "hub_host2_5v_gpio", 0, &flags);
168
- if (ret < 0) {
169
- printk("%s() Can not read property hub_host2_5v_gpio\n", __FUNCTION__);
170
- goto err;
171
- } else {
172
- pdata->hub_host2_5v_gpio = ret;
173
- gpio_free(ret);
174
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host2_5v_gpio, "hub_host2_5v_gpio");
175
- if (ret < 0){
176
- printk("%s() devm_gpio_request hub_host2_5v_gpio request ERROR\n", __FUNCTION__);
177
- goto err;
178
- }
179
-
180
- ret = gpio_direction_output(pdata->hub_host2_5v_gpio,1);
181
- if(ret < 0){
182
- printk("%s() gpio_direction_input hub_host2_5v_gpio set ERROR\n", __FUNCTION__);
183
- goto err;
184
- }
185
- }
186
-
187
- //usb_en_oc_gpio
188
- ret = of_get_named_gpio_flags(node, "usb_en_oc_gpio", 0, &flags);
189
- if (ret < 0) {
190
- printk("%s() Can not read property usb_en_oc_gpio\n", __FUNCTION__);
191
- goto err;
192
- } else {
193
- pdata->usb_en_oc_gpio = ret;
194
- gpio_free(ret);
195
- ret = devm_gpio_request(&pdev->dev, pdata->usb_en_oc_gpio, "usb_en_oc_gpio");
196
- if (ret < 0){
197
- printk("%s() devm_gpio_request usb_en_oc_gpio request ERROR\n", __FUNCTION__);
198
- goto err;
199
- }
200
-
201
- ret = gpio_direction_output(pdata->usb_en_oc_gpio,1);
202
- if(ret < 0){
203
- printk("%s() gpio_direction_input usb_en_oc_gpio set ERROR\n", __FUNCTION__);
204
- goto err;
205
- }
206
- }
207
-
208
- //hub_host2_5V_rest_gpio
209
- ret = of_get_named_gpio_flags(node, "hub_host2_5V_rest_gpio", 0, &flags);
210
- if (ret < 0) {
211
- printk("%s() Can not read property hub_host2_5V_rest_gpio\n", __FUNCTION__);
212
- goto err;
213
- } else {
214
- pdata->hub_host2_5V_rest_gpio = ret;
215
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host2_5V_rest_gpio, "hub_host2_5V_rest_gpio");
216
- if(ret < 0){
217
- printk("%s() devm_gpio_request hub_host2_5V_rest_gpio request ERROR\n", __FUNCTION__);
218
- goto err;
219
- }
220
-
221
- ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,0);
222
- if(ret < 0){
223
- printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__);
224
- goto err;
225
- }
226
- msleep(800);
227
- ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,1);
228
- if(ret < 0){
229
- printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__);
230
- goto err;
231
- }
232
- }
233
-
234
- //hub_host3_5v_gpio
235
- ret = of_get_named_gpio_flags(node, "hub_host3_5v_gpio", 0, &flags);
236
- if (ret < 0) {
237
- printk("%s() Can not read property hub_host3_5v_gpio\n", __FUNCTION__);
238
- goto err;
239
- } else {
240
- pdata->hub_host3_5v_gpio = ret;
241
- gpio_free(ret);
242
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5v_gpio, "hub_host3_5v_gpio");
243
- if(ret < 0){
244
- printk("%s() devm_gpio_request hub_host3_5v_gpio request ERROR\n", __FUNCTION__);
245
- goto err;
246
- }
247
-
248
- ret = gpio_direction_output(pdata->hub_host3_5v_gpio,1);
249
- if(ret < 0){
250
- printk("%s() gpio_direction_input hub_host3_5v_gpio set ERROR\n", __FUNCTION__);
251
- goto err;
252
- }
253
- }
46
+/* creat sysfs gpio api node*/
25447 #if 0
255
- //hub_host3_5V_rest_gpio
256
- ret = of_get_named_gpio_flags(node, "hub_host3_5V_rest_gpio", 0, &flags);
257
- if (ret < 0) {
258
- printk("%s() Can not read property hub_host3_5V_rest_gpio\n", __FUNCTION__);
259
- goto err;
260
- } else {
261
- pdata->hub_host3_5V_rest_gpio = ret;
262
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5V_rest_gpio, "hub_host3_5V_rest_gpio");
263
- if(ret < 0){
264
- printk("%s() devm_gpio_request hub_host3_5V_rest_gpio request ERROR\n", __FUNCTION__);
265
- goto err;
266
- }
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
+}
26752
268
- ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,0);
269
- if(ret < 0){
270
- printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__);
271
- goto err;
272
- }
273
- msleep(800);
274
- ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,1);
275
- if(ret < 0){
276
- printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__);
277
- goto err;
278
- }
279
- }
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
+
28097 #endif
281
- //wake_4g_gpio
282
- ret = of_get_named_gpio_flags(node, "wake_4g_gpio", 0, &flags);
283
- if (ret < 0) {
284
- printk("%s() Can not read property wake_4g_gpio\n", __FUNCTION__);
285
- } else {
286
- pdata->wake_4g_gpio = ret;
287
-
288
- ret = devm_gpio_request(&pdev->dev, pdata->wake_4g_gpio, "wake_4g_gpio");
289
- if(ret < 0){
290
- printk("%s() devm_gpio_request wake_4g_gpio request ERROR\n", __FUNCTION__);
291
- }
292
- ret = gpio_direction_output(pdata->wake_4g_gpio,0);
293
- if(ret < 0){
294
- printk("%s() gpio_direction_input wake_4g_gpio set ERROR\n", __FUNCTION__);
295
- }
296
- }
297
-
298
-
299
- //reset_4g_gpio
300
- ret = of_get_named_gpio_flags(node, "reset_4g_gpio", 0, &flags);
301
- if (ret < 0) {
302
- printk("%s() Can not read property reset_4g_gpio\n", __FUNCTION__);
303
- } else {
304
- pdata->reset_4g_gpio = ret;
305
-
306
- ret = devm_gpio_request(&pdev->dev, pdata->reset_4g_gpio, "reset_4g_gpio");
307
- if(ret < 0){
308
- printk("%s() devm_gpio_request reset_4g_gpio request ERROR\n", __FUNCTION__);
309
- }
310
- ret = gpio_direction_output(pdata->reset_4g_gpio,0);
311
- if(ret < 0){
312
- printk("%s() gpio_direction_input reset_4g_gpio set ERROR\n", __FUNCTION__);
313
- }
314
- }
315
-
316
- //en_4g_gpio
317
- ret = of_get_named_gpio_flags(node, "en_4g_gpio", 0, &flags);
318
- if (ret < 0) {
319
- printk("%s() Can not read property en_4g_gpio\n", __FUNCTION__);
320
- } else {
321
- pdata->en_4g_gpio = ret;
322
-
323
- ret = devm_gpio_request(&pdev->dev, pdata->en_4g_gpio, "en_4g_gpio");
324
- if(ret < 0){
325
- printk("%s() devm_gpio_request en_4g_gpio request ERROR\n", __FUNCTION__);
326
- }
327
- ret = gpio_direction_output(pdata->en_4g_gpio,1);
328
- if(ret < 0){
329
- printk("%s() gpio_direction_input en_4g_gpio set ERROR\n", __FUNCTION__);
330
- }
331
- }
332
-
333
-
334
- //air_mode_4g_gpio
335
- ret = of_get_named_gpio_flags(node, "air_mode_4g_gpio", 0, &flags);
336
- if (ret < 0) {
337
- printk("%s() Can not read property air_mode_4g_gpio\n", __FUNCTION__);
338
- } else {
339
- pdata->air_mode_4g_gpio = ret;
340
-
341
- ret = devm_gpio_request(&pdev->dev, pdata->air_mode_4g_gpio, "air_mode_4g_gpio");
342
- if(ret < 0){
343
- printk("%s() devm_gpio_request air_mode_4g_gpio request ERROR\n", __FUNCTION__);
344
- }
345
- ret = gpio_direction_output(pdata->air_mode_4g_gpio,0);
346
- if(ret < 0){
347
- printk("%s() gpio_direction_input air_mode_4g_gpio set ERROR\n", __FUNCTION__);
348
- }
349
- }
350
-
351
-
352
-/*
353
- //edp_power_supply_gpio;
354
- ret = of_get_named_gpio_flags(node, "edp_power_supply_gpio", 0, &flags);
355
- if (ret < 0) {
356
- printk("%s() Can not read property edp_power_supply_gpio\n", __FUNCTION__);
357
- } else {
358
- pdata->edp_power_supply_gpio = ret;
359
-
360
- ret = devm_gpio_request(&pdev->dev, pdata->edp_power_supply_gpio, "edp_power_supply_gpio");
361
- if(ret < 0){
362
- printk("%s() devm_gpio_request edp_power_supply_gpio request ERROR\n", __FUNCTION__);
363
- }
364
-
365
- ret = gpio_direction_output(pdata->edp_power_supply_gpio,1);
366
- if(ret < 0){
367
- printk("%s() gpio_direction_input edp_power_supply_gpio set ERROR\n", __FUNCTION__);
368
- }
369
- }
370
-
371
- //edp_enable-gpio;
372
- ret = of_get_named_gpio_flags(node, "edp_enable_gpio", 0, &flags);
373
- if (ret < 0) {
374
- printk("%s() Can not read property edp_enable_gpio\n", __FUNCTION__);
375
- } else {
376
- pdata->edp_enable_gpio = ret;
377
-
378
- ret = devm_gpio_request(&pdev->dev, pdata->edp_enable_gpio, "edp_enable_gpio");
379
- if(ret < 0){
380
- printk("%s() devm_gpio_request edp_enable_gpio request ERROR\n", __FUNCTION__);
381
- }
382
-
383
- ret = gpio_direction_output(pdata->edp_enable_gpio,1);
384
- if(ret < 0){
385
- printk("%s() gpio_direction_input edp_enable_gpio set ERROR\n", __FUNCTION__);
386
- }
387
- }
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
+ }
388184
389
- //ch342_enable-gpio;
390
- ret = of_get_named_gpio_flags(node, "ch342_power", 0, &flags);
391
- if (ret < 0) {
392
- printk("%s() Can not read property ch342_gpio\n", __FUNCTION__);
393
- } else {
394
- pdata->ch342_power = ret;
395
-
396
- ret = devm_gpio_request(&pdev->dev, pdata->ch342_power, "ch342_power");
397
- if(ret < 0){
398
- printk("%s() devm_gpio_request ch342_power request ERROR\n", __FUNCTION__);
399
- }
400
-
401
- ret = gpio_direction_output(pdata->ch342_power,1);
402
- if(ret < 0){
403
- printk("%s() gpio_direction_input ch342_power set ERROR\n", __FUNCTION__);
404
- }
405
- }
406
-*/
407
-
408
- //edp_set_pixel-s
409
- 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);
410188 if (ret < 0) {
411
- printk("%s() Can not read property edp_reset\n", __FUNCTION__);
412
- goto err;
189
+ printk("%s() Can not read property gpio_op0\n", __func__);
190
+ return -ENODEV;
413191 }
414
-
415
- reset_pin = ret;
416
-
417
-// enable lvds
418
- ret = of_get_named_gpio_flags(node, "edp_gpio0", 0, &flags);
419
- if (ret < 0) {
420
- printk("%s() Can not read property edp_gpio0\n", __FUNCTION__);
421
- goto err;
422
- }
423
- gpio0 = ret;
424
-
425
-
426
-
427
- ret = of_get_named_gpio_flags(node, "edp_gpio1", 0, &flags);
428
- if (ret < 0) {
429
- printk("%s() Can not read property edp_gpio1\n", __FUNCTION__);
430
- goto err;
431
- }
432
-
433
- gpio1 = ret;
434
-
435
- ret = of_get_named_gpio_flags(node, "edp_gpio2", 0, &flags);
436
- if (ret < 0) {
437
- printk("%s() Can not read property edp_gpio2\n", __FUNCTION__);
438
- goto err;
439
- }
440
-
441
- gpio2 = ret;
442
-
443
- ret = of_get_named_gpio_flags(node, "edp_gpio3", 0, &flags);
444
- if (ret < 0) {
445
- printk("%s() Can not read property edp_gpio3\n", __FUNCTION__);
446
- goto err;
447
- }
448
-
449
- gpio3 = ret;
450
-
451
-
452
- 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");
453194 if(ret < 0){
454
- printk("%s() devm_gpio_request edp_reset request ERROR\n", __FUNCTION__);
455
- goto err;
456
- }
457
-
458
-
459
- ret = devm_gpio_request(&pdev->dev, gpio0, "edp_gpio0");
460
- if(ret < 0){
461
- printk("%s() devm_gpio_request edp_gpio0 request ERROR\n", __FUNCTION__);
462
- goto err;
463
- }
464
-
465
- ret = devm_gpio_request(&pdev->dev, gpio1, "edp_gpio1");
466
- if(ret < 0){
467
- printk("%s() devm_gpio_request edp_gpio1 request ERROR\n", __FUNCTION__);
468
- goto err;
469
- }
470
-
471
- ret = devm_gpio_request(&pdev->dev, gpio2, "edp_gpio2");
472
- if(ret < 0){
473
- printk("%s() devm_gpio_request edp_gpio2 request ERROR\n", __FUNCTION__);
474
- goto err;
475
- }
476
-
477
- ret = devm_gpio_request(&pdev->dev, gpio3, "edp_gpio3");
478
- if(ret < 0){
479
- printk("%s() devm_gpio_request edp_gpio3 request ERROR\n", __FUNCTION__);
480
- goto err;
195
+ printk("%s() gpio_op0 request ERROR\n", __func__);
196
+ return -ENODEV;
481197 }
482198
483
- ret = of_property_read_u32(node, "nodka_lvds", &lvds_index);
484
- if (ret < 0){
485
- printk("%s() Can not read property nodka_lvds\n", __FUNCTION__);
486
- }
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);
487272
488
- printk("nodka_lvds_index = %d\n",lvds_index);
489
-
490
- while ( i < 4 ){
491
- if ( lvds_index > 0)
492
- lvds_gpio[i] = lvds_index%2;
493
- else
494
- lvds_gpio[i] = 0;
495
- printk("lvds_gpio[%d]=%d\n",i,lvds_gpio[i]);
496
- lvds_index = lvds_index/2;
497
- i++;
498
- }
499
-
500
- gpio_direction_output(reset_pin, 0);
501
- usleep_range(80000, 100000);
502
- gpio_direction_output(reset_pin, 1);
503
- usleep_range(80000, 100000);
504
-
505
- gpio_direction_output(gpio0, lvds_gpio[0]);
506
- gpio_direction_output(gpio1, lvds_gpio[1]);
507
- gpio_direction_output(gpio2, lvds_gpio[2]);
508
- gpio_direction_output(gpio3, lvds_gpio[3]);
509
-
510
- printk(" #######nk_io_control_probe end####### \n");
511
- return 0;
512
-
513
-err:
514
- kfree(pdata);
515
- return ret;
516
-}
517
-
518
-
519
-static int nk_io_control_remove(struct platform_device *pdev)
520
-{
521
- if(NKpdata_info)
522
- kfree(NKpdata_info);
523
- 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;
524280 }
525
-
526
-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)
527284 {
528
- int ret;
529
- struct nk_io_pdata *pdata;
530
- printk("nk_suspend !!!!\n");
531
-#if 0
532
- ret = gpio_get_value(8);
533
- printk("vcc12v gpio value : %d\n",ret);
534
- usleep_range(80000, 100000);
535
- gpio_set_value(8,0);
536
- ret = gpio_get_value(8);
537
- printk("vcc12v gpio value : %d\n",ret);
538
-#endif
539
-#if 0
540
- ret = gpio_get_value(21);
541
- printk("hub_host3_5v_gpio value : %d\n",ret);
542
- usleep_range(80000, 100000);
543
- gpio_set_value(21,0);
544
- ret = gpio_get_value(21);
545
- printk("hub_host3_5v_gpio value : %d\n",ret);
546
- //enable = 0;
547
- //LED_SET(0);
548
-#endif
549
- return 0;
285
+// int ret;
286
+// struct nk_io_pdata *pdata;
287
+ printk("nk_suspend !!!!\n");
288
+ return 0;
550289 }
551
-
552
-static int nk_io_control_resume(struct platform_device *pdev)
290
+
291
+static int ndj_gpio_resume(struct platform_device *pdev)
553292 {
554
- int ret,reset_pin;
555
- printk("nk_io resume !!!!\n");
556
- ret = gpio_get_value(120);
557
-
558
-#if 0
559
- gpio_set_value(8,1);
560
- ret = gpio_get_value(8);
561
- printk("vcc12v gpio value : %d\n",ret);
562
-#endif
563
-#if 0
564
- gpio_set_value(15,1);
565
- ret = gpio_get_value(15);
566
- printk("edp_en gpio value : %d\n",ret);
567
- gpio_set_value(21,1);
568
- ret = gpio_get_value(21);
569
- printk("hub_host3_5v_gpio value : %d\n",ret);
570
-#endif
571
-#if 0
572
- usleep_range(80000, 100000);
573
- gpio_set_value(120,0);
574
-// gpio_direction_output(120, 0);
575
- usleep_range(80000, 100000);
576
- ret = gpio_get_value(120);
577
- printk("edp_reset gpio value : %d\n",ret);
578
-// gpio_direction_output(120, 1);
579
- gpio_set_value(120,1);
580
- usleep_range(80000, 100000);
581
- ret = gpio_get_value(120);
582
- printk("edp_reset gpio value : %d\n",ret);
583
-#endif
584
- //enable = 1;
585
- //LED_SET(11);
586
- return 0;
293
+// int ret,reset_pin;
294
+ printk("nk_io resume !!!!\n");
295
+ return 0;
587296 }
588
-
589
-static const struct of_device_id nk_io_control_of_match[] = {
590
- { .compatible = "nk_io_control", },
591
- {},
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
+ { }
592309 };
593
-MODULE_DEVICE_TABLE(of, nk_io_control_of_match);
594
-
595
-static struct platform_driver nk_io_control_driver = {
596
- .probe = nk_io_control_probe,
597
- .remove = nk_io_control_remove,
598
- .resume = nk_io_control_resume,
599
- .suspend = nk_io_control_suspend,
600
- .driver = {
601
- .name = "nk_io_control",
602
- .owner = THIS_MODULE,
603
- .of_match_table = of_match_ptr(nk_io_control_of_match),
604
- },
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
+ },
605320 };
606
-
607
-static int __init nk_io_control_init(void)
608
-{
609
- platform_driver_register(&nk_io_control_driver);
610
- return 0;
611
-}
612
-
613
-static void __exit nk_io_control_exit(void)
614
-{
615
- platform_driver_unregister(&nk_io_control_driver);
616
-}
617
-
618
-subsys_initcall(nk_io_control_init);
619
-
620
-//late_initcall(nk_io_control_init);
621
-MODULE_DESCRIPTION("nk io Core Driver");
321
+
322
+module_platform_driver(ndj_gpio_driver);
323
+MODULE_LICENSE("GPL");
622324 MODULE_LICENSE("GPL");