/* * 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 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", }, {}, }; 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");