From 185649640333407ac269f396d6adcc4b25bfb474 Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Tue, 29 Aug 2023 08:01:55 +0000 Subject: [PATCH] 变更IO驱动 --- kernel/drivers/misc/nkio/nk_io_core.c | 848 +++++++++++++++---------------------------------------- 1 files changed, 238 insertions(+), 610 deletions(-) diff --git a/kernel/drivers/misc/nkio/nk_io_core.c b/kernel/drivers/misc/nkio/nk_io_core.c index 7df3022..1e06855 100755 --- a/kernel/drivers/misc/nkio/nk_io_core.c +++ b/kernel/drivers/misc/nkio/nk_io_core.c @@ -1,620 +1,248 @@ -/* - * Copyright (C) 2014 Rockchip Corporation. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ #include <linux/module.h> -#include <linux/moduleparam.h> -#include <linux/init.h> -#include <linux/delay.h> -#include <linux/pm.h> -#include <linux/i2c.h> -#include <linux/spi/spi.h> -#include <linux/platform_device.h> -#include <linux/errno.h> #include <linux/err.h> -#include <linux/debugfs.h> -#include <linux/of_gpio.h> #include <linux/gpio.h> -#include <linux/iio/consumer.h> -#include <linux/of.h> -#include "nkio.h" - -/* Debug */ -#if 1 -#define DBG(x...) printk(x) -#else -#define DBG(x...) do { } while (0) -#endif - -struct nk_io_pdata *NKpdata_info; -u32 op0_enable,op1_enable,op2_enable,op3_enable,op4_enable,op5_enable,mic_enable; -u32 ip0_enable,ip1_enable,ip2_enable,ip3_enable,ip4_enable,ip5_enable; -u32 module_enable; -//static struct class *nk_class; - - - -void Audio_SET(int i); - - void Audio_SET(int i) - { - if(i==11){ - gpio_direction_output(NKpdata_info->audio_switch_gpio, 1); - printk("Audio_SET ENABLE------andy\n"); - }else{ - gpio_direction_output(NKpdata_info->audio_switch_gpio, 0); - printk("Audio_SET DISABLE------andy\n"); - } - } - EXPORT_SYMBOL_GPL(Audio_SET); - -static int nk_io_control_probe(struct platform_device *pdev) -{ - struct device_node *node = pdev->dev.of_node; - struct nk_io_pdata *pdata; - int ret; - - - enum of_gpio_flags flags; - - printk(" #######nk_io_control_probe####### \n"); - - pdata = kzalloc(sizeof(struct nk_io_pdata), GFP_KERNEL); - if (pdata == NULL) { - printk("%s failed to allocate driver data\n",__FUNCTION__); - return -ENOMEM; - } - memset(pdata,0,sizeof(struct nk_io_pdata)); - - //vcc_5v_io - ret = of_get_named_gpio_flags(node, "vcc_5v_io", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property vcc_5v_io\n", __FUNCTION__); - goto err; - } else { - pdata->vcc_5v_io = ret; - ret = devm_gpio_request(&pdev->dev, pdata->vcc_5v_io, "vcc_5v_io"); - if(ret < 0){ - printk("%s() devm_gpio_request vcc_5v_io request ERROR\n", __FUNCTION__); - goto err; - } - - ret = gpio_direction_output(pdata->vcc_5v_io,1); - if(ret < 0){ - printk("%s() gpio_direction_input vcc_5v_io set ERROR\n", __FUNCTION__); - goto err; - } - } -#if 0 - //vcc3_io_en_gpio - ret = of_get_named_gpio_flags(node, "vcc3_io_en_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property vcc3_io_en_gpio\n", __FUNCTION__); - goto err; - } else { - pdata->vcc3_io_en_gpio = ret; - ret = devm_gpio_request(&pdev->dev, pdata->vcc3_io_en_gpio, "vcc3_io_en_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request vcc3_io_en_gpio request ERROR\n", __FUNCTION__); - goto err; - } - - ret = gpio_direction_output(pdata->vcc3_io_en_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_output vcc3_io_en_gpio set ERROR\n", __FUNCTION__); - goto err; - } - } -#endif - //vcc_12v_io - ret = of_get_named_gpio_flags(node, "vcc_12v_io", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property vcc_12v_io\n", __FUNCTION__); - goto err; - } else { - pdata->vcc_12v_io = ret; - ret = devm_gpio_request(&pdev->dev, pdata->vcc_12v_io, "vcc_12v_io"); - if(ret < 0){ - printk("%s() devm_gpio_request vcc_12v_io request ERROR\n", __FUNCTION__); - goto err; - } - - ret = gpio_direction_output(pdata->vcc_12v_io,1); - if(ret < 0){ - printk("%s() gpio_direction_input vcc_12v_io set ERROR\n", __FUNCTION__); - goto err; - } - } - - - //hub_host2_5V_rest_gpio - ret = of_get_named_gpio_flags(node, "hub_host2_5V_rest_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property hub_host2_5V_rest_gpio\n", __FUNCTION__); - goto err; - } else { - pdata->hub_host2_5V_rest_gpio = ret; - ret = devm_gpio_request(&pdev->dev, pdata->hub_host2_5V_rest_gpio, "hub_host2_5V_rest_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request hub_host2_5V_rest_gpio request ERROR\n", __FUNCTION__); - goto err; - } - - ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,0); - if(ret < 0){ - printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__); - goto err; - } - msleep(800); - ret = gpio_direction_output(pdata->hub_host2_5V_rest_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_input hub_host2_5V_rest_gpio set ERROR\n", __FUNCTION__); - goto err; - } - } - - //hub_host3_5v_gpio - ret = of_get_named_gpio_flags(node, "hub_host3_5v_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property hub_host3_5v_gpio\n", __FUNCTION__); - goto err; - } else { - pdata->hub_host3_5v_gpio = ret; - gpio_free(ret); - ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5v_gpio, "hub_host3_5v_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request hub_host3_5v_gpio request ERROR\n", __FUNCTION__); - goto err; - } - - ret = gpio_direction_output(pdata->hub_host3_5v_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_input hub_host3_5v_gpio set ERROR\n", __FUNCTION__); - goto err; - } - } -#if 0 - //hub_host3_5V_rest_gpio - ret = of_get_named_gpio_flags(node, "hub_host3_5V_rest_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property hub_host3_5V_rest_gpio\n", __FUNCTION__); - goto err; - } else { - pdata->hub_host3_5V_rest_gpio = ret; - ret = devm_gpio_request(&pdev->dev, pdata->hub_host3_5V_rest_gpio, "hub_host3_5V_rest_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request hub_host3_5V_rest_gpio request ERROR\n", __FUNCTION__); - goto err; - } - - ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,0); - if(ret < 0){ - printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__); - goto err; - } - msleep(800); - ret = gpio_direction_output(pdata->hub_host3_5V_rest_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_input hub_host3_5V_rest_gpio set ERROR\n", __FUNCTION__); - goto err; - } - } -#endif - //wake_4g_gpio - ret = of_get_named_gpio_flags(node, "wake_4g_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property wake_4g_gpio\n", __FUNCTION__); - } else { - pdata->wake_4g_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->wake_4g_gpio, "wake_4g_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request wake_4g_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->wake_4g_gpio,0); - if(ret < 0){ - printk("%s() gpio_direction_input wake_4g_gpio set ERROR\n", __FUNCTION__); - } - } - - - //reset_4g_gpio - ret = of_get_named_gpio_flags(node, "reset_4g_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property reset_4g_gpio\n", __FUNCTION__); - } else { - pdata->reset_4g_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->reset_4g_gpio, "reset_4g_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request reset_4g_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->reset_4g_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_input reset_4g_gpio set ERROR\n", __FUNCTION__); - goto err; - } - msleep(800); - ret = gpio_direction_output(pdata->reset_4g_gpio,0); - if(ret < 0){ - printk("%s() gpio_direction_input reset_4g_gpio set ERROR\n", __FUNCTION__); - - } - } - - //en_4g_gpio - ret = of_get_named_gpio_flags(node, "en_4g_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property en_4g_gpio\n", __FUNCTION__); - } else { - pdata->en_4g_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->en_4g_gpio, "en_4g_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request en_4g_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->en_4g_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_output en_4g_gpio set ERROR\n", __FUNCTION__); - } - } - - //hp_en_gpio - ret = of_get_named_gpio_flags(node, "hp_en_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property hp_en_gpio\n", __FUNCTION__); - } else { - pdata->hp_en_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->hp_en_gpio, "hp_en_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request hp_en_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->hp_en_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_output hp_en_gpio set ERROR\n", __FUNCTION__); - } - } -#if 0 - //pcie_power_en_gpio - ret = of_get_named_gpio_flags(node, "pcie_power_en_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property pcie_power_en_gpio\n", __FUNCTION__); - } else { - pdata->pcie_power_en_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->pcie_power_en_gpio, "pcie_power_en_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request pcie_power_en_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->pcie_power_en_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_output pcie_power_en_gpio set ERROR\n", __FUNCTION__); - } - } -#endif - //wifi_power_en_gpio - ret = of_get_named_gpio_flags(node, "wifi_power_en_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property wifi_power_en_gpio\n", __FUNCTION__); - } else { - pdata->wifi_power_en_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->wifi_power_en_gpio, "wifi_power_en_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request wifi_power_en_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->wifi_power_en_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_output wifi_power_en_gpio set ERROR\n", __FUNCTION__); - } - } - -/* - //spk_out_gpio - ret = of_get_named_gpio_flags(node, "spk_out_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property spk_out_gpio\n", __FUNCTION__); - } else { - pdata->spk_out_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->spk_out_gpio, "spk_out_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request spk_out_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->spk_out_gpio,0); - if(ret < 0){ - printk("%s() gpio_direction_output spk_out_gpio set ERROR\n", __FUNCTION__); - } - } -*/ - //air_mode_4g_gpio - ret = of_get_named_gpio_flags(node, "air_mode_4g_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property air_mode_4g_gpio\n", __FUNCTION__); - } else { - pdata->air_mode_4g_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->air_mode_4g_gpio, "air_mode_4g_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request air_mode_4g_gpio request ERROR\n", __FUNCTION__); - } - ret = gpio_direction_output(pdata->air_mode_4g_gpio,0); - if(ret < 0){ - printk("%s() gpio_direction_input air_mode_4g_gpio set ERROR\n", __FUNCTION__); - } - } - - -/* - //edp_power_supply_gpio; - ret = of_get_named_gpio_flags(node, "edp_power_supply_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property edp_power_supply_gpio\n", __FUNCTION__); - } else { - pdata->edp_power_supply_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->edp_power_supply_gpio, "edp_power_supply_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request edp_power_supply_gpio request ERROR\n", __FUNCTION__); - } - - ret = gpio_direction_output(pdata->edp_power_supply_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_input edp_power_supply_gpio set ERROR\n", __FUNCTION__); - } - } - - //edp_enable-gpio; - ret = of_get_named_gpio_flags(node, "edp_enable_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property edp_enable_gpio\n", __FUNCTION__); - } else { - pdata->edp_enable_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->edp_enable_gpio, "edp_enable_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request edp_enable_gpio request ERROR\n", __FUNCTION__); - } - - ret = gpio_direction_output(pdata->edp_enable_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_input edp_enable_gpio set ERROR\n", __FUNCTION__); - } - } - - //lcd_bk_en_gpio; - ret = of_get_named_gpio_flags(node, "lcd_bk_en_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property lcd_bk_en_gpio\n", __FUNCTION__); - } else { - pdata->lcd_bk_en_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->lcd_bk_en_gpio, "lcd_bk_en_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request lcd_bk_en_gpio request ERROR\n", __FUNCTION__); - } - - ret = gpio_direction_output(pdata->lcd_bk_en_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_output lcd_bk_en_gpio set ERROR\n", __FUNCTION__); - } - } - - //lcd_pwblk_gpio; - ret = of_get_named_gpio_flags(node, "lcd_pwblk_gpio", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property lcd_pwblk_gpio\n", __FUNCTION__); - } else { - pdata->lcd_pwblk_gpio = ret; - - ret = devm_gpio_request(&pdev->dev, pdata->lcd_pwblk_gpio, "lcd_pwblk_gpio"); - if(ret < 0){ - printk("%s() devm_gpio_request lcd_pwblk_gpio request ERROR\n", __FUNCTION__); - } - - ret = gpio_direction_output(pdata->lcd_pwblk_gpio,1); - if(ret < 0){ - printk("%s() gpio_direction_output lcd_pwblk_gpio set ERROR\n", __FUNCTION__); - } - } - - - //edp_set_pixel-s - ret = of_get_named_gpio_flags(node, "edp_reset", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property edp_reset\n", __FUNCTION__); - goto err; - } - - reset_pin = ret; - -// enable lvds - ret = of_get_named_gpio_flags(node, "edp_gpio0", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property edp_gpio0\n", __FUNCTION__); - goto err; - } - gpio0 = ret; - - - - ret = of_get_named_gpio_flags(node, "edp_gpio1", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property edp_gpio1\n", __FUNCTION__); - goto err; - } - - gpio1 = ret; - - ret = of_get_named_gpio_flags(node, "edp_gpio2", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property edp_gpio2\n", __FUNCTION__); - goto err; - } - - gpio2 = ret; - - ret = of_get_named_gpio_flags(node, "edp_gpio3", 0, &flags); - if (ret < 0) { - printk("%s() Can not read property edp_gpio3\n", __FUNCTION__); - goto err; - } - - gpio3 = ret; - - - ret = devm_gpio_request(&pdev->dev, reset_pin, "edp_reset"); - if(ret < 0){ - printk("%s() devm_gpio_request edp_reset request ERROR\n", __FUNCTION__); - goto err; - } - - - ret = devm_gpio_request(&pdev->dev, gpio0, "edp_gpio0"); - if(ret < 0){ - printk("%s() devm_gpio_request edp_gpio0 request ERROR\n", __FUNCTION__); - goto err; - } - - ret = devm_gpio_request(&pdev->dev, gpio1, "edp_gpio1"); - if(ret < 0){ - printk("%s() devm_gpio_request edp_gpio1 request ERROR\n", __FUNCTION__); - goto err; - } - - ret = devm_gpio_request(&pdev->dev, gpio2, "edp_gpio2"); - if(ret < 0){ - printk("%s() devm_gpio_request edp_gpio2 request ERROR\n", __FUNCTION__); - goto err; - } - - ret = devm_gpio_request(&pdev->dev, gpio3, "edp_gpio3"); - if(ret < 0){ - printk("%s() devm_gpio_request edp_gpio3 request ERROR\n", __FUNCTION__); - goto err; - } - - ret = of_property_read_u32(node, "nodka_lvds", &lvds_index); - if (ret < 0){ - printk("%s() Can not read property nodka_lvds\n", __FUNCTION__); - } - - printk("nodka_lvds_index = %d\n",lvds_index); - - while ( i < 4 ){ - if ( lvds_index > 0) - lvds_gpio[i] = lvds_index%2; - else - lvds_gpio[i] = 0; - printk("lvds_gpio[%d]=%d\n",i,lvds_gpio[i]); - lvds_index = lvds_index/2; - i++; - } - - gpio_direction_output(reset_pin, 0); - usleep_range(80000, 100000); - gpio_direction_output(reset_pin, 1); - usleep_range(80000, 100000); - - gpio_direction_output(gpio0, lvds_gpio[0]); - gpio_direction_output(gpio1, lvds_gpio[1]); - gpio_direction_output(gpio2, lvds_gpio[2]); - gpio_direction_output(gpio3, lvds_gpio[3]); - - - gpio_direction_output(reset_pin, 0); - usleep_range(80000, 100000); - gpio_direction_output(reset_pin, 1); - usleep_range(80000, 100000); -*/ - printk(" #######nk_io_control_probe end####### \n"); - return 0; - -err: - kfree(pdata); - return ret; -} - - -static int nk_io_control_remove(struct platform_device *pdev) -{ - if(NKpdata_info) - kfree(NKpdata_info); - return 0; -} - -static int nk_io_control_suspend(struct platform_device *pdev, pm_message_t state) -{ - int ret; - struct nk_io_pdata *pdata; - printk("nk_suspend !!!!\n"); -#if 0 - ret = gpio_get_value(8); - printk("vcc12v gpio value : %d\n",ret); - usleep_range(80000, 100000); - gpio_set_value(8,0); - ret = gpio_get_value(8); - printk("vcc12v gpio value : %d\n",ret); -#endif -#if 0 - ret = gpio_get_value(21); - printk("hub_host3_5v_gpio value : %d\n",ret); - usleep_range(80000, 100000); - gpio_set_value(21,0); - ret = gpio_get_value(21); - printk("hub_host3_5v_gpio value : %d\n",ret); - //enable = 0; - //LED_SET(0); -#endif - return 0; -} - -static int nk_io_control_resume(struct platform_device *pdev) -{ - return 0; -} - -static const struct of_device_id nk_io_control_of_match[] = { - { .compatible = "nk_io_control", }, - {}, +#include <linux/kernel.h> +#include <linux/of_gpio.h> +#include <linux/of_platform.h> +#include <linux/delay.h> +#include <linux/input.h> +#include <linux/proc_fs.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <asm/uaccess.h> +#include <linux/string.h> +#include <linux/uaccess.h> + +#define GPIO_FUNCTION_OUTPUT 0 +#define GPIO_FUNCTION_INPUT 1 +#define GPIO_FUNCTION_RESET 3 + +static int flash_flag = 0; + +struct ndj_gpio { + int gpio_num; //gpui num + int action; //gpio flag + int gpio_event; //input only + int send_mode; //input only + int gpio_function; //gpio function,i/o + int gpio_ctrl; + char *gpio_name; }; -MODULE_DEVICE_TABLE(of, nk_io_control_of_match); - -static struct platform_driver nk_io_control_driver = { - .probe = nk_io_control_probe, - .remove = nk_io_control_remove, - .resume = nk_io_control_resume, - .suspend = nk_io_control_suspend, - .driver = { - .name = "nk_io_control", - .owner = THIS_MODULE, - .of_match_table = of_match_ptr(nk_io_control_of_match), - }, + +struct ndj_gpio_data { + struct ndj_gpio ndj_gpio_num[20]; + struct input_dev *input; + struct timer_list mytimer; + int gpio_dts_num; }; - -static int __init nk_io_control_init(void) + +static struct ndj_gpio_data *gpio_data = NULL; +static int event_flag = 0; +static int open_now = 0; +static char* file_name = NULL; + +static int gpio_open(struct inode *inode, struct file *file) { - platform_driver_register(&nk_io_control_driver); - return 0; + struct dentry* dent = file->f_path.dentry; + int i = 0; + + file_name = (char*)(dent->d_name.name); + + for (i = 0; i < gpio_data->gpio_dts_num; i++){ + if(!strcmp(file_name,gpio_data->ndj_gpio_num[i].gpio_name)){ + open_now = i; + } + } + return 0; } - -static void __exit nk_io_control_exit(void) + +static ssize_t gpio_write(struct file *file, const char *buffer,size_t count, loff_t *data) { - platform_driver_unregister(&nk_io_control_driver); + char buf[2]={0}; + char s1[]="1"; + + if(copy_from_user(&buf[0],buffer,1)){ + printk("failed to copy data to kernel space\n"); + return -EFAULT; + } + + if(!strcmp(buf,s1)){ + gpio_direction_output(gpio_data->ndj_gpio_num[open_now].gpio_num,1); + //printk("%s write 1 succeed\n",gpio_data->ndj_gpio_num[open_now].gpio_name); + }else{ + gpio_direction_output(gpio_data->ndj_gpio_num[open_now].gpio_num,0); + //printk("%s write 0 succeed\n",gpio_data->ndj_gpio_num[open_now].gpio_name); + } + return count; } - -subsys_initcall(nk_io_control_init); - -//late_initcall(nk_io_control_init); -MODULE_DESCRIPTION("nk io Core Driver"); + + +static ssize_t gpio_read(struct file *file, char __user * buffer, size_t count, loff_t *data) +{ + int gpio_val = 0; + int len = 0; + char s[10] = {0}; + + if(*data) + return 0; + + gpio_val = gpio_get_value(gpio_data->ndj_gpio_num[open_now].gpio_num); + //printk("get %s value %d\n",gpio_data->ndj_gpio_num[open_now].gpio_name,gpio_val); + + len = sprintf(s+len, "%d\n",gpio_val); + + return simple_read_from_buffer(buffer, count, data, s, 2); +} + + +static const struct file_operations gpio_ops = { + .owner = THIS_MODULE, + .open = gpio_open, + .write = gpio_write, + .read = gpio_read, +}; + +static int ndj_gpio_probe(struct platform_device *pdev) { + struct device_node *np = pdev->dev.of_node; + struct device_node *child_np; + struct device *dev = &pdev->dev; + static struct proc_dir_entry *root_entry_gpio; + enum of_gpio_flags gpio_flags; + int ret = 0; + int gpio_cnt = 0; + char gpio_name_num[20]; + int gpio_in_cnt = 0; + int cnt =0; + int lvds_index = 0; + int gpio0, gpio1, gpio2, gpio3; + int i=0; + enum of_gpio_flags flags; + + gpio_data = devm_kzalloc(&pdev->dev, sizeof(struct ndj_gpio_data),GFP_KERNEL); + if (!gpio_data) { + dev_err(&pdev->dev, "failed to allocate memory\n"); + return -ENOMEM; + } + + gpio_data->gpio_dts_num = of_get_child_count(np); +// printk("ndj_gpio prepare build %d gpio\n",gpio_data->gpio_dts_num); + + if (gpio_data->gpio_dts_num == 0){ + dev_info(&pdev->dev, "no gpio defined\n"); + } + + /* create node */ + root_entry_gpio = proc_mkdir("ndj_gpio", NULL); + + for_each_child_of_node(np, child_np) + { + /* parse dts */ + gpio_data->ndj_gpio_num[gpio_cnt].gpio_num = of_get_named_gpio_flags(child_np, "gpio_num", 0, &gpio_flags); + if (!gpio_is_valid(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num)){ + return -1; + } + + gpio_data->ndj_gpio_num[gpio_cnt].gpio_name = (char*)child_np -> name; + gpio_data->ndj_gpio_num[gpio_cnt].action = gpio_flags; + gpio_data->ndj_gpio_num[gpio_cnt].gpio_ctrl = gpio_cnt; + of_property_read_u32(child_np, "gpio_function", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_function)); + +// printk("ndj_gpio request %s\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_name); + + + switch(gpio_data->ndj_gpio_num[gpio_cnt].gpio_function) { + case GPIO_FUNCTION_INPUT : /* init input gpio */ + ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name); + if (ret < 0) + { + printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num); + }else{ + // printk("success request gpio %d in\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num); + + gpio_direction_input(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num); + //gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action); + event_flag = gpio_flags; + of_property_read_u32(child_np, "send_mode", &(gpio_data->ndj_gpio_num[gpio_cnt].send_mode)); + of_property_read_u32(child_np, "gpio_event", &(gpio_data->ndj_gpio_num[gpio_cnt].gpio_event)); + gpio_in_cnt++; + } + break; + + case GPIO_FUNCTION_OUTPUT : /* init output gpio */ + ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name); + if (ret < 0){ + printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num); + //return ret; + }else{ + gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action); + //printk("success request gpio%d out\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num); + } + break; + + case GPIO_FUNCTION_RESET : + ret = gpio_request(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num, gpio_data->ndj_gpio_num[gpio_cnt].gpio_name); + if (ret < 0){ + printk("gpio%d request error\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num); + //return ret; + }else{ + gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,gpio_data->ndj_gpio_num[gpio_cnt].action); + //printk("success request gpio%d reset\n",gpio_data->ndj_gpio_num[gpio_cnt].gpio_num); + mdelay(200); + gpio_direction_output(gpio_data->ndj_gpio_num[gpio_cnt].gpio_num,!gpio_data->ndj_gpio_num[gpio_cnt].action); + +// gpio_cnt++; + } + break; + } + + sprintf(gpio_name_num,gpio_data->ndj_gpio_num[gpio_cnt].gpio_name,gpio_cnt); + proc_create(gpio_name_num, 0666 , root_entry_gpio , &gpio_ops); + gpio_cnt++; + } + + platform_set_drvdata(pdev, gpio_data); + return 0; +} + + +static int ndj_gpio_suspend(struct platform_device *pdev, pm_message_t state) +{ + int ret; + struct nk_io_pdata *pdata; + printk("nk_suspend !!!!\n"); + return 0; +} + +static int ndj_gpio_resume(struct platform_device *pdev) +{ + int ret,reset_pin; + printk("nk_io resume !!!!\n"); + return 0; +} + + +static int ndj_gpio_remove(struct platform_device *pdev) +{ + return 0; +} + + +static const struct of_device_id ndj_gpio_of_match[] = { + { .compatible = "nk_io_control" }, + { } +}; + +static struct platform_driver ndj_gpio_driver = { + .probe = ndj_gpio_probe, + .remove = ndj_gpio_remove, + .resume = ndj_gpio_resume, + .suspend = ndj_gpio_suspend, + .driver = { + .name = "nk_io_control", + .of_match_table = of_match_ptr(ndj_gpio_of_match), + }, +}; + +module_platform_driver(ndj_gpio_driver); MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL"); \ No newline at end of file -- Gitblit v1.6.2