blob: 4ad03c55e45b1317532448c3026a1b5b8c7d56db [file] [log] [blame]
b.liu4e243dc2023-11-27 11:20:00 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
r.xiao06db9a12024-04-14 18:51:15 -07004#include <stdbool.h>
5#include <time.h>
b.liu4e243dc2023-11-27 11:20:00 +08006
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11
r.xiao06db9a12024-04-14 18:51:15 -070012#include <linux/ioctl.h>
13#include <linux/types.h>
14
15struct 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/*----------------------------------------------------------*/
37struct 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
61typedef 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.xiaod94654a2024-04-22 02:47:51 -070079#define SC_LIBIRQ_MAX (200)
r.xiao06db9a12024-04-14 18:51:15 -070080
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 */
96int 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 */
105int 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 */
115int 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 */
125int 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 */
135int 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 */
145int sc_irq_get_wake(unsigned int line, int *en);
146
r.xiao917e64f2024-04-22 04:18:28 -0700147typedef 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.xiao06db9a12024-04-14 18:51:15 -0700155
156
r.xiao917e64f2024-04-22 04:18:28 -0700157//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.xiao3bddfa32024-04-24 02:56:46 -0700158int line_gpio[4]={21, 22, 23 ,24};//this is the line match gpio
b.liu4e243dc2023-11-27 11:20:00 +0800159
160typedef void (*irq_handler)(void);
161
r.xiao917e64f2024-04-22 04:18:28 -0700162int lynq_irq_install(int line, irq_handler irq_handler, trig_type_e trig_type);
b.liu4e243dc2023-11-27 11:20:00 +0800163
164int lynq_irq_uninstall(int line);
165
166int lynq_irq_set_type(int line, int trig_type);
167
168int lynq_irq_get_type(int line);
169
170int lynq_irq_set_wake(int line, int en);
171
172int lynq_irq_get_wake(int line);
173
174
175#ifdef __cplusplus
176}
177#endif