b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
r.xiao | 06db9a1 | 2024-04-14 18:51:15 -0700 | [diff] [blame] | 4 | #include <stdbool.h> |
| 5 | #include <time.h> |
b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 6 | |
| 7 | #ifdef __cplusplus |
| 8 | extern "C" { |
| 9 | #endif |
| 10 | |
| 11 | |
r.xiao | 06db9a1 | 2024-04-14 18:51:15 -0700 | [diff] [blame] | 12 | #include <linux/ioctl.h> |
| 13 | #include <linux/types.h> |
| 14 | |
| 15 | struct sc_irq_info { |
| 16 | unsigned int line; |
| 17 | unsigned int type; |
| 18 | }; |
| 19 | |
| 20 | #define SC_IRQ_IOC_MAGIC 'I' |
| 21 | |
| 22 | /*ioctl cmd usd by device*/ |
| 23 | #define SC_IRQ_INSTALL _IOW(SC_IRQ_IOC_MAGIC, 1, char *) |
| 24 | #define SC_IRQ_SET_TYPE _IOW(SC_IRQ_IOC_MAGIC, 2, char *) |
| 25 | #define SC_IRQ_SET_WAKE _IOW(SC_IRQ_IOC_MAGIC, 3, char *) |
| 26 | #define SC_IRQ_GET_WAKE _IOW(SC_IRQ_IOC_MAGIC, 4, char *) |
| 27 | #define SC_IRQ_UNINSTALL _IOW(SC_IRQ_IOC_MAGIC, 5, char *) |
| 28 | |
| 29 | #define SC_IRQ_GET_STATUS _IOW(SC_IRQ_IOC_MAGIC, 6, char *) |
| 30 | #define SC_IRQ_CLEAR_STATUS _IOW(SC_IRQ_IOC_MAGIC, 7, char *) |
| 31 | |
| 32 | #define SC_IRQ_DEV "/dev/sc_irq" |
| 33 | |
| 34 | |
| 35 | |
| 36 | /*----------------------------------------------------------*/ |
| 37 | struct sc_pm_info { |
| 38 | unsigned int sleep_time; /* ms */ |
| 39 | unsigned int wake_event; |
| 40 | }; |
| 41 | |
| 42 | #define SC_PM_WL_EVENT_EXT0 ((unsigned int)1 << 0) |
| 43 | #define SC_PM_WL_EVENT_EXT1 ((unsigned int)1 << 1) |
| 44 | #define SC_PM_WL_EVENT_EXT2 ((unsigned int)1 << 2) |
| 45 | #define SC_PM_WL_EVENT_EXT3 ((unsigned int)1 << 3) |
| 46 | #define SC_PM_WL_EVENT_EXT4 ((unsigned int)1 << 4) |
| 47 | #define SC_PM_WL_EVENT_EXT5 ((unsigned int)1 << 5) |
| 48 | #define SC_PM_WL_EVENT_EXT6 ((unsigned int)1 << 6) |
| 49 | #define SC_PM_WL_EVENT_EXT7 ((unsigned int)1 << 7) |
| 50 | |
| 51 | #define SC_PM_IOC_MAGIC 'P' |
| 52 | |
| 53 | /*ioctl cmd usd by device*/ |
| 54 | #define SC_PM_WL_SET _IOW(SC_PM_IOC_MAGIC, 1, char *) |
| 55 | #define SC_PM_WL_CLEAR _IOW(SC_PM_IOC_MAGIC, 2, char *) |
| 56 | #define SC_PM_WL_GET _IOW(SC_PM_IOC_MAGIC, 3, char *) |
| 57 | |
| 58 | #define SC_PM_DEV "/dev/sc_pm" |
| 59 | |
| 60 | |
| 61 | typedef void (*irq_handler)(void); |
| 62 | |
| 63 | #define SC_LIBIRQ_EXT0 (0) |
| 64 | #define SC_LIBIRQ_EXT1 (1) |
| 65 | #define SC_LIBIRQ_EXT2 (2) |
| 66 | #define SC_LIBIRQ_EXT3 (3) |
| 67 | #define SC_LIBIRQ_EXT4 (4) |
| 68 | #define SC_LIBIRQ_EXT5 (5) |
| 69 | #define SC_LIBIRQ_EXT6 (6) |
| 70 | #define SC_LIBIRQ_EXT7 (7) |
| 71 | #define SC_LIBIRQ_EXT8 (8) |
| 72 | #define SC_LIBIRQ_EXT9 (9) |
| 73 | #define SC_LIBIRQ_EXT10 (10) |
| 74 | #define SC_LIBIRQ_EXT11 (11) |
| 75 | #define SC_LIBIRQ_EXT12 (12) |
| 76 | #define SC_LIBIRQ_EXT13 (13) |
| 77 | #define SC_LIBIRQ_EXT14 (14) |
| 78 | #define SC_LIBIRQ_EXT15 (15) |
r.xiao | d94654a | 2024-04-22 02:47:51 -0700 | [diff] [blame] | 79 | #define SC_LIBIRQ_MAX (200) |
r.xiao | 06db9a1 | 2024-04-14 18:51:15 -0700 | [diff] [blame] | 80 | |
| 81 | #define SC_LIBIRQ_TYPE_RISING (0) |
| 82 | #define SC_LIBIRQ_TYPE_FALLING (1) |
| 83 | #define SC_LIBIRQ_TYPE_LEVEL_HIGH (2) |
| 84 | #define SC_LIBIRQ_TYPE_LEVEL_LOW (3) |
| 85 | #define SC_LIBIRQ_TYPE_MAX (4) |
| 86 | |
| 87 | /* |
| 88 | * Add a handler for an interrupt line. |
| 89 | * |
| 90 | * line : The interrupt line |
| 91 | * handler : Function to be called when the IRQ occurs. |
| 92 | * trig_type : rising edge or fallling edge |
| 93 | * |
| 94 | * return 0 if succeed, others failed |
| 95 | */ |
| 96 | int sc_irq_install(unsigned int line, irq_handler handler, int trig_type); |
| 97 | |
| 98 | /* |
| 99 | * free an interrupt allocated with sc_irq_install. |
| 100 | * |
| 101 | * line : The interrupt line |
| 102 | * |
| 103 | * return 0 if succeed, others failed |
| 104 | */ |
| 105 | int sc_irq_uninstall(unsigned int line); |
| 106 | |
| 107 | /* |
| 108 | * set the irq trigger type for an irq. |
| 109 | * |
| 110 | * line : The interrupt line |
| 111 | * trig_type : rising edge or fallling edge |
| 112 | * |
| 113 | * return 0 if succeed, others failed |
| 114 | */ |
| 115 | int sc_irq_set_type(unsigned int line, int trig_type); |
| 116 | |
| 117 | /* |
| 118 | * get the irq trigger type for an irq. |
| 119 | * |
| 120 | * line : The interrupt line |
| 121 | * trig_type : edge or level type |
| 122 | * |
| 123 | * return 0 if succeed, others failed |
| 124 | */ |
| 125 | int sc_irq_get_type(unsigned int line, int *trig_type); |
| 126 | |
| 127 | /* |
| 128 | * control irq power management wakeup. |
| 129 | * |
| 130 | * line : The interrupt line |
| 131 | * en : enable/disable power management wakeup |
| 132 | * |
| 133 | * return 0 if succeed, others failed |
| 134 | */ |
| 135 | int sc_irq_set_wake(unsigned int line, int en); |
| 136 | |
| 137 | /* |
| 138 | * get the irq awake status for an irq. |
| 139 | * |
| 140 | * line : The interrupt line |
| 141 | * en : enable/disable power management wakeup |
| 142 | * |
| 143 | * return 0 if succeed, others failed |
| 144 | */ |
| 145 | int sc_irq_get_wake(unsigned int line, int *en); |
| 146 | |
r.xiao | 917e64f | 2024-04-22 04:18:28 -0700 | [diff] [blame] | 147 | typedef enum |
| 148 | { |
| 149 | Rising_edge_trigger = 0,//:上升沿触发 |
| 150 | Falling_edge_trigger = 1,//:下降沿触发 |
| 151 | High_level_trigger = 2,//:高电平触发 |
| 152 | Low_level_trigger = 3,//:低电平触发 |
| 153 | |
| 154 | }trig_type_e; |
r.xiao | 06db9a1 | 2024-04-14 18:51:15 -0700 | [diff] [blame] | 155 | |
| 156 | |
r.xiao | 917e64f | 2024-04-22 04:18:28 -0700 | [diff] [blame] | 157 | //int line_gpio[15]={-1,48,49,50,51,52,53,54,119,128,129,-1,131,-1,125};//this is the line match gpio |
r.xiao | 3bddfa3 | 2024-04-24 02:56:46 -0700 | [diff] [blame] | 158 | int line_gpio[4]={21, 22, 23 ,24};//this is the line match gpio |
b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 159 | |
| 160 | typedef void (*irq_handler)(void); |
| 161 | |
r.xiao | 917e64f | 2024-04-22 04:18:28 -0700 | [diff] [blame] | 162 | int lynq_irq_install(int line, irq_handler irq_handler, trig_type_e trig_type); |
b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 163 | |
| 164 | int lynq_irq_uninstall(int line); |
| 165 | |
| 166 | int lynq_irq_set_type(int line, int trig_type); |
| 167 | |
| 168 | int lynq_irq_get_type(int line); |
| 169 | |
| 170 | int lynq_irq_set_wake(int line, int en); |
| 171 | |
| 172 | int lynq_irq_get_wake(int line); |
| 173 | |
| 174 | |
| 175 | #ifdef __cplusplus |
| 176 | } |
| 177 | #endif |