/* * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #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 MODULE_SET(int i) { if(i==11){ gpio_direction_output(NKpdata_info->en_4g_gpio, 1); }else{ gpio_direction_output(NKpdata_info->en_4g_gpio, 0); } } EXPORT_SYMBOL_GPL(MODULE_SET); void LED_SET(int i) { if(i==11){ gpio_direction_output(NKpdata_info->led_gpio, 1); }else{ gpio_direction_output(NKpdata_info->led_gpio, 0); } } EXPORT_SYMBOL_GPL(LED_SET); 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 gpio0, gpio1, gpio2, gpio3, reset_pin, ch342_reset; int ret; int lvds_index; int i=0; static int lvds_gpio[4] ; 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; } } //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 tp_enable\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; } } //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_gpio ret = of_get_named_gpio_flags(node, "hub_host2_5v_gpio", 0, &flags); if (ret < 0) { printk("%s() Can not read property hub_host2_5v_gpio\n", __FUNCTION__); goto err; } else { pdata->hub_host2_5v_gpio = ret; gpio_free(ret); ret = devm_gpio_request(&pdev->dev, pdata->hub_host2_5v_gpio, "hub_host2_5v_gpio"); if (ret < 0){ printk("%s() devm_gpio_request hub_host2_5v_gpio request ERROR\n", __FUNCTION__); goto err; } ret = gpio_direction_output(pdata->hub_host2_5v_gpio,1); if(ret < 0){ printk("%s() gpio_direction_input hub_host2_5v_gpio set ERROR\n", __FUNCTION__); goto err; } } //usb_en_oc_gpio ret = of_get_named_gpio_flags(node, "usb_en_oc_gpio", 0, &flags); if (ret < 0) { printk("%s() Can not read property usb_en_oc_gpio\n", __FUNCTION__); goto err; } else { pdata->usb_en_oc_gpio = ret; gpio_free(ret); ret = devm_gpio_request(&pdev->dev, pdata->usb_en_oc_gpio, "usb_en_oc_gpio"); if (ret < 0){ printk("%s() devm_gpio_request usb_en_oc_gpio request ERROR\n", __FUNCTION__); goto err; } ret = gpio_direction_output(pdata->usb_en_oc_gpio,1); if(ret < 0){ printk("%s() gpio_direction_input usb_en_oc_gpio 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,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_input en_4g_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__); } } //ch342_enable-gpio; ret = of_get_named_gpio_flags(node, "ch342_power", 0, &flags); if (ret < 0) { printk("%s() Can not read property ch342_gpio\n", __FUNCTION__); } else { pdata->ch342_power = ret; ret = devm_gpio_request(&pdev->dev, pdata->ch342_power, "ch342_power"); if(ret < 0){ printk("%s() devm_gpio_request ch342_power request ERROR\n", __FUNCTION__); } ret = gpio_direction_output(pdata->ch342_power,1); if(ret < 0){ printk("%s() gpio_direction_input ch342_power 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]); 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) { int ret,reset_pin; printk("nk_io resume !!!!\n"); ret = gpio_get_value(120); #if 0 gpio_set_value(8,1); ret = gpio_get_value(8); printk("vcc12v gpio value : %d\n",ret); #endif #if 0 gpio_set_value(15,1); ret = gpio_get_value(15); printk("edp_en gpio value : %d\n",ret); gpio_set_value(21,1); ret = gpio_get_value(21); printk("hub_host3_5v_gpio value : %d\n",ret); #endif #if 0 usleep_range(80000, 100000); gpio_set_value(120,0); // gpio_direction_output(120, 0); usleep_range(80000, 100000); ret = gpio_get_value(120); printk("edp_reset gpio value : %d\n",ret); // gpio_direction_output(120, 1); gpio_set_value(120,1); usleep_range(80000, 100000); ret = gpio_get_value(120); printk("edp_reset gpio value : %d\n",ret); #endif //enable = 1; //LED_SET(11); return 0; } static const struct of_device_id nk_io_control_of_match[] = { { .compatible = "nk_io_control", }, {}, }; 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), }, }; static int __init nk_io_control_init(void) { platform_driver_register(&nk_io_control_driver); return 0; } static void __exit nk_io_control_exit(void) { platform_driver_unregister(&nk_io_control_driver); } subsys_initcall(nk_io_control_init); //late_initcall(nk_io_control_init); MODULE_DESCRIPTION("nk io Core Driver"); MODULE_LICENSE("GPL");