b.liu | b17525e | 2025-05-14 17:22:29 +0800 | [diff] [blame^] | 1 | |
| 2 | #include <linux/debugfs.h> |
| 3 | #include <linux/device.h> |
| 4 | #include <linux/module.h> |
| 5 | #include <linux/err.h> |
| 6 | #include <linux/slab.h> |
| 7 | #include <linux/delay.h> |
| 8 | #include <linux/platform_device.h> |
| 9 | #include <linux/pm_runtime.h> |
| 10 | #include <linux/suspend.h> |
| 11 | #include <linux/clk.h> |
| 12 | #include <linux/of_device.h> |
| 13 | #include <linux/of_gpio.h> |
| 14 | #include <linux/of_platform.h> |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | int g_emmc_pwr_pin = -1; |
| 20 | int g_eth_pwr_pin = -1; |
| 21 | int g_eth_0v9_pin = -1; |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | static int customer_power_ctrl_suspend(struct platform_device *pdev, |
| 27 | pm_message_t pm_state) |
| 28 | { |
| 29 | |
| 30 | gpio_direction_output(g_eth_0v9_pin, 0); |
| 31 | mdelay(50); |
| 32 | gpio_direction_output(g_eth_pwr_pin, 0); |
| 33 | mdelay(50); |
| 34 | gpio_direction_output(g_emmc_pwr_pin, 0); |
| 35 | ; |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int customer_power_ctrl_resume(struct platform_device *pdev) |
| 41 | { |
| 42 | |
| 43 | gpio_direction_output(g_emmc_pwr_pin, 1); |
| 44 | mdelay(10); |
| 45 | gpio_direction_output(g_eth_pwr_pin, 1); |
| 46 | mdelay(10); |
| 47 | gpio_direction_output(g_eth_0v9_pin, 1); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | |
| 53 | static int customer_power_ctrl_probe(struct platform_device *pdev) |
| 54 | { |
| 55 | |
| 56 | int ret; |
| 57 | struct device_node *np = pdev->dev.of_node; |
| 58 | |
| 59 | printk("[===>%s: begin]/L%d.\n", __FUNCTION__, __LINE__); |
| 60 | |
| 61 | g_emmc_pwr_pin = of_get_named_gpio(np, "emmc-pwr-en", 0); |
| 62 | if (unlikely(g_emmc_pwr_pin < 0)) { |
| 63 | printk("g_emmc_pwr_pin undefined\n"); |
| 64 | |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | printk("g_emmc_pwr_pin get success \n"); |
| 69 | gpio_request(g_emmc_pwr_pin, "g_emmc_pwr_pin"); |
| 70 | gpio_direction_output(g_emmc_pwr_pin, 1); |
| 71 | mdelay(8); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | |
| 76 | g_eth_pwr_pin = of_get_named_gpio(np, "eth-pwr-en", 0); |
| 77 | if (unlikely(g_eth_pwr_pin < 0)) { |
| 78 | printk("g_eth_pwr_pin undefined\n"); |
| 79 | |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | printk("g_eth_pwr_pin get success \n"); |
| 84 | gpio_request(g_eth_pwr_pin, "g_eth_pwr_pin"); |
| 85 | gpio_direction_output(g_eth_pwr_pin, 1); |
| 86 | mdelay(8); |
| 87 | } |
| 88 | |
| 89 | g_eth_0v9_pin = of_get_named_gpio(np, "eth-0v9-en", 0); |
| 90 | if (unlikely(g_eth_0v9_pin < 0)) { |
| 91 | printk("g_eth_0v9_pin undefined\n"); |
| 92 | |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | printk("g_eth_0v9_pin get success \n"); |
| 97 | gpio_request(g_eth_0v9_pin, "g_eth_0v9_pin"); |
| 98 | gpio_direction_output(g_eth_0v9_pin, 1); |
| 99 | |
| 100 | } |
| 101 | |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | static int customer_power_ctrl_remove(struct platform_device *pdev) |
| 108 | { |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | static const struct of_device_id customer_power_ctrl_dt_match[] = { |
| 114 | { .compatible = "customer,power", }, |
| 115 | { }, |
| 116 | }; |
| 117 | MODULE_DEVICE_TABLE(of, customer_power_ctrl_dt_match); |
| 118 | |
| 119 | static struct platform_driver customer_power_ctrl_driver = { |
| 120 | .driver = { |
| 121 | .name = "customer-PowerCtl", |
| 122 | .owner = THIS_MODULE, |
| 123 | .of_match_table = of_match_ptr(customer_power_ctrl_dt_match), |
| 124 | }, |
| 125 | .probe = customer_power_ctrl_probe, |
| 126 | .remove = customer_power_ctrl_remove, |
| 127 | .suspend = customer_power_ctrl_suspend, |
| 128 | .resume = customer_power_ctrl_resume, |
| 129 | }; |
| 130 | |
| 131 | static int __init customer_power_ctrl_init(void) |
| 132 | { |
| 133 | return platform_driver_register(&customer_power_ctrl_driver); |
| 134 | } |
| 135 | |
| 136 | fs_initcall(customer_power_ctrl_init); |
| 137 | |
| 138 | static void __exit customer_power_ctrl_exit(void) |
| 139 | { |
| 140 | platform_driver_unregister(&customer_power_ctrl_driver); |
| 141 | } |
| 142 | module_exit(customer_power_ctrl_exit); |
| 143 | |
| 144 | MODULE_DESCRIPTION("customer power pin driver"); |
| 145 | MODULE_LICENSE("GPL"); |