1 #include <linux/module.h>
2 #include <linux/kernel.h>
5 #include <linux/gpio.h>
6 #include <linux/input.h>
7 #include <linux/platform_device.h>
10 #include <linux/uaccess.h>
11 #include <linux/miscdevice.h>
12 #include <linux/circ_buf.h>
13 #include <linux/interrupt.h>
14 #include <mach/spi_fpga.h>
15 #include <linux/delay.h>
18 #define D(x...) printk(x)
23 static int misc_opened;
25 #define AP_TD_UNDEFINED_GBIN5 FPGA_PIO2_02
26 #define AP_RESET_TD FPGA_PIO2_04
27 #define AP_SHUTDOWN_TD_PMU FPGA_PIO2_05
28 #define AP_PW_EN_TD FPGA_PIO2_03
30 #define PIN_BPSEND_ACK RK2818_PIN_PE0
31 #define PIN_APSEND_ACK RK2818_PIN_PF7
33 static int bp_power_on(void)
37 ret = gpio_request(AP_TD_UNDEFINED_GBIN5, NULL);
39 printk("%s:failed to request fpga s %d\n",__FUNCTION__,__LINE__);
42 ret = gpio_request(AP_RESET_TD, NULL);
44 printk("%s:failed to request fpga s %d\n",__FUNCTION__,__LINE__);
49 ret = gpio_request(AP_SHUTDOWN_TD_PMU, NULL);
51 printk("%s:failed to request fpga %d\n",__FUNCTION__,__LINE__);
55 ret = gpio_request(AP_PW_EN_TD, NULL);
57 printk("%s:failed to request fpga %d\n",__FUNCTION__,__LINE__);
61 gpio_set_value(AP_TD_UNDEFINED_GBIN5, 1);
62 gpio_direction_output(AP_TD_UNDEFINED_GBIN5, 1);
63 gpio_direction_input(AP_RESET_TD);
65 gpio_set_value(AP_SHUTDOWN_TD_PMU, 0);
66 gpio_direction_output(AP_SHUTDOWN_TD_PMU, 0);
68 gpio_set_value(AP_PW_EN_TD, 0);
69 gpio_direction_output(AP_PW_EN_TD, 0);
71 gpio_set_value(AP_PW_EN_TD, 1);
73 gpio_set_value(AP_PW_EN_TD, 0);
77 gpio_free(AP_SHUTDOWN_TD_PMU);
79 gpio_free(AP_RESET_TD);
81 gpio_free(AP_TD_UNDEFINED_GBIN5);
88 static int bp_power_off(void)
90 D("+++--++++++%s_________ \r\n",__FUNCTION__);
92 gpio_set_value(AP_TD_UNDEFINED_GBIN5, 0);
94 gpio_set_value(AP_PW_EN_TD, 0);
95 //gpio_direction_output(AP_PW_EN_TD, 0);
97 gpio_set_value(AP_PW_EN_TD, 1);
99 gpio_set_value(AP_PW_EN_TD, 0);
102 gpio_set_value(AP_SHUTDOWN_TD_PMU, 1);
104 // gpio_free(AP_PW_EN_TD);
105 D("++++--+++++%s ok_________\r\n",__FUNCTION__);
110 static int ste_open(struct inode *inode, struct file *file)
119 static int ste_release(struct inode *inode, struct file *file)
126 static int ste_ioctl(struct inode *inode,struct file *file, unsigned int cmd, unsigned long arg)
129 D("%s cmd %d\n", __func__, _IOC_NR(cmd));
131 case STE_IOCTL_EN_APSEND_ACK:
132 D("%s:STE_IOCTL_EN_APSEND_ACK\n");
133 gpio_direction_output(PIN_APSEND_ACK,GPIO_LOW);
135 gpio_direction_output(PIN_APSEND_ACK,GPIO_HIGH);
138 case STE_IOCTL_GET_ACK:
139 val = gpio_get_value(PIN_BPSEND_ACK);
140 D("%s:STE_IOCTL_GET_ACK pin status is %d\n",__func__,val);
141 return put_user(val, (unsigned long __user *)arg);
143 case STE_IOCTL_POWER_ON:
144 D("%s:STE_IOCTL_POWER_ON\n",__func__);
147 case STE_IOCTL_POWER_OFF:
148 D("%s:STE_IOCTL_POWER_OFF\n",__func__);
152 pr_err("%s: invalid cmd %d\n", __func__, _IOC_NR(cmd));
158 static struct file_operations ste_fops = {
159 .owner = THIS_MODULE,
161 .release = ste_release,
165 static struct miscdevice ste_misc = {
166 .minor = MISC_DYNAMIC_MINOR,
171 static int ste_probe(struct platform_device *pdev)
174 D("%s-----------\n",__FUNCTION__);
176 rc = misc_register(&ste_misc);
178 pr_err("%s: could not register misc device\n", __func__);
179 // goto err_unregister_input_device;
184 static struct platform_driver ste_driver = {
192 static int __init ste_init(void)
194 return platform_driver_register(&ste_driver);
197 static void __exit ste_exit(void)
199 platform_driver_unregister(&ste_driver);
202 module_init(ste_init);
203 module_exit(ste_exit);