1 /*
2  * Copyright  2017 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __ROM_API_H_
10 #define __ROM_API_H_
11 
12 /* Component ID definition, used by tools. */
13 #ifndef FSL_COMPONENT_ID
14 #define FSL_COMPONENT_ID "platform.drivers.rom_api"
15 #endif
16 
17 // Power APIs
18 typedef struct _PWRD
19 {
20     void (*set_pll)(unsigned int cmd[], unsigned int resp[]);
21     void (*set_power)(unsigned int cmd[], unsigned int resp[]);
22     void (*set_fro_frequency)(unsigned frequency);
23     void (*power_mode_configure)(unsigned int power_mode, unsigned int peripheral_ctrl);
24     void (*set_aclkgate)(unsigned aclkgate);
25     unsigned (*get_aclkgate)(void);
26 } PWRD_API_T;
27 
28 // Integer divide API routines
29 typedef struct
30 {
31     int quot; // Quotient
32     int rem;  // Remainder
33 } IDIV_RETURN_T;
34 
35 typedef struct
36 {
37     unsigned quot; // Quotient
38     unsigned rem;  // Reminder
39 } UIDIV_RETURN_T;
40 
41 typedef struct
42 {
43     int (*sidiv)(int numerator, int denominator);                         // Signed integer division
44     unsigned (*uidiv)(unsigned numerator, unsigned denominator);          // Unsigned integer division
45     IDIV_RETURN_T (*sidivmod)(int numerator, int denominator);            // Signed integer division with remainder
46     UIDIV_RETURN_T (*uidivmod)(unsigned numerator, unsigned denominator); // Unsigned integer division with remainder
47 } ROM_DIV_API_T;
48 
49 // The master structure that defines the table of all ROM APIs on the device (a.k.a ROM Driver table)
50 typedef struct _ROM_API
51 {
52     const unsigned int reserved3[3]; // Offsets 0, 4, 8
53     const PWRD_API_T *pPWRD;         // Offset 0xC. Power APIs function table base address
54     const ROM_DIV_API_T *divApiBase; // Offset 0x10. Integer division routines function table base address
55     const unsigned int reserved7[7]; // Offsets 0x14 - 0x2C
56 } LPC_ROM_API_T;
57 
58 #define ROM_DRIVER_BASE (0x0F001FF8UL)
59 
60 // Define a pointer to the master table
61 #define LPC_ROM_API (*(LPC_ROM_API_T **)ROM_DRIVER_BASE)
62 
63 // Use like this:
64 // ROM_DIV_API_T const *pROMDiv = LPC_ROM_API->divApiBase;             // Create and initialize a pointer to the DIVIDE
65 // functions table int32_t result;                                                     // Declare an int variable result
66 // = pROMDiv->sidiv(-99, 6);                                    // Call the sidiv routine, result now contains -99/6 =
67 // -16 ROM_DIV_API_T const *pPwr = LPC_ROM_API->pPWRD;                     // Create and initialize a pointer to the
68 // power API functions table pPwr->set_power((uint32_t *)&cmd_table, (uint32_t *)&result_table); // Call the set_power
69 // routine
70 
71 // Alternate form
72 #define LPC_PWRD_API ((const PWRD_API_T *)((*(LPC_ROM_API_T **)(ROM_DRIVER_BASE))->pPWRD))
73 #define LPC_DIVD_API ((ROM_DIV_API_T *)((*(LPC_ROM_API_T **)(ROM_DRIVER_BASE))->divApiBase))
74 
75 // Use like this:
76 // LPC_PWRD_API->set_power((uint32_t *)&cmd_table, (uint32_t *)&result_table); // Call the set_power routine
77 
78 #endif // rom_api.h
79