blob: 0566df9d2ef3a726e93c47cef7744bc32902a032 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2001
8*
9*****************************************************************************/
10
11/*****************************************************************************
12 *
13 * Filename:
14 * ---------
15 * dcl_PWM.h
16 *
17 * Project:
18 * --------
19 * Maui
20 *
21 * Description:
22 * ------------
23 * Header file of DCL (Driver Common Layer) for PWM.
24 *
25 * Author:
26 * -------
27 * -------
28 *
29 *============================================================================
30 * HISTORY
31 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
32 *------------------------------------------------------------------------------
33 * removed!
34 * removed!
35 * removed!
36 *
37 * removed!
38 * removed!
39 * removed!
40 *
41 * removed!
42 * removed!
43 * removed!
44 *
45 * removed!
46 * removed!
47 * removed!
48 *
49 * removed!
50 * removed!
51 * removed!
52 *
53 * removed!
54 * removed!
55 * removed!
56 *
57 * removed!
58 * removed!
59 * removed!
60 *
61 * removed!
62 * removed!
63 * removed!
64 *
65 * removed!
66 * removed!
67 * removed!
68 *
69 * removed!
70 * removed!
71 * removed!
72 *
73 * removed!
74 * removed!
75 * removed!
76 *
77 * removed!
78 * removed!
79 * removed!
80 *
81 * removed!
82 * removed!
83 * removed!
84 *
85 * removed!
86 * removed!
87 * removed!
88 *
89 * removed!
90 * removed!
91 * removed!
92 *
93 * removed!
94 * removed!
95 * removed!
96 *
97 * removed!
98 * removed!
99 * removed!
100 *
101 * removed!
102 * removed!
103 * removed!
104 *
105 * removed!
106 * removed!
107 * removed!
108 *
109 * removed!
110 * removed!
111 * removed!
112 *
113 * removed!
114 * removed!
115 * removed!
116 *
117 *------------------------------------------------------------------------------
118 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
119 *============================================================================
120 ****************************************************************************/
121#ifdef DCL_DEFINITION_STRUCT
122#ifndef __DCL_PWM_H_STRUCT__
123#define __DCL_PWM_H_STRUCT__
124//#include "kal_non_specific_general_types.h" //it is empty ,we don't delete it in order to avoid vilating HAL rule 1
125
126#include "kal_general_types.h"
127#define PWM_OUTPUT_LOW 0
128#define PWM_OUTPUT_HIGH 1
129//******************************************
130#define PWM_MAX_FREQ 50000
131#define PWM_MAX_DUTY 100
132#define PWM_MIN_FREQ 50
133#define PWM_MIN_DUTY 1
134//******************************************
135typedef struct
136{
137 DCL_UINT8 pitch; /*note vlaue*/
138 DCL_UINT8 volume; /*note volume*/
139 DCL_UINT16 on_duration; /* in ms */
140 DCL_UINT16 off_duration; /* in ms */
141}BuzNoteStruct;
142
143typedef struct
144{
145 DCL_UINT8 volume;
146 DCL_UINT8 stop;
147 DCL_UINT32 handle; /*GPT handle*/
148 BuzNoteStruct NotesData;
149 kal_bool (*GetNotesCallbac)(BuzNoteStruct *Buz);
150 void (*EndofAlterPlay)(void);
151}ALterNoteStruct;
152
153/* PWM wrok mode enumerate*/
154typedef enum
155{
156 PWM_FIFO_MODE=0,
157 PWM_MEMO_MODE,
158 PWM_OLD_MODE,
159 PWM_RANDOM_MODE,
160 PWM_MODE_COUNT
161}pwm_mode_e;
162
163/*PWM FIFO mode data structure.[more detail in spec]*/
164typedef struct
165{
166 kal_uint32 data0;
167 kal_uint32 data1;
168 kal_uint16 repeat_count; /* 0 means endless repeat */
169 kal_uint8 stop_bitpos; /* 0~63*/
170 kal_uint16 high_dur; /* must>0. When set to N, the duration is N+1 clocks. */
171 kal_uint16 low_dur; /* must>0. When set to N, the duration is N+1 clocks. */
172 kal_uint16 guard_dur; /* must>0. When set to N, the duration is N+1 clocks. */
173 kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
174 kal_uint8 guard_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
175 void (*pwm_callback)(kal_uint32 pwm_num);
176}pwm_fifo_para_s;
177
178/*PWM memory mode data structure.[more detail in spec] */
179typedef struct
180{
181 kal_uint32 *buf_addr;
182 kal_uint16 buf_size;
183 kal_uint16 repeat_count; /* 0 means endless repeat */
184 kal_uint8 stop_bitpos; /* 0~31 in the last 32bits*/
185 kal_uint16 high_dur; /* must>0. When set to N, the duration is N+1 clocks. */
186 kal_uint16 low_dur; /* must>0. When set to N, the duration is N+1 clocks. */
187 kal_uint16 guard_dur; /* must>0. When set to N, the duration is N+1 clocks. */
188 kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
189 kal_uint8 guard_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
190 void (*pwm_callback)(kal_uint32 pwm_num);
191}pwm_memo_para_s;
192
193/*PWM old mode data structure.[more detail in spec]*/
194typedef struct
195{
196 kal_uint16 data_width;
197 kal_uint16 threshold;
198 kal_uint16 repeat_count; /* 0 means endless repeat */
199 kal_uint16 guard_dur; /* must>0. When set to N, the duration is N+1 clocks. */
200 kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
201 kal_uint8 guard_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
202 void (*pwm_callback)(kal_uint32 pwm_num);
203}pwm_old_para_s;
204
205/*PWM random mode data structure.[more detail in spec]*/
206typedef struct
207{
208 kal_uint32 *buf0_addr;
209 kal_uint32 *buf1_addr;
210 kal_uint16 buf0_size; /* must>0 */
211 kal_uint16 buf1_size; /* must>0 */
212 kal_uint16 high_dur; /* must>0. When set to N, the duration is N+1 clocks. */
213 kal_uint16 low_dur; /* must>0. When set to N, the duration is N+1 clocks. */
214 kal_uint8 idle_output; /* PWM_OUTPUT_LOW or PWM_OUTPUT_HIGH */
215 void (*pwm_invalid_cb)(kal_uint32 pwm_num, kal_uint8 buf_num);
216 void (*pwm_underflow_cb)(kal_uint32 pwm_num);
217}pwm_random_para_s;
218
219typedef struct
220{
221 DCL_UINT32 clksrc; //the Clock source of the PWM module.
222 DCL_UINT32 clkdiv; //The Clock Divisor value.
223}PWM_CONFIG_T;
224
225#define PWM_CONFIGS \
226 PWM_CONFIG_T rPWMConfig;
227
228#ifdef __BUILD_DOM__
229/*
230* The ALERTER Command values in DCL_CTRL_CMD_T Enum of dcl.h
231* DCL_CTRL_DATA_T Define the Control data structure for each module's command
232*/
233typedef enum
234{
235 PWM_CMD_SEQ_OPEN, //This command is to open the PWM channel under the Sequential mode.
236 PWM_CMD_SEQ_START, //This command is to enable PWM output under the Sequential mode.
237 PWM_CMD_SEQ_STOP, //This command is to stop PWM output under the Sequential mode.
238 PWM_CMD_SEQ_CLOSE, //This command is to Close the PWM channel under the Sequential mode.
239 PWM_CONFIG_FREQ_STEPS, //The command is to set the output frequency and the steps.it is used by the Camera AF lens driver.
240 PWM_CMD_SET_DUTY, //The function is to set the output duty value, it should not larger than the Steps in the above function.it is used by the Camera AF lens driver.
241 PWM_CMD_OPEN, //This command is to Open PWM channel.This command should be called before any other configuration function.
242 PWM_CMD_CLOSE, //The function is to close the PWM channel.it should be called after stop the PWM channel.
243 PWM_CMD_START, //This command is to Start the PWM channel output.It is called after all the configuration finished
244 PWM_CMD_STOP, //This command is to stop the PWM channel output.
245 PWM_CMD_CONFIG, //This command is to configure the PWM channel working mode and setting the accoring mode parameter.
246 PWM_CMD_CONFIG_OLD, //This command is to configure the PWM1 output frequency and duty cycle.the function is to generate the simpliest periodical output signal.
247 PWM_CMD_SET_BUF_VALID, //Set buffer status to be valid and update the buffer data.the function is called when receiving the finish interrupt under the random mode.it is responsible to call the function to update the buffer of the user.
248 PWM_CMD_SET_DELAY, //This command is to set the delay time during the adjacent channels under the Sequential mode.
249 //PWM_CMD_TEST_SEL, should remove.
250 PWM_CMD_GET_CURRENT_LEVEL, //This command is to get current PWM1 output level.
251 PWM_CMD_GET_CURRENT_DUTY, //This command is to get current PWM1 output duty cycle.
252 PWM_CMD_GET_CURRENT_FREQ, //This command is to get current PWM1 output duty cycle.
253 ALERTER_CMD_CONFIGURE, //configure ALerter freq and duty.
254 ALERTER_CMD_START, //Start ALERTER module.
255 ALERTER_CMD_STOP, //Stop ALERTER module.
256 ALERTER_CMD_PWROPEN,
257 ALERTER_CMD_OUTPUT,
258 ALERTER_CMD_PLAYNOTES,
259 ALERTER_CMD_STOPNOTES,
260 ALERTER_CMD_SETBUZVOLUME,
261 ALERTER_CMD_GETLEVEL,
262}DCL_CTRL_CMD_T;
263#else
264#define PWM_CMDS \
265 PWM_CMD_SEQ_OPEN, \
266 PWM_CMD_SEQ_START, \
267 PWM_CMD_SEQ_STOP, \
268 PWM_CMD_SEQ_CLOSE, \
269 PWM_CONFIG_FREQ_STEPS, \
270 PWM_CMD_START, \
271 PWM_CMD_STOP, \
272 PWM_CMD_GET_CURRENT_LEVEL, \
273 PWM_CMD_GET_CURRENT_DUTY, \
274 PWM_CMD_GET_CURRENT_FREQ, \
275 PWM_CMD_CONFIG, \
276 PWM_CMD_CONFIG_OLD, \
277 PWM_CMD_SET_BUF_VALID, \
278 PWM_CMD_SET_DELAY, \
279 PWM_CMD_SET_DUTY, \
280 PWM_CMD_TEST_SEL, \
281 PWM_CMD_OPEN, \
282 PWM_CMD_CLOSE,
283
284#define ALERTER_CMDS \
285 ALERTER_CMD_CONFIGURE, \
286 ALERTER_CMD_START, \
287 ALERTER_CMD_STOP, \
288 ALERTER_CMD_PWROPEN, \
289 ALERTER_CMD_OUTPUT, \
290 ALERTER_CMD_PLAYNOTES, \
291 ALERTER_CMD_STOPNOTES, \
292 ALERTER_CMD_SETBUZVOLUME, \
293 ALERTER_CMD_GETLEVEL,
294
295#endif
296
297/* For PWM_CMD_SEQ_START command parameter. */
298typedef struct
299{
300 DCL_UINT8 uEnCount; //the PWM Channel Group of the Sequential mode
301}PWM_CTRL_SS_T;
302
303/* For PWM_CMD_CLK_INIT command parameter. */
304typedef struct
305{
306 DCL_UINT32 u4ClkSel; //the Clock source of the PWM module.
307 DCL_UINT32 u4ClkDiv; // The Clock Divisor value.
308}PWM_CTRL_CI_T;
309
310/* For PWM_CMD_SET_BUF_VALID command parameter. */
311typedef struct
312{
313 DCL_UINT32 *pu4BufAddr; //the buffer address of the update data.
314 DCL_UINT16 u2BufSize; //the buffer size.
315 DCL_BOOL fgIsBuf0; //the flag indicates whether buffer 0 is to be update
316}PWM_CTRL_SBV_T;
317
318/* For PWM_CMD_SET_DELAY command parameter. */
319typedef struct
320{
321 DCL_UINT32 u4ClkSel; // the clock unit of the delay_cnt
322 DCL_UINT16 u2DelayCnt; //the delay clock count of the two channels.
323}PWM_CTRL_SD_T;
324
325/* For PWM_CMD_TEST_SEL command parameter. */
326typedef struct
327{
328 DCL_BOOLEAN bTestSel;
329}PWM_CTRL_TS_T;
330
331/* For PWM_CMD_CONFIG command parameter. */
332typedef struct
333{
334 DCL_UINT32 mode; //Set the work mode of the PWM channel.
335 void *para; // The mode parameter.
336}PWM_CTRL_CONFIG_T;
337
338/* For PWM_CMD_CONFIG_OLD command parameter. */
339typedef struct
340{
341 kal_uint32 freq; // the PWM channel output frequency.
342 kal_uint8 duty; // the duty cycle of the high level under the periodical output.
343}PWM_CMD_CONFIG_OLD_T;
344
345/*For
346* PWM_CMD_GET_CURRENT_LEVEL,
347* PWM_CMD_GET_CURRENT_DUTY,
348* PWM_CMD_GET_CURRENT_FREQ,
349* command parameter
350*/
351typedef struct
352{
353 DCL_UINT8 pwm_level;//return value of the command , the current level value
354 DCL_UINT8 pwm_duty; //return value of the command ,the current setting duty cycle value
355 DCL_UINT32 pwm_freq;//return value of the command ,the current setting frequency value
356}PWM_DATA_T;
357
358/*For PWM_CMD_SET_DUTY command parameter.*/
359typedef struct
360{
361 DCL_UINT16 duty; //the output duty value (0~steps).
362}PWM_DUTY_T;
363
364/*For PWM_CONFIG_FREQ_STEPS command parameter.*/
365typedef struct
366{
367 kal_uint32 freq; //the output frequency.
368 kal_uint16 steps; //the lens driver steps.
369}PWM_CONFIG_FREQ_STEPS_T;
370
371//#if !defined(DRV_ALERTER_NOT_EXIST)
372typedef struct
373{
374 DCL_UINT32 freq;
375 DCL_UINT8 duty;
376}ALERTER_CONFIGURE_T;
377
378typedef struct
379{
380 DCL_BOOL poweron;
381}ALERTER_PWROPEN_T;
382
383typedef struct
384{
385 kal_bool (*GetNotecallbac)(BuzNoteStruct *Buz);
386 void (*endofAlter)(void);
387}ALERTER_PLAYNOTE_T;
388
389typedef struct
390{
391 DCL_UINT8 volumn;
392}ALERTER_SETVOLUMN_T;
393
394typedef struct
395{
396 DCL_UINT8 mode;
397 DCL_UINT8 clock;
398}ALERTER_CONFIG_T;
399
400typedef struct
401{
402 kal_uint8 output;
403}ALERTER_OUTPUT_T;
404
405typedef struct
406{
407 kal_uint8 level;
408}ALERTER_LEVEL_T;
409
410#define ALERTER_CTRLS \
411 ALERTER_CONFIGURE_T ralertConfigure; \
412 ALERTER_PWROPEN_T ralertPwrOpen; \
413 ALERTER_PLAYNOTE_T ralertPlayNote; \
414 ALERTER_SETVOLUMN_T ralertSetVolumn; \
415 ALERTER_CONFIG_T ralertConfig; \
416 ALERTER_OUTPUT_T ralertOutput; \
417 ALERTER_LEVEL_T ralertlevel;
418
419
420#define PWM_CTRLS \
421 PWM_CTRL_SS_T rPWMCtrlSS; \
422 PWM_CTRL_CI_T rPWMCtrlCI; \
423 PWM_CTRL_SBV_T rPWMCtrlSBV; \
424 PWM_CTRL_SD_T rPWMCtrlSD; \
425 PWM_CTRL_TS_T rPWMCtrlTS; \
426 PWM_DUTY_T rPWMCtrlDuty; \
427 PWM_DATA_T rPWMSaveData; \
428 PWM_CTRL_CONFIG_T rPWMConfig; \
429 PWM_CONFIG_FREQ_STEPS_T rPWMFreqConfig; \
430 PWM_CMD_CONFIG_OLD_T rPWMConfigOld;
431
432#endif // #ifndef __DCL_PWM_H_STRUCT__
433#endif // #ifdef DCL_DEFINITION_STRUCT
434
435
436#ifdef DCL_DEFINITION_PROTOTYPE
437#ifndef __DCL_PWM_H_PROTOTYPE__
438#define __DCL_PWM_H_PROTOTYPE__
439
440/*************************************************************************
441* FUNCTION
442* DclPWM_Close
443*
444* DESCRIPTION
445* This function is to close the software layer of PWM module.
446*
447* CALLS
448* It is called to close PWM(1~6) module
449*
450* PARAMETERS
451* None
452*
453* RETURNS
454* DCL_STATUS_OK
455* STATUS_INVALID_ARGUMENT: invalid arguments
456*
457* GLOBALS AFFECTED
458* external_global
459*************************************************************************/
460extern DCL_STATUS DclPWM_Close(DCL_HANDLE handle);
461/*************************************************************************
462* FUNCTION
463* DclPWM_Configure
464*
465* DESCRIPTION
466* This function is to configure the PWM module. Include clock sources and div vaules.
467*
468* CALLS
469* It is called to configure of the PWM module.
470*
471* PARAMETERS
472* handle: - a valid handle return by DclPWM_Configure()
473*
474* RETURNS
475* STATUS_OK: command is executed successfully.
476* STATUS_FAIL: command is failed.
477*
478* GLOBALS AFFECTED
479* external_global
480*************************************************************************/
481extern DCL_STATUS DclPWM_Configure(DCL_HANDLE handle, DCL_CONFIGURE_T *configure);
482/*************************************************************************
483* FUNCTION
484* DclPWM_Control
485*
486* DESCRIPTION
487* This function is to send command to control the PWM module.
488* All command
489*
490* CALLS
491* It is called to send command to control the PWM module.
492*
493* PARAMETERS
494* handle: - a valid handle return by DclPWM_Open()
495* cmd: - a control command for PWM module
496* 1. PWM_CMD_START: to start a PWM timer
497* 2. PWM_CMD_STOP: to stop a PWM timer
498* 3. PWM_CMD_CONFIG: to config a pwm timer.
499* 4. PWM_CMD_CONFIG_OLD
500* 5. PWM_CMD_GET_CURRENT_LEVEL:
501* 6. PWM_CMD_GET_CURRENT_DUTY:
502* 7. PWM_CMD_GET_CURRENT_FREQ:
503* 8. PWM_CMD_OPEN
504* 9. PWM_CMD_CLOSE
505* 10. PWM_CMD_SEQ_OPEN:
506* 11. PWM_CMD_SEQ_START:
507* 12. PWM_CMD_SEQ_STOP:
508* 13. PWM_CMD_SEQ_CLOSE
509* 14. PWM_CMD_SET_BUF_VALID
510* 15. PWM_CMD_SET_DELAY
511* 16. PWM_CMD_TEST_SEL
512* data - for 1. PWM_CMD_START: poiter to a PWM_CTRL_START_T structure
513* 2. PWM_CMD_STOP: a NULL pointer
514* #if !defined(DRV_ALERTER_NOT_EXIST)
515 #define ALERTER_CMDS
516 ALERTER_CMD_CONFIGURE, \
517 ALERTER_CMD_START, \
518 ALERTER_CMD_STOP, \
519 ALERTER_CMD_PWROPEN, \
520 ALERTER_CMD_OUTPUT, \
521 ALERTER_CMD_PLAYNOTES, \
522 ALERTER_CMD_STOPNOTES, \
523 ALERTER_CMD_SETBUZVOLUME,
524 #endif
525* RETURNS
526* STATUS_OK: command is executed successfully.
527* STATUS_FAIL: command is failed.
528* STATUS_INVALID_CMD: It's a invalid command.
529*
530* GLOBALS AFFECTED
531* external_global
532*************************************************************************/
533extern DCL_STATUS DclPWM_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data);
534/*************************************************************************
535* FUNCTION
536* DclPWM_Initialize
537*
538* DESCRIPTION
539* This function is to initialize PWM module, It's should be called during drv_init stage.
540*
541* For PWM, this function do nothing.
542*
543* For RWG, this function create some global variable and LISR, HISR.
544*
545* CALLS
546* It is called to initialize PWM module
547*
548* PARAMETERS
549* None
550*
551* RETURNS
552* DCL_STATUS_OK
553*
554* GLOBALS AFFECTED
555* external_global
556*************************************************************************/
557extern DCL_STATUS DclPWM_Initialize(void);
558/*************************************************************************
559* FUNCTION
560* DclPWM_Open
561*
562* DESCRIPTION
563* This function is to open the software layer PWM module and return a software handle.
564* This function don't open the PWM hardware power or generate out wave.
565* This is only for software layer to avoid multi open by different module.
566*
567* If you want to power on or start PWM hardware , you should send a command by use of DclPWM_Control.
568* CALLS
569* It is called to open PWM module
570*
571* PARAMETERS
572* dev - valid for DCL_PWM1 ~ DCL_PWM6
573* flags - module name that call this fuction.
574*
575* RETURNS
576* DCL_HANDLE_OCCUPIED: - Open failed.
577* STATUS_INVALID_ARGUMENT: - invalid arguments
578* other value: - a valid handle
579*
580* GLOBALS AFFECTED
581* external_global
582*************************************************************************/
583extern DCL_HANDLE DclPWM_Open(DCL_DEV dev, DCL_FLAGS flags);
584/*************************************************************************
585* FUNCTION
586* DclPWM_RegisterCallback
587*
588* DESCRIPTION
589* This function is not supported for the PWM module now.
590*
591* PARAMETERS
592* N/A
593*
594* RETURNS
595* STATUS_UNSUPPORTED
596*
597*************************************************************************/
598extern DCL_STATUS DclPWM_RegisterCallback(DCL_HANDLE handle, DCL_EVENT event, PFN_DCL_CALLBACK callback);
599
600#endif // #ifndef __DCL_PWM_H_PROTOTYPE__
601#endif // #ifdef DCL_DEFINITION_PROTOTYPE
602
603