| |
| #include <linux/debugfs.h> |
| #include <linux/device.h> |
| #include <linux/module.h> |
| #include <linux/err.h> |
| #include <linux/slab.h> |
| #include <linux/delay.h> |
| #include <linux/platform_device.h> |
| #include <linux/pm_runtime.h> |
| #include <linux/suspend.h> |
| #include <linux/clk.h> |
| #include <linux/of_device.h> |
| #include <linux/of_gpio.h> |
| #include <linux/of_platform.h> |
| |
| |
| |
| |
| int g_emmc_pwr_pin = -1; |
| int g_eth_pwr_pin = -1; |
| int g_eth_0v9_pin = -1; |
| |
| |
| |
| |
| static int customer_power_ctrl_suspend(struct platform_device *pdev, |
| pm_message_t pm_state) |
| { |
| |
| gpio_direction_output(g_eth_0v9_pin, 0); |
| mdelay(50); |
| gpio_direction_output(g_eth_pwr_pin, 0); |
| mdelay(50); |
| gpio_direction_output(g_emmc_pwr_pin, 0); |
| ; |
| |
| return 0; |
| } |
| |
| static int customer_power_ctrl_resume(struct platform_device *pdev) |
| { |
| |
| gpio_direction_output(g_emmc_pwr_pin, 1); |
| mdelay(10); |
| gpio_direction_output(g_eth_pwr_pin, 1); |
| mdelay(10); |
| gpio_direction_output(g_eth_0v9_pin, 1); |
| return 0; |
| } |
| |
| |
| |
| static int customer_power_ctrl_probe(struct platform_device *pdev) |
| { |
| |
| int ret; |
| struct device_node *np = pdev->dev.of_node; |
| |
| printk("[===>%s: begin]/L%d.\n", __FUNCTION__, __LINE__); |
| |
| g_emmc_pwr_pin = of_get_named_gpio(np, "emmc-pwr-en", 0); |
| if (unlikely(g_emmc_pwr_pin < 0)) { |
| printk("g_emmc_pwr_pin undefined\n"); |
| |
| } |
| else |
| { |
| printk("g_emmc_pwr_pin get success \n"); |
| gpio_request(g_emmc_pwr_pin, "g_emmc_pwr_pin"); |
| gpio_direction_output(g_emmc_pwr_pin, 1); |
| mdelay(8); |
| } |
| |
| |
| |
| g_eth_pwr_pin = of_get_named_gpio(np, "eth-pwr-en", 0); |
| if (unlikely(g_eth_pwr_pin < 0)) { |
| printk("g_eth_pwr_pin undefined\n"); |
| |
| } |
| else |
| { |
| printk("g_eth_pwr_pin get success \n"); |
| gpio_request(g_eth_pwr_pin, "g_eth_pwr_pin"); |
| gpio_direction_output(g_eth_pwr_pin, 1); |
| mdelay(8); |
| } |
| |
| g_eth_0v9_pin = of_get_named_gpio(np, "eth-0v9-en", 0); |
| if (unlikely(g_eth_0v9_pin < 0)) { |
| printk("g_eth_0v9_pin undefined\n"); |
| |
| } |
| else |
| { |
| printk("g_eth_0v9_pin get success \n"); |
| gpio_request(g_eth_0v9_pin, "g_eth_0v9_pin"); |
| gpio_direction_output(g_eth_0v9_pin, 1); |
| |
| } |
| |
| |
| return 0; |
| } |
| |
| |
| static int customer_power_ctrl_remove(struct platform_device *pdev) |
| { |
| return 0; |
| } |
| |
| |
| static const struct of_device_id customer_power_ctrl_dt_match[] = { |
| { .compatible = "customer,power", }, |
| { }, |
| }; |
| MODULE_DEVICE_TABLE(of, customer_power_ctrl_dt_match); |
| |
| static struct platform_driver customer_power_ctrl_driver = { |
| .driver = { |
| .name = "customer-PowerCtl", |
| .owner = THIS_MODULE, |
| .of_match_table = of_match_ptr(customer_power_ctrl_dt_match), |
| }, |
| .probe = customer_power_ctrl_probe, |
| .remove = customer_power_ctrl_remove, |
| .suspend = customer_power_ctrl_suspend, |
| .resume = customer_power_ctrl_resume, |
| }; |
| |
| static int __init customer_power_ctrl_init(void) |
| { |
| return platform_driver_register(&customer_power_ctrl_driver); |
| } |
| |
| fs_initcall(customer_power_ctrl_init); |
| |
| static void __exit customer_power_ctrl_exit(void) |
| { |
| platform_driver_unregister(&customer_power_ctrl_driver); |
| } |
| module_exit(customer_power_ctrl_exit); |
| |
| MODULE_DESCRIPTION("customer power pin driver"); |
| MODULE_LICENSE("GPL"); |