| .. | .. |
|---|
| 12 | 12 | #include <asm/uaccess.h>
|
|---|
| 13 | 13 | #include <linux/string.h>
|
|---|
| 14 | 14 | #include <linux/uaccess.h>
|
|---|
| 15 | +#include <linux/device.h>
|
|---|
| 16 | +#include <linux/proc_fs.h>
|
|---|
| 15 | 17 |
|
|---|
| 16 | 18 | #define GPIO_FUNCTION_OUTPUT 0
|
|---|
| 17 | 19 | #define GPIO_FUNCTION_INPUT 1
|
|---|
| 18 | 20 | #define GPIO_FUNCTION_RESET 3
|
|---|
| 19 | | -
|
|---|
| 20 | | -static int flash_flag = 0;
|
|---|
| 21 | +#define HIGH "1"
|
|---|
| 22 | +#define LOW "0"
|
|---|
| 23 | +
|
|---|
| 24 | +//static int flash_flag = 0;
|
|---|
| 21 | 25 |
|
|---|
| 22 | 26 | struct ndj_gpio {
|
|---|
| 23 | | - int gpio_num; //gpui num
|
|---|
| 27 | + int gpio_num; //gpio num
|
|---|
| 24 | 28 | int action; //gpio flag
|
|---|
| 25 | 29 | int gpio_event; //input only
|
|---|
| 26 | 30 | int send_mode; //input only
|
|---|
| .. | .. |
|---|
| 31 | 35 |
|
|---|
| 32 | 36 | struct ndj_gpio_data {
|
|---|
| 33 | 37 | struct ndj_gpio ndj_gpio_num[20];
|
|---|
| 34 | | - struct input_dev *input;
|
|---|
| 35 | 38 | struct timer_list mytimer;
|
|---|
| 36 | 39 | int gpio_dts_num;
|
|---|
| 40 | + unsigned int gpio_op0;
|
|---|
| 41 | + unsigned int gpio_op1;
|
|---|
| 37 | 42 | };
|
|---|
| 38 | | -
|
|---|
| 43 | +
|
|---|
| 39 | 44 | static struct ndj_gpio_data *gpio_data = NULL;
|
|---|
| 40 | | -static int event_flag = 0;
|
|---|
| 45 | +
|
|---|
| 46 | +/* creat sysfs gpio api node*/
|
|---|
| 47 | +#if 0
|
|---|
| 48 | +static ssize_t gpio_op0_show(struct class *class,struct class_attribute *attr, char *buf)
|
|---|
| 49 | +{
|
|---|
| 50 | + return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op0));
|
|---|
| 51 | +}
|
|---|
| 52 | +
|
|---|
| 53 | +static ssize_t gpio_op0_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
|
|---|
| 54 | +{
|
|---|
| 55 | + if(!strncmp(buf, HIGH, strlen(HIGH))) {
|
|---|
| 56 | + gpio_set_value(gpio_data->gpio_op0, 1);
|
|---|
| 57 | +
|
|---|
| 58 | + } else if(!strncmp(buf, LOW, strlen(LOW))) {
|
|---|
| 59 | + gpio_set_value(gpio_data->gpio_op0, 0);
|
|---|
| 60 | + }
|
|---|
| 61 | + return size;
|
|---|
| 62 | +}
|
|---|
| 63 | +
|
|---|
| 64 | +static ssize_t gpio_op1_show(struct class *class,struct class_attribute *attr, char *buf)
|
|---|
| 65 | +{
|
|---|
| 66 | + return sprintf(buf, "%d\n", gpio_get_value(gpio_data->gpio_op1));
|
|---|
| 67 | +}
|
|---|
| 68 | +
|
|---|
| 69 | +static ssize_t gpio_op1_store(struct class *class,struct class_attribute *attr, const char *buf, size_t size)
|
|---|
| 70 | +{
|
|---|
| 71 | + if(!strncmp(buf, HIGH, strlen(HIGH))) {
|
|---|
| 72 | + gpio_set_value(gpio_data->gpio_op1, 1);
|
|---|
| 73 | +
|
|---|
| 74 | + } else if(!strncmp(buf, LOW, strlen(LOW))) {
|
|---|
| 75 | + gpio_set_value(gpio_data->gpio_op1, 0);
|
|---|
| 76 | + }
|
|---|
| 77 | + return size;
|
|---|
| 78 | +}
|
|---|
| 79 | +
|
|---|
| 80 | +static CLASS_ATTR_RW(gpio_op0);
|
|---|
| 81 | +static CLASS_ATTR_RW(gpio_op1);
|
|---|
| 82 | +
|
|---|
| 83 | +static struct attribute *ndj_gpio_attrs[] = {
|
|---|
| 84 | + &class_attr_gpio_op0.attr,
|
|---|
| 85 | + &class_attr_gpio_op1.attr,
|
|---|
| 86 | + NULL,
|
|---|
| 87 | +};
|
|---|
| 88 | +
|
|---|
| 89 | +ATTRIBUTE_GROUPS(ndj_gpio);
|
|---|
| 90 | +
|
|---|
| 91 | +/** Device model classes */
|
|---|
| 92 | +struct class ndj_io_class = {
|
|---|
| 93 | + .name = "io_control", //sysfs directory
|
|---|
| 94 | + .class_groups = ndj_gpio_groups,
|
|---|
| 95 | +};
|
|---|
| 96 | +
|
|---|
| 97 | +#endif
|
|---|
| 98 | +//static int event_flag = 0;
|
|---|
| 41 | 99 | static int open_now = 0;
|
|---|
| 42 | 100 | static char* file_name = NULL;
|
|---|
| 43 | 101 |
|
|---|
| .. | .. |
|---|
| 95 | 153 | }
|
|---|
| 96 | 154 |
|
|---|
| 97 | 155 |
|
|---|
| 98 | | -static const struct file_operations gpio_ops = {
|
|---|
| 99 | | - .owner = THIS_MODULE,
|
|---|
| 100 | | - .open = gpio_open,
|
|---|
| 101 | | - .write = gpio_write,
|
|---|
| 102 | | - .read = gpio_read,
|
|---|
| 156 | +static const struct proc_ops gpio_ops = {
|
|---|
| 157 | + .proc_open = gpio_open,
|
|---|
| 158 | + .proc_write = gpio_write,
|
|---|
| 159 | + .proc_read = gpio_read,
|
|---|
| 103 | 160 | };
|
|---|
| 104 | 161 |
|
|---|
| 105 | 162 | static int ndj_gpio_probe(struct platform_device *pdev) {
|
|---|
| 106 | 163 | struct device_node *np = pdev->dev.of_node;
|
|---|
| 107 | 164 | struct device_node *child_np;
|
|---|
| 108 | | - struct device *dev = &pdev->dev;
|
|---|
| 109 | 165 | static struct proc_dir_entry *root_entry_gpio;
|
|---|
| 110 | 166 | enum of_gpio_flags gpio_flags;
|
|---|
| 111 | 167 | int ret = 0;
|
|---|
| 112 | 168 | int gpio_cnt = 0;
|
|---|
| 113 | 169 | char gpio_name_num[20];
|
|---|
| 114 | 170 | int gpio_in_cnt = 0;
|
|---|
| 115 | | - int cnt =0;
|
|---|
| 116 | | - int lvds_index = 0;
|
|---|
| 117 | | - int gpio0, gpio1, gpio2, gpio3;
|
|---|
| 118 | | - int i=0;
|
|---|
| 119 | | - enum of_gpio_flags flags;
|
|---|
| 120 | 171 |
|
|---|
| 121 | 172 | gpio_data = devm_kzalloc(&pdev->dev, sizeof(struct ndj_gpio_data),GFP_KERNEL);
|
|---|
| 122 | 173 | if (!gpio_data) {
|
|---|
| .. | .. |
|---|
| 130 | 181 | if (gpio_data->gpio_dts_num == 0){
|
|---|
| 131 | 182 | dev_info(&pdev->dev, "no gpio defined\n");
|
|---|
| 132 | 183 | }
|
|---|
| 184 | +
|
|---|
| 185 | + #if 0
|
|---|
| 186 | + /*gpio_op0*/
|
|---|
| 187 | + ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
|
|---|
| 188 | + if (ret < 0) {
|
|---|
| 189 | + printk("%s() Can not read property gpio_op0\n", __func__);
|
|---|
| 190 | + return -ENODEV;
|
|---|
| 191 | + }
|
|---|
| 192 | + gpio_data->gpio_op0 = ret;
|
|---|
| 193 | + ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
|
|---|
| 194 | + if(ret < 0){
|
|---|
| 195 | + printk("%s() gpio_op0 request ERROR\n", __func__);
|
|---|
| 196 | + return -ENODEV;
|
|---|
| 197 | + }
|
|---|
| 198 | +
|
|---|
| 199 | + gpio_direction_output(gpio_data->gpio_op0,!gpio_flags);
|
|---|
| 200 | +#endif
|
|---|
| 133 | 201 |
|
|---|
| 134 | 202 | /* create node */
|
|---|
| 135 | 203 | root_entry_gpio = proc_mkdir("ndj_gpio", NULL);
|
|---|
| .. | .. |
|---|
| 161 | 229 |
|
|---|
| 162 | 230 | gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num);
|
|---|
| 163 | 231 | //gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action);
|
|---|
| 164 | | - event_flag = gpio_flags;
|
|---|
| 165 | | - of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
|
|---|
| 166 | | - of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
|
|---|
| 232 | + //event_flag = gpio_flags;
|
|---|
| 233 | + //of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode));
|
|---|
| 234 | + //of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event));
|
|---|
| 167 | 235 | gpio_in_cnt++;
|
|---|
| 168 | 236 | }
|
|---|
| 169 | 237 | break;
|
|---|
| .. | .. |
|---|
| 200 | 268 | gpio_cnt++;
|
|---|
| 201 | 269 | }
|
|---|
| 202 | 270 |
|
|---|
| 203 | | - platform_set_drvdata(pdev, gpio_data);
|
|---|
| 271 | + platform_set_drvdata(pdev, gpio_data);
|
|---|
| 272 | +
|
|---|
| 273 | +#if 0
|
|---|
| 274 | + ret= class_register(&ndj_io_class);
|
|---|
| 275 | + if(ret < 0) {
|
|---|
| 276 | + return -EINVAL;
|
|---|
| 277 | + }
|
|---|
| 278 | +#endif
|
|---|
| 204 | 279 | return 0;
|
|---|
| 205 | 280 | }
|
|---|
| 206 | 281 |
|
|---|
| 207 | 282 |
|
|---|
| 208 | 283 | static int ndj_gpio_suspend(struct platform_device *pdev, pm_message_t state)
|
|---|
| 209 | 284 | {
|
|---|
| 210 | | - int ret;
|
|---|
| 211 | | - struct nk_io_pdata *pdata;
|
|---|
| 285 | +// int ret;
|
|---|
| 286 | +// struct nk_io_pdata *pdata;
|
|---|
| 212 | 287 | printk("nk_suspend !!!!\n");
|
|---|
| 213 | 288 | return 0;
|
|---|
| 214 | 289 | }
|
|---|
| 215 | 290 |
|
|---|
| 216 | 291 | static int ndj_gpio_resume(struct platform_device *pdev)
|
|---|
| 217 | 292 | {
|
|---|
| 218 | | - int ret,reset_pin;
|
|---|
| 293 | +// int ret,reset_pin;
|
|---|
| 219 | 294 | printk("nk_io resume !!!!\n");
|
|---|
| 220 | 295 | return 0;
|
|---|
| 221 | 296 | }
|
|---|
| .. | .. |
|---|
| 223 | 298 |
|
|---|
| 224 | 299 | static int ndj_gpio_remove(struct platform_device *pdev)
|
|---|
| 225 | 300 | {
|
|---|
| 301 | +// class_unregister(&ndj_io_class);
|
|---|
| 226 | 302 | return 0;
|
|---|
| 227 | 303 | }
|
|---|
| 228 | 304 |
|
|---|
| .. | .. |
|---|
| 245 | 321 |
|
|---|
| 246 | 322 | module_platform_driver(ndj_gpio_driver);
|
|---|
| 247 | 323 | MODULE_LICENSE("GPL");
|
|---|
| 248 | | -MODULE_LICENSE("GPL"); |
|---|
| 324 | +MODULE_LICENSE("GPL");
|
|---|