hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/drivers/misc/nkio/nk_io_core.c
....@@ -1,584 +1,328 @@
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
+
17
+#define GPIO_FUNCTION_OUTPUT 0
18
+#define GPIO_FUNCTION_INPUT 1
19
+#define GPIO_FUNCTION_RESET 3
20
+#define HIGH "1"
21
+#define LOW "0"
3022
31
-/* Debug */
32
-#if 1
33
-#define DBG(x...) printk(x)
34
-#else
35
-#define DBG(x...) do { } while (0)
36
-#endif
23
+static int flash_flag = 0;
24
+
25
+struct ndj_gpio {
26
+ int gpio_num; //gpio num
27
+ int action; //gpio flag
28
+ int gpio_event; //input only
29
+ int send_mode; //input only
30
+ int gpio_function; //gpio function,i/o
31
+ int gpio_ctrl;
32
+ char *gpio_name;
33
+};
34
+
35
+struct ndj_gpio_data {
36
+ struct ndj_gpio ndj_gpio_num[20];
37
+ struct timer_list mytimer;
38
+ int gpio_dts_num;
39
+ unsigned int gpio_op0;
40
+ unsigned int gpio_op1;
41
+};
3742
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;
43
+static struct ndj_gpio_data *gpio_data = NULL;
4344
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
- //usb_en_oc_gpio
143
- ret = of_get_named_gpio_flags(node, "usb_en_oc_gpio", 0, &flags);
144
- if (ret < 0) {
145
- printk("%s() Can not read property usb_en_oc_gpio\n", __FUNCTION__);
146
- goto err;
147
- } else {
148
- pdata->usb_en_oc_gpio = ret;
149
- gpio_free(ret);
150
- ret = devm_gpio_request(&pdev->dev, pdata->usb_en_oc_gpio, "usb_en_oc_gpio");
151
- if (ret < 0){
152
- printk("%s() devm_gpio_request usb_en_oc_gpio request ERROR\n", __FUNCTION__);
153
- goto err;
154
- }
155
-
156
- ret = gpio_direction_output(pdata->usb_en_oc_gpio,1);
157
- if(ret < 0){
158
- printk("%s() gpio_direction_input usb_en_oc_gpio set ERROR\n", __FUNCTION__);
159
- goto err;
160
- }
161
- }
162
-
163
- //hub_host2_5V_rest_gpio
164
- ret = of_get_named_gpio_flags(node, "hub_host2_5V_rest_gpio", 0, &flags);
165
- if (ret < 0) {
166
- printk("%s() Can not read property hub_host2_5V_rest_gpio\n", __FUNCTION__);
167
- goto err;
168
- } else {
169
- pdata->hub_host2_5V_rest_gpio = ret;
170
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host2_5V_rest_gpio, "hub_host2_5V_rest_gpio");
171
- if(ret < 0){
172
- printk("%s() devm_gpio_request hub_host2_5V_rest_gpio request ERROR\n", __FUNCTION__);
173
- goto err;
174
- }
175
-
176
- ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,0);
177
- if(ret < 0){
178
- printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__);
179
- goto err;
180
- }
181
- msleep(800);
182
- ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,1);
183
- if(ret < 0){
184
- printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__);
185
- goto err;
186
- }
187
- }
188
-
189
- //hub_host3_5v_gpio
190
- ret = of_get_named_gpio_flags(node, "hub_host3_5v_gpio", 0, &flags);
191
- if (ret < 0) {
192
- printk("%s() Can not read property hub_host3_5v_gpio\n", __FUNCTION__);
193
- goto err;
194
- } else {
195
- pdata->hub_host3_5v_gpio = ret;
196
- gpio_free(ret);
197
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5v_gpio, "hub_host3_5v_gpio");
198
- if(ret < 0){
199
- printk("%s() devm_gpio_request hub_host3_5v_gpio request ERROR\n", __FUNCTION__);
200
- goto err;
201
- }
202
-
203
- ret = gpio_direction_output(pdata->hub_host3_5v_gpio,1);
204
- if(ret < 0){
205
- printk("%s() gpio_direction_input hub_host3_5v_gpio set ERROR\n", __FUNCTION__);
206
- goto err;
207
- }
208
- }
45
+/* creat sysfs gpio api node*/
20946 #if 0
210
- //hub_host3_5V_rest_gpio
211
- ret = of_get_named_gpio_flags(node, "hub_host3_5V_rest_gpio", 0, &flags);
212
- if (ret < 0) {
213
- printk("%s() Can not read property hub_host3_5V_rest_gpio\n", __FUNCTION__);
214
- goto err;
215
- } else {
216
- pdata->hub_host3_5V_rest_gpio = ret;
217
- ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5V_rest_gpio, "hub_host3_5V_rest_gpio");
218
- if(ret < 0){
219
- printk("%s() devm_gpio_request hub_host3_5V_rest_gpio request ERROR\n", __FUNCTION__);
220
- goto err;
221
- }
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
+}
22251
223
- ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,0);
224
- if(ret < 0){
225
- printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__);
226
- goto err;
227
- }
228
- msleep(800);
229
- ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,1);
230
- if(ret < 0){
231
- printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__);
232
- goto err;
233
- }
234
- }
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
+
23596 #endif
236
- //wake_4g_gpio
237
- ret = of_get_named_gpio_flags(node, "wake_4g_gpio", 0, &flags);
238
- if (ret < 0) {
239
- printk("%s() Can not read property wake_4g_gpio\n", __FUNCTION__);
240
- } else {
241
- pdata->wake_4g_gpio = ret;
242
-
243
- ret = devm_gpio_request(&pdev->dev, pdata->wake_4g_gpio, "wake_4g_gpio");
244
- if(ret < 0){
245
- printk("%s() devm_gpio_request wake_4g_gpio request ERROR\n", __FUNCTION__);
246
- }
247
- ret = gpio_direction_output(pdata->wake_4g_gpio,0);
248
- if(ret < 0){
249
- printk("%s() gpio_direction_input wake_4g_gpio set ERROR\n", __FUNCTION__);
250
- }
251
- }
252
-
253
-
254
- //reset_4g_gpio
255
- ret = of_get_named_gpio_flags(node, "reset_4g_gpio", 0, &flags);
256
- if (ret < 0) {
257
- printk("%s() Can not read property reset_4g_gpio\n", __FUNCTION__);
258
- } else {
259
- pdata->reset_4g_gpio = ret;
260
-
261
- ret = devm_gpio_request(&pdev->dev, pdata->reset_4g_gpio, "reset_4g_gpio");
262
- if(ret < 0){
263
- printk("%s() devm_gpio_request reset_4g_gpio request ERROR\n", __FUNCTION__);
264
- }
265
- ret = gpio_direction_output(pdata->reset_4g_gpio,0);
266
- if(ret < 0){
267
- printk("%s() gpio_direction_input reset_4g_gpio set ERROR\n", __FUNCTION__);
268
- goto err;
269
- }
270
- msleep(800);
271
- ret = gpio_direction_output(pdata->reset_4g_gpio,1);
272
- if(ret < 0){
273
- printk("%s() gpio_direction_input reset_4g_gpio set ERROR\n", __FUNCTION__);
274
-
275
- }
276
- }
277
-
278
- //en_4g_gpio
279
- ret = of_get_named_gpio_flags(node, "en_4g_gpio", 0, &flags);
280
- if (ret < 0) {
281
- printk("%s() Can not read property en_4g_gpio\n", __FUNCTION__);
282
- } else {
283
- pdata->en_4g_gpio = ret;
284
-
285
- ret = devm_gpio_request(&pdev->dev, pdata->en_4g_gpio, "en_4g_gpio");
286
- if(ret < 0){
287
- printk("%s() devm_gpio_request en_4g_gpio request ERROR\n", __FUNCTION__);
288
- }
289
- ret = gpio_direction_output(pdata->en_4g_gpio,1);
290
- if(ret < 0){
291
- printk("%s() gpio_direction_output en_4g_gpio set ERROR\n", __FUNCTION__);
292
- }
293
- }
294
-
295
-
296
- //air_mode_4g_gpio
297
- ret = of_get_named_gpio_flags(node, "air_mode_4g_gpio", 0, &flags);
298
- if (ret < 0) {
299
- printk("%s() Can not read property air_mode_4g_gpio\n", __FUNCTION__);
300
- } else {
301
- pdata->air_mode_4g_gpio = ret;
302
-
303
- ret = devm_gpio_request(&pdev->dev, pdata->air_mode_4g_gpio, "air_mode_4g_gpio");
304
- if(ret < 0){
305
- printk("%s() devm_gpio_request air_mode_4g_gpio request ERROR\n", __FUNCTION__);
306
- }
307
- ret = gpio_direction_output(pdata->air_mode_4g_gpio,0);
308
- if(ret < 0){
309
- printk("%s() gpio_direction_input air_mode_4g_gpio set ERROR\n", __FUNCTION__);
310
- }
311
- }
312
-
313
-
314
-/*
315
- //edp_power_supply_gpio;
316
- ret = of_get_named_gpio_flags(node, "edp_power_supply_gpio", 0, &flags);
317
- if (ret < 0) {
318
- printk("%s() Can not read property edp_power_supply_gpio\n", __FUNCTION__);
319
- } else {
320
- pdata->edp_power_supply_gpio = ret;
321
-
322
- ret = devm_gpio_request(&pdev->dev, pdata->edp_power_supply_gpio, "edp_power_supply_gpio");
323
- if(ret < 0){
324
- printk("%s() devm_gpio_request edp_power_supply_gpio request ERROR\n", __FUNCTION__);
325
- }
326
-
327
- ret = gpio_direction_output(pdata->edp_power_supply_gpio,1);
328
- if(ret < 0){
329
- printk("%s() gpio_direction_input edp_power_supply_gpio set ERROR\n", __FUNCTION__);
330
- }
331
- }
332
-
333
- //edp_enable-gpio;
334
- ret = of_get_named_gpio_flags(node, "edp_enable_gpio", 0, &flags);
335
- if (ret < 0) {
336
- printk("%s() Can not read property edp_enable_gpio\n", __FUNCTION__);
337
- } else {
338
- pdata->edp_enable_gpio = ret;
339
-
340
- ret = devm_gpio_request(&pdev->dev, pdata->edp_enable_gpio, "edp_enable_gpio");
341
- if(ret < 0){
342
- printk("%s() devm_gpio_request edp_enable_gpio request ERROR\n", __FUNCTION__);
343
- }
344
-
345
- ret = gpio_direction_output(pdata->edp_enable_gpio,1);
346
- if(ret < 0){
347
- printk("%s() gpio_direction_input edp_enable_gpio set ERROR\n", __FUNCTION__);
348
- }
349
- }
97
+static int event_flag = 0;
98
+static int open_now = 0;
99
+static char* file_name = NULL;
100
+
101
+static int gpio_open(struct inode *inode, struct file *file)
102
+{
103
+ struct dentry* dent = file->f_path.dentry;
104
+ int i = 0;
105
+
106
+ file_name = (char*)(dent->d_name.name);
107
+
108
+ for (i = 0; i < gpio_data->gpio_dts_num; i++){
109
+ if(!strcmp(file_name,gpio_data->ndj_gpio_num[i].gpio_name)){
110
+ open_now = i;
111
+ }
112
+ }
113
+ return 0;
114
+}
115
+
116
+static ssize_t gpio_write(struct file *file, const char *buffer,size_t count, loff_t *data)
117
+{
118
+ char buf[2]={0};
119
+ char s1[]="1";
120
+
121
+ if(copy_from_user(&buf[0],buffer,1)){
122
+ printk("failed to copy data to kernel space\n");
123
+ return -EFAULT;
124
+ }
125
+
126
+ if(!strcmp(buf,s1)){
127
+ gpio_direction_output(gpio_data->ndj_gpio_num[open_now].gpio_num,1);
128
+ //printk("%s write 1 succeed\n",gpio_data->ndj_gpio_num[open_now].gpio_name);
129
+ }else{
130
+ gpio_direction_output(gpio_data->ndj_gpio_num[open_now].gpio_num,0);
131
+ //printk("%s write 0 succeed\n",gpio_data->ndj_gpio_num[open_now].gpio_name);
132
+ }
133
+ return count;
134
+}
135
+
136
+
137
+static ssize_t gpio_read(struct file *file, char __user * buffer, size_t count, loff_t *data)
138
+{
139
+ int gpio_val = 0;
140
+ int len = 0;
141
+ char s[10] = {0};
142
+
143
+ if(*data)
144
+ return 0;
145
+
146
+ gpio_val = gpio_get_value(gpio_data->ndj_gpio_num[open_now].gpio_num);
147
+ //printk("get %s value %d\n",gpio_data->ndj_gpio_num[open_now].gpio_name,gpio_val);
148
+
149
+ len = sprintf(s+len, "%d\n",gpio_val);
150
+
151
+ return simple_read_from_buffer(buffer, count, data, s, 2);
152
+}
153
+
154
+
155
+static const struct file_operations gpio_ops = {
156
+ .owner = THIS_MODULE,
157
+ .open = gpio_open,
158
+ .write = gpio_write,
159
+ .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
+ struct device *dev = &pdev->dev;
166
+ static struct proc_dir_entry *root_entry_gpio;
167
+ enum of_gpio_flags gpio_flags;
168
+ int ret = 0;
169
+ int gpio_cnt = 0;
170
+ char gpio_name_num[20];
171
+ int gpio_in_cnt = 0;
172
+ int cnt =0;
173
+ int i=0;
174
+ enum of_gpio_flags flags;
175
+
176
+ gpio_data = devm_kzalloc(&pdev->dev, sizeof(struct ndj_gpio_data),GFP_KERNEL);
177
+ if (!gpio_data) {
178
+ dev_err(&pdev->dev, "failed to allocate memory\n");
179
+ return -ENOMEM;
180
+ }
181
+
182
+ gpio_data->gpio_dts_num = of_get_child_count(np);
183
+// printk("ndj_gpio prepare build %d gpio\n",gpio_data->gpio_dts_num);
184
+
185
+ if (gpio_data->gpio_dts_num == 0){
186
+ dev_info(&pdev->dev, "no gpio defined\n");
187
+ }
350188
351
- //ch342_enable-gpio;
352
- ret = of_get_named_gpio_flags(node, "ch342_power", 0, &flags);
353
- if (ret < 0) {
354
- printk("%s() Can not read property ch342_gpio\n", __FUNCTION__);
355
- } else {
356
- pdata->ch342_power = ret;
357
-
358
- ret = devm_gpio_request(&pdev->dev, pdata->ch342_power, "ch342_power");
359
- if(ret < 0){
360
- printk("%s() devm_gpio_request ch342_power request ERROR\n", __FUNCTION__);
361
- }
362
-
363
- ret = gpio_direction_output(pdata->ch342_power,1);
364
- if(ret < 0){
365
- printk("%s() gpio_direction_input ch342_power set ERROR\n", __FUNCTION__);
366
- }
367
- }
368
-*/
369
-
370
- //edp_set_pixel-s
371
- ret = of_get_named_gpio_flags(node, "edp_reset", 0, &flags);
189
+ #if 0
190
+ /*gpio_op0*/
191
+ ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
372192 if (ret < 0) {
373
- printk("%s() Can not read property edp_reset\n", __FUNCTION__);
374
- goto err;
193
+ printk("%s() Can not read property gpio_op0\n", __func__);
194
+ return -ENODEV;
375195 }
376
-
377
- reset_pin = ret;
378
-
379
-// enable lvds
380
- ret = of_get_named_gpio_flags(node, "edp_gpio0", 0, &flags);
381
- if (ret < 0) {
382
- printk("%s() Can not read property edp_gpio0\n", __FUNCTION__);
383
- goto err;
384
- }
385
- gpio0 = ret;
386
-
387
-
388
-
389
- ret = of_get_named_gpio_flags(node, "edp_gpio1", 0, &flags);
390
- if (ret < 0) {
391
- printk("%s() Can not read property edp_gpio1\n", __FUNCTION__);
392
- goto err;
393
- }
394
-
395
- gpio1 = ret;
396
-
397
- ret = of_get_named_gpio_flags(node, "edp_gpio2", 0, &flags);
398
- if (ret < 0) {
399
- printk("%s() Can not read property edp_gpio2\n", __FUNCTION__);
400
- goto err;
401
- }
402
-
403
- gpio2 = ret;
404
-
405
- ret = of_get_named_gpio_flags(node, "edp_gpio3", 0, &flags);
406
- if (ret < 0) {
407
- printk("%s() Can not read property edp_gpio3\n", __FUNCTION__);
408
- goto err;
409
- }
410
-
411
- gpio3 = ret;
412
-
413
-
414
- ret = devm_gpio_request(&pdev->dev, reset_pin, "edp_reset");
196
+ gpio_data->gpio_op0 = ret;
197
+ ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
415198 if(ret < 0){
416
- printk("%s() devm_gpio_request edp_reset request ERROR\n", __FUNCTION__);
417
- goto err;
418
- }
419
-
420
-
421
- ret = devm_gpio_request(&pdev->dev, gpio0, "edp_gpio0");
422
- if(ret < 0){
423
- printk("%s() devm_gpio_request edp_gpio0 request ERROR\n", __FUNCTION__);
424
- goto err;
425
- }
426
-
427
- ret = devm_gpio_request(&pdev->dev, gpio1, "edp_gpio1");
428
- if(ret < 0){
429
- printk("%s() devm_gpio_request edp_gpio1 request ERROR\n", __FUNCTION__);
430
- goto err;
431
- }
432
-
433
- ret = devm_gpio_request(&pdev->dev, gpio2, "edp_gpio2");
434
- if(ret < 0){
435
- printk("%s() devm_gpio_request edp_gpio2 request ERROR\n", __FUNCTION__);
436
- goto err;
437
- }
438
-
439
- ret = devm_gpio_request(&pdev->dev, gpio3, "edp_gpio3");
440
- if(ret < 0){
441
- printk("%s() devm_gpio_request edp_gpio3 request ERROR\n", __FUNCTION__);
442
- goto err;
199
+ printk("%s() gpio_op0 request ERROR\n", __func__);
200
+ return -ENODEV;
443201 }
444202
445
- ret = of_property_read_u32(node, "nodka_lvds", &lvds_index);
446
- if (ret < 0){
447
- printk("%s() Can not read property nodka_lvds\n", __FUNCTION__);
448
- }
203
+ gpio_direction_output(gpio_data->gpio_op0,!gpio_flags);
204
+#endif
205
+
206
+ /* create node */
207
+ root_entry_gpio = proc_mkdir("ndj_gpio", NULL);
208
+
209
+ for_each_child_of_node(np, child_np)
210
+ {
211
+ /* parse dts */
212
+ gpio_data->ndj_gpio_num[gpio_cnt].gpio_num = of_get_named_gpio_flags(child_np, "gpio_num", 0, &gpio_flags);
213
+ if (!gpio_is_valid(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num)){
214
+ return -1;
215
+ }
216
+
217
+ gpio_data->ndj_gpio_num[gpio_cnt].gpio_name = (char*)child_np -> name;
218
+ gpio_data->ndj_gpio_num[gpio_cnt].action = gpio_flags;
219
+ gpio_data->ndj_gpio_num[gpio_cnt].gpio_ctrl = gpio_cnt;
220
+ of_property_read_u32(child_np, "gpio_function", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_function));
221
+
222
+// printk("ndj_gpio request %s\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
223
+
224
+
225
+ switch(gpio_data->ndj_gpio_num[gpio_cnt].gpio_function) {
226
+ case GPIO_FUNCTION_INPUT : /* init input gpio */
227
+ ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
228
+ if (ret < 0)
229
+ {
230
+ printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
231
+ }else{
232
+ // printk("success request gpio %d in\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
233
+
234
+ gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
235
+ //gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
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));
239
+ gpio_in_cnt++;
240
+ }
241
+ break;
242
+
243
+ case GPIO_FUNCTION_OUTPUT : /* init output gpio */
244
+ ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
245
+ if (ret < 0){
246
+ printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
247
+ //return ret;
248
+ }else{
249
+ gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
250
+ //printk("success request gpio%d out\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
251
+ }
252
+ break;
253
+
254
+ case GPIO_FUNCTION_RESET :
255
+ ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name);
256
+ if (ret < 0){
257
+ printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
258
+ //return ret;
259
+ }else{
260
+ gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,gpio_data->ndj_gpio_num[gpio_cnt].action);
261
+ //printk("success request gpio%d reset\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
262
+ mdelay(200);
263
+ gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
264
+
265
+// gpio_cnt++;
266
+ }
267
+ break;
268
+ }
269
+
270
+ sprintf(gpio_name_num,gpio_data->ndj_gpio_num[gpio_cnt].gpio_name,gpio_cnt);
271
+ proc_create(gpio_name_num, 0666 , root_entry_gpio , &gpio_ops);
272
+ gpio_cnt++;
273
+ }
274
+
275
+ platform_set_drvdata(pdev, gpio_data);
449276
450
- printk("nodka_lvds_index = %d\n",lvds_index);
451
-
452
- while ( i < 4 ){
453
- if ( lvds_index > 0)
454
- lvds_gpio[i] = lvds_index%2;
455
- else
456
- lvds_gpio[i] = 0;
457
- printk("lvds_gpio[%d]=%d\n",i,lvds_gpio[i]);
458
- lvds_index = lvds_index/2;
459
- i++;
460
- }
461
-
462
- gpio_direction_output(reset_pin, 0);
463
- usleep_range(80000, 100000);
464
- gpio_direction_output(reset_pin, 1);
465
- usleep_range(80000, 100000);
466
-
467
- gpio_direction_output(gpio0, lvds_gpio[0]);
468
- gpio_direction_output(gpio1, lvds_gpio[1]);
469
- gpio_direction_output(gpio2, lvds_gpio[2]);
470
- gpio_direction_output(gpio3, lvds_gpio[3]);
471
-
472
- printk(" #######nk_io_control_probe end####### \n");
473
- return 0;
474
-
475
-err:
476
- kfree(pdata);
477
- return ret;
478
-}
479
-
480
-
481
-static int nk_io_control_remove(struct platform_device *pdev)
482
-{
483
- if(NKpdata_info)
484
- kfree(NKpdata_info);
485
- return 0;
277
+#if 0
278
+ ret= class_register(&ndj_io_class);
279
+ if(ret < 0) {
280
+ return -EINVAL;
281
+ }
282
+#endif
283
+ return 0;
486284 }
487
-
488
-static int nk_io_control_suspend(struct platform_device *pdev, pm_message_t state)
285
+
286
+
287
+static int ndj_gpio_suspend(struct platform_device *pdev, pm_message_t state)
489288 {
490
- int ret;
491
- struct nk_io_pdata *pdata;
492
- printk("nk_suspend !!!!\n");
493
-#if 0
494
- ret = gpio_get_value(8);
495
- printk("vcc12v gpio value : %d\n",ret);
496
- usleep_range(80000, 100000);
497
- gpio_set_value(8,0);
498
- ret = gpio_get_value(8);
499
- printk("vcc12v gpio value : %d\n",ret);
500
-#endif
501
-#if 0
502
- ret = gpio_get_value(21);
503
- printk("hub_host3_5v_gpio value : %d\n",ret);
504
- usleep_range(80000, 100000);
505
- gpio_set_value(21,0);
506
- ret = gpio_get_value(21);
507
- printk("hub_host3_5v_gpio value : %d\n",ret);
508
- //enable = 0;
509
- //LED_SET(0);
510
-#endif
511
- return 0;
289
+ int ret;
290
+ struct nk_io_pdata *pdata;
291
+ printk("nk_suspend !!!!\n");
292
+ return 0;
512293 }
513
-
514
-static int nk_io_control_resume(struct platform_device *pdev)
294
+
295
+static int ndj_gpio_resume(struct platform_device *pdev)
515296 {
516
- int ret,reset_pin;
517
- printk("nk_io resume !!!!\n");
518
- ret = gpio_get_value(120);
519
-
520
-#if 0
521
- gpio_set_value(8,1);
522
- ret = gpio_get_value(8);
523
- printk("vcc12v gpio value : %d\n",ret);
524
-#endif
525
-#if 0
526
- gpio_set_value(15,1);
527
- ret = gpio_get_value(15);
528
- printk("edp_en gpio value : %d\n",ret);
529
- gpio_set_value(21,1);
530
- ret = gpio_get_value(21);
531
- printk("hub_host3_5v_gpio value : %d\n",ret);
532
-#endif
533
-#if 0
534
- usleep_range(80000, 100000);
535
- gpio_set_value(120,0);
536
-// gpio_direction_output(120, 0);
537
- usleep_range(80000, 100000);
538
- ret = gpio_get_value(120);
539
- printk("edp_reset gpio value : %d\n",ret);
540
-// gpio_direction_output(120, 1);
541
- gpio_set_value(120,1);
542
- usleep_range(80000, 100000);
543
- ret = gpio_get_value(120);
544
- printk("edp_reset gpio value : %d\n",ret);
545
-#endif
546
- //enable = 1;
547
- //LED_SET(11);
548
- return 0;
297
+ int ret,reset_pin;
298
+ printk("nk_io resume !!!!\n");
299
+ return 0;
549300 }
550
-
551
-static const struct of_device_id nk_io_control_of_match[] = {
552
- { .compatible = "nk_io_control", },
553
- {},
301
+
302
+
303
+static int ndj_gpio_remove(struct platform_device *pdev)
304
+{
305
+// class_unregister(&ndj_io_class);
306
+ return 0;
307
+}
308
+
309
+
310
+static const struct of_device_id ndj_gpio_of_match[] = {
311
+ { .compatible = "nk_io_control" },
312
+ { }
554313 };
555
-MODULE_DEVICE_TABLE(of, nk_io_control_of_match);
556
-
557
-static struct platform_driver nk_io_control_driver = {
558
- .probe = nk_io_control_probe,
559
- .remove = nk_io_control_remove,
560
- .resume = nk_io_control_resume,
561
- .suspend = nk_io_control_suspend,
562
- .driver = {
563
- .name = "nk_io_control",
564
- .owner = THIS_MODULE,
565
- .of_match_table = of_match_ptr(nk_io_control_of_match),
566
- },
314
+
315
+static struct platform_driver ndj_gpio_driver = {
316
+ .probe = ndj_gpio_probe,
317
+ .remove = ndj_gpio_remove,
318
+ .resume = ndj_gpio_resume,
319
+ .suspend = ndj_gpio_suspend,
320
+ .driver = {
321
+ .name = "nk_io_control",
322
+ .of_match_table = of_match_ptr(ndj_gpio_of_match),
323
+ },
567324 };
568
-
569
-static int __init nk_io_control_init(void)
570
-{
571
- platform_driver_register(&nk_io_control_driver);
572
- return 0;
573
-}
574
-
575
-static void __exit nk_io_control_exit(void)
576
-{
577
- platform_driver_unregister(&nk_io_control_driver);
578
-}
579
-
580
-subsys_initcall(nk_io_control_init);
581
-
582
-//late_initcall(nk_io_control_init);
583
-MODULE_DESCRIPTION("nk io Core Driver");
325
+
326
+module_platform_driver(ndj_gpio_driver);
584327 MODULE_LICENSE("GPL");
328
+MODULE_LICENSE("GPL");