.. | .. |
---|
12 | 12 | #include <asm/uaccess.h>
|
---|
13 | 13 | #include <linux/string.h>
|
---|
14 | 14 | #include <linux/uaccess.h>
|
---|
| 15 | +#include <linux/device.h>
|
---|
15 | 16 |
|
---|
16 | 17 | #define GPIO_FUNCTION_OUTPUT 0
|
---|
17 | 18 | #define GPIO_FUNCTION_INPUT 1
|
---|
18 | 19 | #define GPIO_FUNCTION_RESET 3
|
---|
19 | | -
|
---|
| 20 | +#define HIGH "1"
|
---|
| 21 | +#define LOW "0"
|
---|
| 22 | +
|
---|
20 | 23 | static int flash_flag = 0;
|
---|
21 | 24 |
|
---|
22 | 25 | struct ndj_gpio {
|
---|
23 | | - int gpio_num; //gpui num
|
---|
| 26 | + int gpio_num; //gpio num
|
---|
24 | 27 | int action; //gpio flag
|
---|
25 | 28 | int gpio_event; //input only
|
---|
26 | 29 | int send_mode; //input only
|
---|
.. | .. |
---|
31 | 34 |
|
---|
32 | 35 | struct ndj_gpio_data {
|
---|
33 | 36 | struct ndj_gpio ndj_gpio_num[20];
|
---|
34 | | - struct input_dev *input;
|
---|
35 | 37 | struct timer_list mytimer;
|
---|
36 | 38 | int gpio_dts_num;
|
---|
| 39 | + unsigned int gpio_op0;
|
---|
| 40 | + unsigned int gpio_op1;
|
---|
37 | 41 | };
|
---|
38 | | -
|
---|
| 42 | +
|
---|
39 | 43 | static struct ndj_gpio_data *gpio_data = NULL;
|
---|
| 44 | +
|
---|
| 45 | +/* creat sysfs gpio api node*/
|
---|
| 46 | +#if 0
|
---|
| 47 | +static ssize_t gpio_op0_show(struct class *class,struct class_attribute *attr, char *buf)
|
---|
| 48 | +{
|
---|
| 49 | + return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op0));
|
---|
| 50 | +}
|
---|
| 51 | +
|
---|
| 52 | +static ssize_t gpio_op0_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
|
---|
| 53 | +{
|
---|
| 54 | + if(!strncmp(buf, HIGH, strlen(HIGH))) {
|
---|
| 55 | + gpio_set_value(gpio_data->gpio_op0, 1);
|
---|
| 56 | +
|
---|
| 57 | + } else if(!strncmp(buf, LOW, strlen(LOW))) {
|
---|
| 58 | + gpio_set_value(gpio_data->gpio_op0, 0);
|
---|
| 59 | + }
|
---|
| 60 | + return size;
|
---|
| 61 | +}
|
---|
| 62 | +
|
---|
| 63 | +static ssize_t gpio_op1_show(struct class *class,struct class_attribute *attr, char *buf)
|
---|
| 64 | +{
|
---|
| 65 | + return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op1));
|
---|
| 66 | +}
|
---|
| 67 | +
|
---|
| 68 | +static ssize_t gpio_op1_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
|
---|
| 69 | +{
|
---|
| 70 | + if(!strncmp(buf, HIGH, strlen(HIGH))) {
|
---|
| 71 | + gpio_set_value(gpio_data->gpio_op1, 1);
|
---|
| 72 | +
|
---|
| 73 | + } else if(!strncmp(buf, LOW, strlen(LOW))) {
|
---|
| 74 | + gpio_set_value(gpio_data->gpio_op1, 0);
|
---|
| 75 | + }
|
---|
| 76 | + return size;
|
---|
| 77 | +}
|
---|
| 78 | +
|
---|
| 79 | +static CLASS_ATTR_RW(gpio_op0);
|
---|
| 80 | +static CLASS_ATTR_RW(gpio_op1);
|
---|
| 81 | +
|
---|
| 82 | +static struct attribute *ndj_gpio_attrs[] = {
|
---|
| 83 | + &class_attr_gpio_op0.attr,
|
---|
| 84 | + &class_attr_gpio_op1.attr,
|
---|
| 85 | + NULL,
|
---|
| 86 | +};
|
---|
| 87 | +
|
---|
| 88 | +ATTRIBUTE_GROUPS(ndj_gpio);
|
---|
| 89 | +
|
---|
| 90 | +/** Device model classes */
|
---|
| 91 | +struct class ndj_io_class = {
|
---|
| 92 | + .name = "io_control", //sysfs directory
|
---|
| 93 | + .class_groups = ndj_gpio_groups,
|
---|
| 94 | +};
|
---|
| 95 | +
|
---|
| 96 | +#endif
|
---|
40 | 97 | static int event_flag = 0;
|
---|
41 | 98 | static int open_now = 0;
|
---|
42 | 99 | static char* file_name = NULL;
|
---|
.. | .. |
---|
113 | 170 | char gpio_name_num[20];
|
---|
114 | 171 | int gpio_in_cnt = 0;
|
---|
115 | 172 | int cnt =0;
|
---|
116 | | - int lvds_index = 0;
|
---|
117 | | - int gpio0, gpio1, gpio2, gpio3;
|
---|
118 | 173 | int i=0;
|
---|
119 | 174 | enum of_gpio_flags flags;
|
---|
120 | 175 |
|
---|
.. | .. |
---|
130 | 185 | if (gpio_data->gpio_dts_num == 0){
|
---|
131 | 186 | dev_info(&pdev->dev, "no gpio defined\n");
|
---|
132 | 187 | }
|
---|
| 188 | +
|
---|
| 189 | + #if 0
|
---|
| 190 | + /*gpio_op0*/
|
---|
| 191 | + ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
|
---|
| 192 | + if (ret < 0) {
|
---|
| 193 | + printk("%s() Can not read property gpio_op0\n", __func__);
|
---|
| 194 | + return -ENODEV;
|
---|
| 195 | + }
|
---|
| 196 | + gpio_data->gpio_op0 = ret;
|
---|
| 197 | + ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
|
---|
| 198 | + if(ret < 0){
|
---|
| 199 | + printk("%s() gpio_op0 request ERROR\n", __func__);
|
---|
| 200 | + return -ENODEV;
|
---|
| 201 | + }
|
---|
| 202 | +
|
---|
| 203 | + gpio_direction_output(gpio_data->gpio_op0,!gpio_flags);
|
---|
| 204 | +#endif
|
---|
133 | 205 |
|
---|
134 | 206 | /* create node */
|
---|
135 | 207 | root_entry_gpio = proc_mkdir("ndj_gpio", NULL);
|
---|
.. | .. |
---|
161 | 233 |
|
---|
162 | 234 | gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
|
---|
163 | 235 | //gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
|
---|
164 | | - event_flag = gpio_flags;
|
---|
165 | | - of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
|
---|
166 | | - of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
|
---|
| 236 | + //event_flag = gpio_flags;
|
---|
| 237 | + //of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
|
---|
| 238 | + //of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
|
---|
167 | 239 | gpio_in_cnt++;
|
---|
168 | 240 | }
|
---|
169 | 241 | break;
|
---|
.. | .. |
---|
200 | 272 | gpio_cnt++;
|
---|
201 | 273 | }
|
---|
202 | 274 |
|
---|
203 | | - platform_set_drvdata(pdev, gpio_data);
|
---|
| 275 | + platform_set_drvdata(pdev, gpio_data);
|
---|
| 276 | +
|
---|
| 277 | +#if 0
|
---|
| 278 | + ret= class_register(&ndj_io_class);
|
---|
| 279 | + if(ret < 0) {
|
---|
| 280 | + return -EINVAL;
|
---|
| 281 | + }
|
---|
| 282 | +#endif
|
---|
204 | 283 | return 0;
|
---|
205 | 284 | }
|
---|
206 | 285 |
|
---|
.. | .. |
---|
223 | 302 |
|
---|
224 | 303 | static int ndj_gpio_remove(struct platform_device *pdev)
|
---|
225 | 304 | {
|
---|
| 305 | +// class_unregister(&ndj_io_class);
|
---|
226 | 306 | return 0;
|
---|
227 | 307 | }
|
---|
228 | 308 |
|
---|