| .. | .. |
|---|
| 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 | | - */
|
|---|
| 14 | 1 | #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>
|
|---|
| 23 | 2 | #include <linux/err.h>
|
|---|
| 24 | | -#include <linux/debugfs.h>
|
|---|
| 25 | | -#include <linux/of_gpio.h>
|
|---|
| 26 | 3 | #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"
|
|---|
| 30 | 22 |
|
|---|
| 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 | +};
|
|---|
| 37 | 42 |
|
|---|
| 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;
|
|---|
| 43 | 44 |
|
|---|
| 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 | | - }
|
|---|
| 45 | +/* creat sysfs gpio api node*/
|
|---|
| 254 | 46 | #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 | | - }
|
|---|
| 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 | +}
|
|---|
| 267 | 51 |
|
|---|
| 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 | | - }
|
|---|
| 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 | +
|
|---|
| 280 | 96 | #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 | | - }
|
|---|
| 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 | + }
|
|---|
| 388 | 188 |
|
|---|
| 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);
|
|---|
| 189 | + #if 0
|
|---|
| 190 | + /*gpio_op0*/
|
|---|
| 191 | + ret = of_get_named_gpio_flags(np, "gpio_op0", 0, &gpio_flags);
|
|---|
| 410 | 192 | if (ret < 0) {
|
|---|
| 411 | | - printk("%s() Can not read property edp_reset\n", __FUNCTION__);
|
|---|
| 412 | | - goto err;
|
|---|
| 193 | + printk("%s() Can not read property gpio_op0\n", __func__);
|
|---|
| 194 | + return -ENODEV;
|
|---|
| 413 | 195 | }
|
|---|
| 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");
|
|---|
| 196 | + gpio_data->gpio_op0 = ret;
|
|---|
| 197 | + ret = gpio_request(gpio_data->gpio_op0, "gpio_op0");
|
|---|
| 453 | 198 | 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;
|
|---|
| 199 | + printk("%s() gpio_op0 request ERROR\n", __func__);
|
|---|
| 200 | + return -ENODEV;
|
|---|
| 481 | 201 | }
|
|---|
| 482 | 202 |
|
|---|
| 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 | | - }
|
|---|
| 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);
|
|---|
| 487 | 276 |
|
|---|
| 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;
|
|---|
| 277 | +#if 0
|
|---|
| 278 | + ret= class_register(&ndj_io_class);
|
|---|
| 279 | + if(ret < 0) {
|
|---|
| 280 | + return -EINVAL;
|
|---|
| 281 | + }
|
|---|
| 282 | +#endif
|
|---|
| 283 | + return 0;
|
|---|
| 524 | 284 | }
|
|---|
| 525 | | -
|
|---|
| 526 | | -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)
|
|---|
| 527 | 288 | {
|
|---|
| 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;
|
|---|
| 289 | + int ret;
|
|---|
| 290 | + struct nk_io_pdata *pdata;
|
|---|
| 291 | + printk("nk_suspend !!!!\n");
|
|---|
| 292 | + return 0;
|
|---|
| 550 | 293 | }
|
|---|
| 551 | | -
|
|---|
| 552 | | -static int nk_io_control_resume(struct platform_device *pdev)
|
|---|
| 294 | +
|
|---|
| 295 | +static int ndj_gpio_resume(struct platform_device *pdev)
|
|---|
| 553 | 296 | {
|
|---|
| 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;
|
|---|
| 297 | + int ret,reset_pin;
|
|---|
| 298 | + printk("nk_io resume !!!!\n");
|
|---|
| 299 | + return 0;
|
|---|
| 587 | 300 | }
|
|---|
| 588 | | -
|
|---|
| 589 | | -static const struct of_device_id nk_io_control_of_match[] = {
|
|---|
| 590 | | - { .compatible = "nk_io_control", },
|
|---|
| 591 | | - {},
|
|---|
| 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 | + { }
|
|---|
| 592 | 313 | };
|
|---|
| 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 | | - },
|
|---|
| 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 | + },
|
|---|
| 605 | 324 | };
|
|---|
| 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");
|
|---|
| 325 | +
|
|---|
| 326 | +module_platform_driver(ndj_gpio_driver);
|
|---|
| 622 | 327 | MODULE_LICENSE("GPL");
|
|---|
| 328 | +MODULE_LICENSE("GPL"); |
|---|