s5j/mct: fix coding style issues
authorIvan <ivan.galkin@samsung.com>
Thu, 9 Mar 2017 13:50:11 +0000 (22:50 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Mon, 17 Apr 2017 10:00:55 +0000 (19:00 +0900)
To follow naming rules and code style MCT code was modified.

Change-Id: I8ccb8eaa4eb480dde9c013dd5c247b24a829d3ca
Signed-off-by: Ivan <ivan.galkin@samsung.com>
os/arch/arm/src/s5j/s5j_mct.c
os/arch/arm/src/s5j/s5j_mct.h
os/arch/arm/src/s5j/s5j_timerisr.c

index fbcec8d..3b3ad85 100644 (file)
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
-static u32 mct_local_get_int_cnt(int mct_id);
-static u32 mct_local_get_tick_cnt(int mct_id);
-u32 mct_local_get_frc_cnt(int mct_id);
-static cycle_t usec2ticks(u64 usec);
-//static bool mct_is_global(int mct_id);
-//static void mct_global_clear_int(int mct_id);
-//static void mct_global_disable_auto_incr(int mct_id);
-//static bool mct_is_global(int mct_id);
-//static void mct_global_clear_int(int mct_id);
-//static void mct_global_disable_auto_incr(int mct_id);
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
-#define CFG                (0x000)
-#define G_CNT_L            (0x100)
-#define G_CNT_U            (0x104)
-#define G_CNT_WSTAT        (0x110)
-#define G_COMP_L(x)        (0x200 + (0x10 * x))
-#define G_COMP_U(x)        (0x204 + (0x10 * x))
-#define G_COMP_ADD_INCR(x) (0x208 + (0x10 * x))
-#define G_TCON             (0x240)
-#define G_INT_CSTAT        (0x244)
-#define G_INT_ENB          (0x248)
-#define G_WSTAT            (0x24C)
-
-#define L_BASE(x)     (0x300 + (0x100 * x))
-#define L_MASK        (0xffffff00)
-
-#define L_TCNTB(x)      (L_BASE(x) + 0x00)
-#define L_TCNTO(x)      (L_BASE(x) + 0x04)
-#define L_ICNTB(x)      (L_BASE(x) + 0x08)
-#define L_ICNTO(x)      (L_BASE(x) + 0x0C)
-#define L_FRCNTB(x)     (L_BASE(x) + 0x10)
-#define L_FRCNTO(x)     (L_BASE(x) + 0x14)
-#define L_TCON(x)       (L_BASE(x) + 0x20)
-#define L_INT_CSTAT(x)  (L_BASE(x) + 0x30)
-#define L_INT_ENB(x)    (L_BASE(x) + 0x34)
-#define L_WSTAT(x)      (L_BASE(x) + 0x40)
-
-#define G_TCON_START_FRC      (1 << 8)
-
-#define G_TCON_AUTO_INCR_ENABLE(x) (1 << ((2 * x) + 1))
-#define G_TCON_COMP_ENABLE(x)      (1 << ((2 * x) + 0))
-
-#define L_TCON_FRC_START      (1 << 3)
-#define L_TCON_INTERVAL_MODE  (1 << 2)
-#define L_TCON_INT_START      (1 << 1)
-#define L_TCON_TIMER_START    (1 << 0)
-
-#define L_INTR_FRC          (1 << 1)
-#define L_INTR_ICNT         (1 << 0)
-
-#define WSTAT_G_CNT_U       (1 << 1)
-#define WSTAT_G_CNT_L       (1 << 0)
-
-#define WSTAT_G_COMP_ADD_INCR(x) (1 << ((x * 4) + 2))
-#define WSTAT_G_COMP_U(x)        (1 << ((x * 4) + 1))
-#define WSTAT_G_COMP_L(x)        (1 << ((x * 4) + 0))
-
-#define WSTAT_G_TCON        (1 << 16)
-
-#define WSTAT_L_TCON        (1 << 3)
-#define WSTAT_L_FRCCNTB     (1 << 2)
-#define WSTAT_L_ICNTB       (1 << 1)
-#define WSTAT_L_TCNTB       (1 << 0)
-
-#define mct_check_wstat(wstat, offset) \
-       do { \
-               if (__raw_readl(mct_base + wstat) & offset) { \
-                       __raw_writel(offset, mct_base + wstat); \
-                       break; \
-               } \
-       } while (1)
-
-#define MCT_DRIVER_FROM_EXCITE
+#define CFG                            (0x000)
+#define G_CNT_L                                (0x100)
+#define G_CNT_U                                (0x104)
+#define G_CNT_WSTAT                    (0x110)
+#define G_COMP_L(x)                    (x)
+#define G_COMP_U(x)                    (4 + x)
+#define G_COMP_ADD_INCR(x)             (8 + x)
+#define G_TCON                         (0x240)
+#define G_INT_CSTAT                    (0x244)
+#define G_INT_ENB                      (0x248)
+#define G_WSTAT                                (0x24C)
+
+#define L_MASK                         (0xffffff00)
+
+#define L_TCNTB(x)                     (x + 0x00)
+#define L_TCNTO(x)                     (x + 0x04)
+#define L_ICNTB(x)                     (x + 0x08)
+#define L_ICNTO(x)                     (x + 0x0C)
+#define L_FRCNTB(x)                    (x + 0x10)
+#define L_FRCNTO(x)                    (x + 0x14)
+#define L_TCON(x)                      (x + 0x20)
+#define L_INT_CSTAT(x)                 (x + 0x30)
+#define L_INT_ENB(x)                   (x + 0x34)
+#define L_WSTAT(x)                     (x + 0x40)
+
+#define G_TCON_START_FRC               (1 << 8)
+
+#define G_TCON_AUTO_INCR_ENABLE(x)     (1 << ((2 * x) + 1))
+#define G_TCON_COMP_ENABLE(x)          (1 << ((2 * x) + 0))
+
+#define L_TCON_FRC_START               (1 << 3)
+#define L_TCON_INTERVAL_MODE           (1 << 2)
+#define L_TCON_INT_START               (1 << 1)
+#define L_TCON_TIMER_START             (1 << 0)
+
+#define WSTAT_G_CNT_U                  (1 << 1)
+#define WSTAT_G_CNT_L                  (1 << 0)
+
+#define WSTAT_G_COMP_ADD_INCR(x)       (1 << ((x * 4) + 2))
+#define WSTAT_G_COMP_U(x)              (1 << ((x * 4) + 1))
+#define WSTAT_G_COMP_L(x)              (1 << ((x * 4) + 0))
+
+#define WSTAT_G_TCON                   (1 << 16)
+
+#define WSTAT_L_TCON                   (1 << 3)
+#define WSTAT_L_FRCCNTB                        (1 << 2)
+#define WSTAT_L_ICNTB                  (1 << 1)
+#define WSTAT_L_TCNTB                  (1 << 0)
+
+#define G_INT_OFFS(x)                  ((x>>4)&0xf)
+
+#define mct_check_wstat(wstat, mct_id) \
+do { \
+       if (__raw_readl(mct_base + wstat) & mct_id) { \
+               __raw_writel(mct_id, mct_base + wstat); \
+               break; \
+       } \
+} while (1)
 
 /****************************************************************************
  * Private Types
  ****************************************************************************/
-enum {
-       MCT_GLOBAL,
-       MCT_LOCAL,
-};
-
-struct mct_desc {
-       char *name;
-       int offset;
-       unsigned irq_id;
-       mct_cb_t callback;
-       void *param;
-};
-
-struct mct_desc mct_device[] = {
-       /* global */
-       [MCT_G0] = {
-               .name = "mct-g.0",
-               .irq_id = IRQ_MCT_G0,
-       },
-       [MCT_G1] = {
-               .name = "mct-g.1",
-               .irq_id = IRQ_MCT_G1,
-       },
-       [MCT_G2] = {
-               .name = "mct-g.2",
-               .irq_id = IRQ_MCT_G2,
-       },
-       [MCT_G3] = {
-               .name = "mct-g.3",
-               .irq_id = IRQ_MCT_G3,
-       },
-       /* local */
-       [MCT_L0] = {
-               .name = "mct-l.0",
-               .irq_id = IRQ_MCT_L0,
-       },
-       [MCT_L1] = {
-               .name = "mct-l.1",
-               .irq_id = IRQ_MCT_L1,
-       },
-       [MCT_L2] = {
-               .name = "mct-l.2",
-               .irq_id = IRQ_MCT_L2,
-       },
-       [MCT_L3] = {
-               .name = "mct-l.3",
-               .irq_id = IRQ_MCT_L3,
-       },
-};
 
 /****************************************************************************
  * Private Data
@@ -203,234 +140,279 @@ struct mct_desc mct_device[] = {
 static volatile bool bmct_init;
 static const u32 clk_rate = CONFIG_FIN_HZ;
 static u32 divided_clk_rate = 1;
+void *mct_base = (void *)MCT0_BASE;
 
 /****************************************************************************
  * Public Data
  ****************************************************************************/
-void *mct_base = (void *)MCT0_BASE;
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
-static int mct_get_offset_by_id(int mct_id)
-{
-       char *p;
-       int i;
-       struct mct_desc *mct = &mct_device[mct_id];
-
-       /*  Assert(mct_id >= 0 && mct_id < MCT_END); */
-
-       for (i = 0, p = &mct->name[0]; i < strlen(mct->name); i++, p++)
-               if (*p == '.') {
-                       break;
-               }
-
-       return (int)(*(++p) - '0');
-}
-
-static int mct_get_type_by_id(int mct_id)
-{
-       Assert(mct_id >= 0 && mct_id < MCT_END);
-
-       if (mct_id < MCT_L0) {
-               return MCT_GLOBAL;
-       } else {
-               return MCT_LOCAL;
-       }
-
-       return -EINVAL;
-}
-
-static int mct_get_id_by_name(char *name)
-{
-       struct mct_desc *mct;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(mct_device); i++) {
-               mct = &mct_device[i];
-               if (!strcmp(mct->name, name)) {
-                       return i;
-               }
-       }
-
-       return -EINVAL;
-}
-
-static bool mct_is_valid(int mct_id)
-{
-       return (mct_id >= 0 && mct_id < MCT_END) ? true : false;
-}
-
-static void mct_global_disable_int(int mct_id)
-{
-       uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       reg = __raw_readl(mct_base + G_INT_ENB);
-       reg &= ~(1 << offset);
-       __raw_writel(reg, mct_base + G_INT_ENB);
-}
 
-static void mct_local_enable_int(int mct_id, int flag)
-{
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       if (flag & 0xFFFFFFFC) {
-               lldbg("invalid mct local interrupt flag\n");
-               goto out;
-       }
-
-       __raw_writel(flag, mct_base + L_INT_ENB(offset));
-out:
-       return;
-}
-
-static void mct_local_disable_int(int mct_id, int flag)
-{
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       if (flag & 0xFFFFFFFC) {
-               lldbg("invalid mct local interrupt flag\n");
-               goto out;
-       }
-
-       __raw_writel(flag, mct_base + L_INT_ENB(offset));
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
 
-out:
-       return;
+/****************************************************************************
+* Name: s5j_mct_local_int_ctrl
+*
+* Description:
+*   Local timer interrupt control.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*   flag - interrupt enable/disable: LINT_NONE, LINT_INT, LINT_FRC.
+*
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_int_ctrl(MCT_CHANNEL mct_id, MCT_LINT flag)
+{
+       Assert(mct_id >= MCT_L0);
+       __raw_writel(flag, mct_base + L_INT_ENB(mct_id));
 }
 
-static u64 mct_global_get_comp_cnt(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_global_get_cmp_cnt
+*
+* Description:
+*   Get Global timer channel current compare value.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+*
+* Returned Value:
+*   Compare value
+*
+****************************************************************************/
+u64 s5j_mct_global_get_comp_cnt(MCT_CHANNEL mct_id)
 {
-       int offset;
        u32 low, high;
 
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
-
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id <= MCT_G3);
 
-       low = __raw_readl(mct_base + G_COMP_L(offset));
-       high = __raw_readl(mct_base + G_COMP_U(offset));
+       low = __raw_readl(mct_base + G_COMP_L(mct_id));
+       high = __raw_readl(mct_base + G_COMP_U(mct_id));
 
        return (u64)(((u64) high << 32) | low);
 }
 
-static u32 mct_global_get_auto_incr(int mct_id)
-{
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       return (u32)(__raw_readl(mct_base + G_COMP_ADD_INCR(offset)));
+/****************************************************************************
+* Name: s5j_mct_global_get_auto_incr
+*
+* Description:
+*   Get Global timer channel auto increment value.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+*
+* Returned Value:
+*   Increment value
+*
+****************************************************************************/
+u32 s5j_mct_global_get_auto_incr(MCT_CHANNEL mct_id)
+{
+       Assert(mct_id <= MCT_G3);
+       return (u32)(__raw_readl(mct_base + G_COMP_ADD_INCR(mct_id)));
 }
 
-static void mct_global_set_auto_incr(int mct_id, u32 count)
-{
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
-
-       if (count == mct_global_get_auto_incr(mct_id)) {
+/****************************************************************************
+* Name: s5j_mct_global_set_auto_incr
+*
+* Description:
+*   Global timer channel compare value auto increment set.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*   count - increment value
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_global_set_auto_incr(MCT_CHANNEL mct_id, u32 count)
+{
+       Assert(mct_id <= MCT_G3);
+
+       if (count == s5j_mct_global_get_auto_incr(mct_id)) {
                return;
        }
 
-       offset = mct_get_offset_by_id(mct_id);
-
-       __raw_writel(count, mct_base + G_COMP_ADD_INCR(offset));
-       mct_check_wstat(G_WSTAT, WSTAT_G_COMP_ADD_INCR(offset));
+       __raw_writel(count, mct_base + G_COMP_ADD_INCR(mct_id));
+       mct_check_wstat(G_WSTAT, WSTAT_G_COMP_ADD_INCR(mct_id));
 }
 
-static void mct_local_set_int_cnt(int mct_id, u32 count)
-{
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
-
-       if (count == mct_local_get_int_cnt(mct_id)) {
-               return;
-       }
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       if (count >> 31) {
-               lldbg("invalid count value: count[31] used for a manual update bit.\n");
-               goto out;
-       }
+/****************************************************************************
+* Name: s5j_mct_local_set_int_cnt_auto
+*
+* Description:
+*   Set Local interrupt counter value after counter reaches 0 value.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*   count - initial value
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_set_int_cnt_auto(MCT_CHANNEL mct_id, u32 count)
+{
+       Assert(mct_id >= MCT_L0);
+       /* clear manual update bit (ICNTB[31]) */
+       count &= ~(1 << 31);
+       __raw_writel(count, mct_base + L_ICNTB(mct_id));
+       mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_ICNTB);
+}
 
-       /* set a manual update bit (ICNTB[31]) */
+/****************************************************************************
+* Name: s5j_mct_local_set_int_cnt_manual
+*
+* Description:
+*   Set Local interrupt counter value immediately.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*   count - initial value
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_set_int_cnt_manual(MCT_CHANNEL mct_id, u32 count)
+{
+       Assert(mct_id >= MCT_L0);
+       /* set manual update bit (ICNTB[31]) */
        count |= 1 << 31;
-       __raw_writel(count, mct_base + L_ICNTB(offset));
-       mct_check_wstat(L_WSTAT(offset), WSTAT_L_ICNTB);
-out:
-       return;
+       __raw_writel(count, mct_base + L_ICNTB(mct_id));
+       mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_ICNTB);
 }
 
-static void mct_local_set_tick_cnt(int mct_id, u32 count)
-{
-       int offset;
-
-       if (count == mct_local_get_tick_cnt(mct_id)) {
-               return;
-       }
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       __raw_writel(count, mct_base + L_TCNTB(offset));
-       mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCNTB);
+/****************************************************************************
+* Name: s5j_mct_local_set_tick_cnt
+*
+* Description:
+*   Set Local TICK counter value
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*   count - initial value
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_set_tick_cnt(MCT_CHANNEL mct_id, u32 count)
+{
+       Assert(mct_id >= MCT_L0);
+       __raw_writel(count, mct_base + L_TCNTB(mct_id));
+       mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCNTB);
 }
 
-static u32 mct_local_get_int_cnt(int mct_id)
-{
-       int offset;
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       return (u32)(__raw_readl(mct_base + L_ICNTO(offset)) & 0x7FFFFFFF);
+/****************************************************************************
+* Name: s5j_mct_local_get_int_cnt
+*
+* Description:
+*   Return current Local interrupt counter value
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   counter value.
+*
+****************************************************************************/
+u32 s5j_mct_local_get_int_cnt(MCT_CHANNEL mct_id)
+{
+       Assert(mct_id >= MCT_L0);
+       return (u32)(__raw_readl(mct_base + L_ICNTO(mct_id)) & 0x7FFFFFFF);
 }
 
-static u32 mct_local_get_tick_cnt(int mct_id)
-{
-       int offset;
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       return (u32)__raw_readl(mct_base + L_TCNTO(offset));
+/****************************************************************************
+* Name: s5j_mct_local_get_tick_cnt
+*
+* Description:
+*   Return current Local TICK counter value
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   counter value.
+*
+****************************************************************************/
+u32 s5j_mct_local_get_tick_cnt(MCT_CHANNEL mct_id)
+{
+       Assert(mct_id >= MCT_L0);
+       return (u32) __raw_readl(mct_base + L_TCNTO(mct_id));
 }
 
-u32 mct_local_get_frc_cnt(int mct_id)
-{
-       int offset;
-
-       offset = mct_get_offset_by_id(mct_id);
+/****************************************************************************
+* Name: s5j_mct_local_set_frc_cnt
+*
+* Description:
+*   Set Local FRC counter value.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*   count - value to set
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_set_frc_cnt(MCT_CHANNEL mct_id, u32 count)
+{
+       Assert(mct_id >= MCT_L0);
+       __raw_writel(count, mct_base + L_FRCNTB(mct_id));
+       mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_FRCCNTB);
+}
 
-       return (u32)__raw_readl(mct_base + L_FRCNTO(offset));
+/****************************************************************************
+* Name: s5j_mct_local_get_frc_cnt
+*
+* Description:
+*   Return current Local FRC counter value
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   counter value.
+*
+****************************************************************************/
+u32 s5j_mct_local_get_frc_cnt(MCT_CHANNEL mct_id)
+{
+       Assert(mct_id >= MCT_L0);
+       return (u32) __raw_readl(mct_base + L_FRCNTO(mct_id));
 }
 
-static bool mct_ispending(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_ispending
+*
+* Description:
+*   Check if selected MCT interrupt is pending or not.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   true - pending, false - not pending.
+*
+****************************************************************************/
+bool s5j_mct_ispending(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
 
-       offset = mct_get_offset_by_id(mct_id);
-
-       if (mct_get_type_by_id(mct_id) == MCT_LOCAL) {
-               reg = __raw_readl(mct_base + L_INT_CSTAT(offset)) & 0x3;
+       if (mct_id > MCT_G3) {
+               reg = __raw_readl(mct_base + L_INT_CSTAT(mct_id)) & 3;
        } else {
-               reg = __raw_readl(mct_base + G_INT_CSTAT) & (1 << offset);
+               reg = __raw_readl(mct_base + G_INT_CSTAT) & (1 << G_INT_OFFS(mct_id));
        }
 
        if (!reg) {
@@ -440,7 +422,20 @@ static bool mct_ispending(int mct_id)
        }
 }
 
-static void mct_global_start_frc(void)
+/****************************************************************************
+* Name: s5j_mct_global_start_frc
+*
+* Description:
+*   Start global FRC counter
+*
+* Input Parameters:
+*   None
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_global_start_frc(void)
 {
        uregister reg;
 
@@ -450,7 +445,20 @@ static void mct_global_start_frc(void)
        mct_check_wstat(G_WSTAT, WSTAT_G_TCON);
 }
 
-static void mct_global_stop_frc(void)
+/****************************************************************************
+* Name: s5j_mct_global_stop_frc
+*
+* Description:
+*   Stop global FRC counter
+*
+* Input Parameters:
+*   None
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_global_stop_frc(void)
 {
        uregister reg;
 
@@ -462,12 +470,24 @@ static void mct_global_stop_frc(void)
        }
 }
 
-static void mct_global_set_frc_cnt(cycle_t count)
+/****************************************************************************
+* Name: s5j_mct_global_set_frc_cnt
+*
+* Description:
+*   Preset initial value of global FRC
+*
+* Input Parameters:
+*   count - initial value
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_global_set_frc_cnt(cycle_t count)
 {
-       u32 low;
-       u32 high;
+       u32 low, high;
 
-       if (count == mct_global_get_frc_cnt()) {
+       if (count == s5j_mct_global_get_frc_cnt()) {
                return;
        }
 
@@ -481,18 +501,21 @@ static void mct_global_set_frc_cnt(cycle_t count)
        mct_check_wstat(G_CNT_WSTAT, WSTAT_G_CNT_L);
 }
 
-static cycle_t mct_get_timer(cycle_t start)
-{
-       return mct_global_get_frc_cnt() - start;
-}
-
-static void mct_udelay(u64 usec)
-{
-       cycle_t end = mct_get_timer(0) + usec2ticks(usec);
-       while (mct_get_timer(0) < end) ;
-}
-
-static void mct_clk_rate(u32 prescaler, eMCT_DIVIDER divider)
+/****************************************************************************
+* Name: s5j_mct_clk_rate
+*
+* Description:
+*   Set MCT prescaler/divider values.
+*
+* Input Parameters:
+*   prescaler - precsaler value
+*   divider - divider value
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_clk_rate(u32 prescaler, eMCT_DIVIDER divider)
 {
        u32 reg;
 
@@ -504,305 +527,317 @@ static void mct_clk_rate(u32 prescaler, eMCT_DIVIDER divider)
        __raw_writel(reg, mct_base + CFG);
 }
 
-static cycle_t usec2ticks(u64 usec)
-{
-       return (usec * divided_clk_rate) / USEC_PER_SEC;
-}
-
-static u64 ticks2usec(cycle_t tick)
-{
-       return (tick * USEC_PER_SEC) / divided_clk_rate;
-}
-
-static void mct_local_set_interval(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_local_set_interval
+*
+* Description:
+*   Local timer enambe autoreload mode.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_set_interval(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
 
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id >= MCT_L0);
 
-       reg = __raw_readl(mct_base + L_TCON(offset));
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
        if (!(reg & L_TCON_INTERVAL_MODE)) {
                reg |= L_TCON_INTERVAL_MODE;
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
 }
 
-static void mct_local_clear_interval(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_local_clear_interval
+*
+* Description:
+*   Local timer disable autoreload mode.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_clear_interval(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
 
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id >= MCT_L0);
 
-       reg = __raw_readl(mct_base + L_TCON(offset));
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
        if (reg & L_TCON_INTERVAL_MODE) {
                reg &= ~(L_TCON_INTERVAL_MODE);
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
 }
 
-static void mct_local_start_int(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_local_start_int
+*
+* Description:
+*   Start Local timer interrupt counter.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_start_int(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
 
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id >= MCT_L0);
 
-       reg = __raw_readl(mct_base + L_TCON(offset));
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
        if (!(reg & L_TCON_INT_START)) {
                reg |= L_TCON_INT_START;
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
 }
 
-static void mct_local_stop_int(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_local_stop_int
+*
+* Description:
+*   Stop Local timer interrupt counter.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_stop_int(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
 
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id >= MCT_L0);
 
-       reg = __raw_readl(mct_base + L_TCON(offset));
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
        if (reg & L_TCON_INT_START) {
                reg &= ~(L_TCON_INT_START);
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
 }
 
-static void mct_local_start_timer(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_local_start_timer
+*
+* Description:
+*   Start Local timer tick counter.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_start_timer(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       /*  Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL); */
 
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id >= MCT_L0);
 
-       reg = __raw_readl(mct_base + L_TCON(offset));
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
        if (!(reg & L_TCON_TIMER_START)) {
                reg |= L_TCON_TIMER_START;
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
 }
 
-static void mct_local_stop_timer(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_local_stop_timer
+*
+* Description:
+*   Stop Local timer tick counter.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_stop_timer(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_LOCAL);
 
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id >= MCT_L0);
 
-       reg = __raw_readl(mct_base + L_TCON(offset));
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
        if (reg & L_TCON_TIMER_START) {
                reg &= ~(L_TCON_TIMER_START);
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
 }
 
-static void mct_set_callback(int mct_id, mct_cb_t mct_cb, void *param)
-{
-       struct mct_desc *mct = &mct_device[mct_id];
-
-       mct->callback = mct_cb;
-       mct->param = param;
-}
-
-static void mct_handler(int mct_id)
-{
-       /*  struct mct_desc *mct = &mct_device[mct_id]; */
-       mct_clear_pending(mct_id);
-}
-
-static __irq void mct_isr_gt0_handler(void)
-{
-       mct_handler(MCT_G0);
-}
-
-static __irq void mct_isr_gt1_handler(void)
-{
-       mct_handler(MCT_G1);
-}
-
-static __irq void mct_isr_gt2_handler(void)
-{
-       mct_handler(MCT_G2);
-}
-
-static __irq void mct_isr_gt3_handler(void)
-{
-       mct_handler(MCT_G3);
-}
-
-static void mct_reset(int mct_id)
+/****************************************************************************
+* Name: s5j_mct_local_start_frc
+*
+* Description:
+*   Start Local timer FRC counter.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_start_frc(MCT_CHANNEL mct_id)
 {
-       int type = mct_get_type_by_id(mct_id);
-
-       mct_clear_pending(mct_id);
+       uregister reg;
 
-       if (type == MCT_GLOBAL) {
-               mct_global_disable_comp(mct_id);
-               mct_global_disable_int(mct_id);
-               mct_global_set_auto_incr(mct_id, 0);
-               mct_global_set_comp_cnt(mct_id, 0);
-       } else if (type == MCT_LOCAL) {
-               mct_local_disable_int(mct_id, (L_INTR_FRC | L_INTR_ICNT));
-               mct_local_stop_frc(mct_id);
-               mct_local_stop_timer(mct_id);
-               mct_local_stop_int(mct_id);
-               mct_local_clear_interval(mct_id);
-               mct_local_set_tick_cnt(mct_id, 0);
-               mct_local_set_int_cnt(mct_id, 0);
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
+       if (!(reg & L_TCON_FRC_START)) {
+               reg |= L_TCON_FRC_START;
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
-
-       mct_set_callback(mct_id, NULL, NULL);
 }
 
-static int mct_open(char *name)
+/****************************************************************************
+* Name: s5j_mct_local_stop_frc
+*
+* Description:
+*   Stop Local timer FRC counter.
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_local_stop_frc(MCT_CHANNEL mct_id)
 {
-       int mct_id;
-
-       mct_id = mct_get_id_by_name(name);
+       uregister reg;
 
-       if (!mct_is_valid(mct_id)) {
-               lldbg("invalid mct id\n");
-               return -1;
+       reg = __raw_readl(mct_base + L_TCON(mct_id));
+       if (reg & L_TCON_FRC_START) {
+               reg &= ~(L_TCON_FRC_START);
+               __raw_writel(reg, mct_base + L_TCON(mct_id));
+               mct_check_wstat(L_WSTAT(mct_id), WSTAT_L_TCON);
        }
-
-       mct_reset(mct_id);
-
-       return mct_id;
-}
-
-static void mct_close(int mct_id)
-{
-       mct_reset(mct_id);
 }
 
 /****************************************************************************
- * Public Functions
- ****************************************************************************/
-/**
- *
- * @brief    enable mctX timer function, call with mct_id will enabel mctX
- * @param    int mct_id  : channel number of MCT
- * @return
- * @note     note here
- */
-void mct_global_enable_int(int mct_id)
+* Name: s5j_mct_global_enable_int
+*
+* Description:
+*   Enable interrupt for global counter channel
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_global_enable_int(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
 
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id <= MCT_G3);
 
        reg = __raw_readl(mct_base + G_INT_ENB);
-       reg |= 1 << offset;
+       reg |= 1 << G_INT_OFFS(mct_id);
        __raw_writel(reg, mct_base + G_INT_ENB);
 }
 
-/**
- *
- * @brief    mct has globan and local timer, this function enable local timer0 function
- * @return
- * @note     note here
- */
-void mct_local_start_timer0(void)
-{
-       int mct = MCT_L0;
-       int tick = (26 * USEC_PER_TICK);        /*  Fin*TargetPeriod  */
-       int icnt = 0;
-       mct_local_enable_int(mct, L_INTR_ICNT);
-       mct_local_set_tick_cnt(mct, tick);
-       mct_local_set_int_cnt(mct, icnt);
-
-       mct_local_set_interval(mct);
-       mct_local_start_int(mct);
-       mct_local_start_timer(mct);
-}
-
-/**
- *
- * @brief    Initialize global timer for tick
- * @return
- * @note     note here
- */
-void mct_init(void)
+/****************************************************************************
+* Name: s5j_mct_global_disable_int
+*
+* Description:
+*   Disable interrupt for global counter channel
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_global_disable_int(MCT_CHANNEL mct_id)
 {
+       uregister reg;
 
-#ifndef TEMP_TEST
-       if (bmct_init == true) {
-               return;
-       }
-#endif
-
-       mct_base = (void *)MCT0_BASE;
-       mct_global_set_frc_cnt(0);
-       mct_global_start_frc();
+       Assert(mct_id <= MCT_G3);
 
-       bmct_init = true;
+       reg = __raw_readl(mct_base + G_INT_ENB);
+       reg &= ~(1 << G_INT_OFFS(mct_id));
+       __raw_writel(reg, mct_base + G_INT_ENB);
 }
 
-/**
- *
- * @brief    set global timer comparation value, MCT will set interrupt if reach to timer count. FRC in global timer is an up-counter. After it starts, it increments until 64'hffff_ffff_ffff_ffff and returns to 0. Comparator continuously see the value. When it matches with two values, interrupt occurs.
- * @param    int mct_id : channel of mct
- * @param    u64 count : 64 bit comparation value
- * @note     note here
- */
-void mct_global_set_comp_cnt(int mct_id, u64 count)
+/****************************************************************************
+* Name: s5j_mct_global_set_comp_cnt
+*
+* Description:
+*   Sets Compare value for global times channel
+*
+* Input Parameters:
+*   mct_id - mct timer ID
+*   count - 64 bit unsigned value for compare with FRC
+*
+* Returned Value:
+*   None
+*
+****************************************************************************/
+void s5j_mct_global_set_comp_cnt(MCT_CHANNEL mct_id, u64 count)
 {
-       int offset;
-       u32 low;
-       u32 high;
+       u32 low, high;
 
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
+       Assert(mct_id <= MCT_G3);
 
-       if (count == mct_global_get_comp_cnt(mct_id)) {
+       if (count == s5j_mct_global_get_comp_cnt(mct_id)) {
                return;
        }
 
-       offset = mct_get_offset_by_id(mct_id);
-
        low = (u32)(count & 0xFFFFFFFF);
        high = (u32)((count >> 32) & 0xFFFFFFFF);
 
-       __raw_writel(low, mct_base + G_COMP_L(offset));
-       mct_check_wstat(G_WSTAT, WSTAT_G_COMP_L(offset));
-       __raw_writel(high, mct_base + G_COMP_U(offset));
-       mct_check_wstat(G_WSTAT, WSTAT_G_COMP_U(offset));
+       __raw_writel(low, mct_base + G_COMP_L(mct_id));
+       mct_check_wstat(G_WSTAT, WSTAT_G_COMP_L(mct_id));
+       __raw_writel(high, mct_base + G_COMP_U(mct_id));
+       mct_check_wstat(G_WSTAT, WSTAT_G_COMP_U(mct_id));
 }
 
-/**
+/****************************************************************************
+ * Name: s5j_mct_global_get_frc_cnt
+ *
+ * Description:
+ *   Returns current Free Running Counter value
+ *
+ * Input Parameters:
+ *   None
  *
- * @brief    return value of free running counter
- * @return   cycle_t count : 64bit value of FRC
- * @note     note here
- */
-cycle_t mct_global_get_frc_cnt(void)
+ * Returned Value:
+ *   64 bit value of FRC
+ *
+ ****************************************************************************/
+
+cycle_t s5j_mct_global_get_frc_cnt(void)
 {
        cycle_t count;
-       u32 low;
-       u32 high;
-       u32 high1;
+       u32 low, high, high1;
 
        high = __raw_readl(mct_base + G_CNT_U);
        low = __raw_readl(mct_base + G_CNT_L);
@@ -813,132 +848,147 @@ cycle_t mct_global_get_frc_cnt(void)
 
        count = (cycle_t) low;
        if (sizeof(cycle_t) > sizeof(u32)) {
-               count |= ((cycle_t)high1 << 32);
+               count |= ((cycle_t) high1 << 32);
        }
 
        return count;
 }
 
-/**
+/****************************************************************************
+ * Name: s5j_mct_global_disable_comp
+ *
+ * Description:
+ *   Disable compare operation for selected global timer
+ *
+ * Input Parameters:
+ *   mct_id - mct timer ID
+ *
+ * Returned Value:
+ *   None
  *
- * @brief    disable the comparison between the global FRC and the 64-bit comparaton in MCT channel.
- * @param    int mct_id : channel of MCT
- * @note     note here
- */
-void mct_global_disable_comp(int mct_id)
+ ****************************************************************************/
+
+void s5j_mct_global_disable_comp(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
 
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
-
-       offset = mct_get_offset_by_id(mct_id);
+       Assert(mct_id <= MCT_G3);
 
        reg = __raw_readl(mct_base + G_TCON);
-       if (reg & G_TCON_COMP_ENABLE(offset)) {
-               reg &= ~(1 << (offset * 2));
+       if (reg & G_TCON_COMP_ENABLE(mct_id)) {
+               reg &= ~(1 << (G_INT_OFFS(mct_id) * 2));
                __raw_writel(reg, mct_base + G_TCON);
                mct_check_wstat(G_WSTAT, WSTAT_G_TCON);
        }
 }
 
-/**
+/****************************************************************************
+ * Name: s5j_mct_global_enable_comp
  *
- * @brief    ensable the comparison between the global FRC and the 64-bit comparaton in MCT channel.
- * @param    int mct_id : channel of MCT
- * @note     note here
- */
-void mct_global_enable_comp(int mct_id)
+ * Description:
+ *   Enable compare operation for selected global timer
+ *
+ * Input Parameters:
+ *   mct_id - mct timer ID
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void s5j_mct_global_enable_comp(MCT_CHANNEL mct_id)
 {
        uregister reg;
-       int offset;
-
-       Assert(mct_get_type_by_id(mct_id) == MCT_GLOBAL);
-
-       offset = mct_get_offset_by_id(mct_id);
 
        reg = __raw_readl(mct_base + G_TCON);
-       if (!(reg & G_TCON_COMP_ENABLE(offset))) {
-               reg |= G_TCON_COMP_ENABLE(offset);
+       if (!(reg & G_TCON_COMP_ENABLE(mct_id))) {
+               reg |= G_TCON_COMP_ENABLE(mct_id);
                __raw_writel(reg, mct_base + G_TCON);
                mct_check_wstat(G_WSTAT, WSTAT_G_TCON);
        }
 }
 
-/**
+/****************************************************************************
+ * Name: s5j_mct_reset
  *
- * @brief    when FRC in global timer are matched with comparation value, interrupt is asserted. this function will clear interupt pending register in MCT.
- * @param    int mct_id : channel of MCT
- * @note     note here
- */
-void mct_clear_pending(int mct_id)
-{
-       int offset;
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       if (mct_get_type_by_id(mct_id) == MCT_LOCAL) {
-               __raw_writel(3, mct_base + L_INT_CSTAT(offset));
-       } else if (mct_get_type_by_id(mct_id) == MCT_GLOBAL) {
-               __raw_writel(1 << offset, mct_base + G_INT_CSTAT);
-       }
-}
-
-void mct_local_start_frc(int mct_id)
+ * Description:
+ *   Stops operationof selected MCT timer.
+ *
+ * Input Parameters:
+ *   mct_id - mct timer ID
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+void s5j_mct_reset(MCT_CHANNEL mct_id)
 {
-       uregister reg;
-       int offset;
 
-       offset = mct_get_offset_by_id(mct_id);
+       s5j_mct_clear_pending(mct_id);
 
-       reg = __raw_readl(mct_base + L_TCON(offset));
-       if (!(reg & L_TCON_FRC_START)) {
-               reg |= L_TCON_FRC_START;
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+       if (mct_id <= MCT_G3) {
+               s5j_mct_global_disable_comp(mct_id);
+               s5j_mct_global_disable_int(mct_id);
+               s5j_mct_global_set_auto_incr(mct_id, 0);
+               s5j_mct_global_set_comp_cnt(mct_id, 0);
+       } else {
+               s5j_mct_local_int_ctrl(mct_id, LINT_NONE);
+               s5j_mct_local_stop_frc(mct_id);
+               s5j_mct_local_stop_timer(mct_id);
+               s5j_mct_local_stop_int(mct_id);
+               s5j_mct_local_clear_interval(mct_id);
+               s5j_mct_local_set_tick_cnt(mct_id, 0);
+               s5j_mct_local_set_int_cnt_manual(mct_id, 0);
        }
 }
 
-void mct_local_stop_frc(int mct_id)
+/****************************************************************************
+ * Name: s5j_mct_clear_pending
+ *
+ * Description:
+ *   Clear pending interript flag.
+ *
+ * Input Parameters:
+ *   mct_id - mct timer ID
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+void s5j_mct_clear_pending(MCT_CHANNEL mct_id)
 {
-       uregister reg;
-       int offset;
-
-       offset = mct_get_offset_by_id(mct_id);
-
-       reg = __raw_readl(mct_base + L_TCON(offset));
-       if (reg & L_TCON_FRC_START) {
-               reg &= ~(L_TCON_FRC_START);
-               __raw_writel(reg, mct_base + L_TCON(offset));
-               mct_check_wstat(L_WSTAT(offset), WSTAT_L_TCON);
+       if (mct_id > MCT_G3) {
+               __raw_writel(3, mct_base + L_INT_CSTAT(mct_id));
+       } else {
+               __raw_writel(1 << G_INT_OFFS(mct_id), mct_base + G_INT_CSTAT);
        }
 }
 
-__irq void mct_isr_lt0_handler(void)
-{
-       mct_handler(MCT_L0);
-}
-
-__irq void mct_isr_lt1_handler(void)
-{
-       mct_handler(MCT_L1);
-}
-
-__irq void mct_isr_lt2_handler(void)
-{
-       mct_handler(MCT_L2);
-}
-
-__irq void mct_isr_lt3_handler(void)
-{
-       mct_handler(MCT_L3);
-}
-
-void mct_local_start_frc_all(void)
+/****************************************************************************
+ * Name: s5j_mct_local_start_timer0
+ *
+ * Description:
+ *   Initializes MCT_L0 local timer to operate as a tick source.
+ *   Expectd that CLK cource is 26MHz.
+ *   Used is in timerisr.c
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+void s5j_mct_local_start_timer0(void)
 {
-       mct_local_start_frc(0);
-       irq_attach(IRQ_MCT_L0, (xcpt_t) mct_isr_lt0_handler);
-       /* Enable SysTick interrupts */
-       up_enable_irq(IRQ_MCT_L0);
+       MCT_CHANNEL mct = MCT_L0;
+       int tick = (26 * USEC_PER_TICK);        /*  Fin*TargetPeriod  */
+       int icnt = 0;
+       s5j_mct_local_int_ctrl(mct, LINT_INT);
+       s5j_mct_local_set_tick_cnt(mct, tick);
+       s5j_mct_local_set_int_cnt_manual(mct, icnt);
 
+       s5j_mct_local_set_interval(mct);
+       s5j_mct_local_start_int(mct);
+       s5j_mct_local_start_timer(mct);
 }
index 61b02c1..8de88ba 100644 (file)
@@ -49,9 +49,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  *
  ****************************************************************************/
-
-#ifndef __ARCH_ARM_SRC_S5J_S5J_MCT_H
-#define __ARCH_ARM_SRC_S5J_S5J_MCT_H
+#ifndef __S5J_MCT_H__
+#define __S5J_MCT_H__
 
 /****************************************************************************
  * Included Files
 static "C" {
 #endif
 
-enum {
-       MCT_G0,
-       MCT_G1,
-       MCT_G2,
-       MCT_G3,
-       MCT_L0,
-       MCT_L1,
-       MCT_L2,
-       MCT_L3,
-       MCT_L4,
-       MCT_L5,
-       MCT_L6,
-       MCT_L7,
-
-       MCT_END,
-};
+       typedef enum {
+               MCT_G0 = 0x200,
+               MCT_G1 = 0x210,
+               MCT_G2 = 0x220,
+               MCT_G3 = 0x230,
+               MCT_L0 = 0x300,
+               MCT_L1 = 0x400,
+               MCT_L2 = 0x500,
+               MCT_L3 = 0x600,
+       } MCT_CHANNEL;
 
-typedef enum {
-       eDIVIDER_1 = 0,
-       eDIVIDER_2,
-       eDIVIDER_4,
-       eDIVIDER_8,
-       eDIVIDER_16,
-       eDIVIDER_MAX,
-} eMCT_DIVIDER;
+       typedef enum {
+               LINT_NONE = 0,
+               LINT_INT = 1,
+               LINT_FRC = 2,
+               LINT_FRC_INT = 3,
+       } MCT_LINT;
 
-typedef void (*mct_cb_t)(void *);
+       typedef enum {
+               eDIVIDER_1 = 0,
+               eDIVIDER_2,
+               eDIVIDER_4,
+               eDIVIDER_8,
+               eDIVIDER_16,
+               eDIVIDER_MAX,
+       } eMCT_DIVIDER;
 
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-void mct_init(void);
-cycle_t mct_global_get_frc_cnt(void);
-void mct_global_enable_int(int mct_id);
-void mct_global_disable_comp(int mct_id);
-void mct_global_set_comp_cnt(int mct_id, u64 count);
-void mct_global_enable_comp(int mct_id);
-void mct_clear_pending(int mct_id);
-void mct_local_start_frc(int mct_id);
-void mct_local_stop_frc(int mct_id);
+       /****************************************************************************
+        * Public Functions
+        ****************************************************************************/
+       void s5j_mct_local_int_ctrl(MCT_CHANNEL mct_id, MCT_LINT flag);
+       u64 s5j_mct_global_get_comp_cnt(MCT_CHANNEL mct_id);
+       u32 s5j_mct_global_get_auto_incr(MCT_CHANNEL mct_id);
+       void s5j_mct_global_set_auto_incr(MCT_CHANNEL mct_id, u32 count);
+       void s5j_mct_local_set_int_cnt_auto(MCT_CHANNEL mct_id, u32 count);
+       void s5j_mct_local_set_int_cnt_manual(MCT_CHANNEL mct_id, u32 count);
+       void s5j_mct_local_set_tick_cnt(MCT_CHANNEL mct_id, u32 count);
+       u32 s5j_mct_local_get_int_cnt(MCT_CHANNEL mct_id);
+       u32 s5j_mct_local_get_tick_cnt(MCT_CHANNEL mct_id);
+       void s5j_mct_local_set_frc_cnt(MCT_CHANNEL mct_id, u32 count);
+       u32 s5j_mct_local_get_frc_cnt(MCT_CHANNEL mct_id);
+       bool s5j_mct_ispending(MCT_CHANNEL mct_id);
+       void s5j_mct_global_start_frc(void);
+       void s5j_mct_global_stop_frc(void);
+       void s5j_mct_global_set_frc_cnt(cycle_t count);
+       void s5j_mct_clk_rate(u32 prescaler, eMCT_DIVIDER divider);
+       void s5j_mct_local_set_interval(MCT_CHANNEL mct_id);
+       void s5j_mct_local_clear_interval(MCT_CHANNEL mct_id);
+       void s5j_mct_local_start_int(MCT_CHANNEL mct_id);
+       void s5j_mct_local_stop_int(MCT_CHANNEL mct_id);
+       void s5j_mct_local_start_timer(MCT_CHANNEL mct_id);
+       void s5j_mct_local_stop_timer(MCT_CHANNEL mct_id);
+       void s5j_mct_local_start_frc(MCT_CHANNEL mct_id);
+       void s5j_mct_local_stop_frc(MCT_CHANNEL mct_id);
+       void s5j_mct_global_enable_int(MCT_CHANNEL mct_id);
+       void s5j_mct_global_disable_int(MCT_CHANNEL mct_id);
+       void s5j_mct_global_set_comp_cnt(MCT_CHANNEL mct_id, u64 count);
+       cycle_t s5j_mct_global_get_frc_cnt(void);
+       void s5j_mct_global_disable_comp(MCT_CHANNEL mct_id);
+       void s5j_mct_global_enable_comp(MCT_CHANNEL mct_id);
+       void s5j_mct_reset(MCT_CHANNEL mct_id);
+       void s5j_mct_clear_pending(MCT_CHANNEL mct_id);
+       void s5j_mct_local_start_timer0(void);
 
 #ifdef __cplusplus
 }
 #endif
-#endif                                                 //__ARCH_ARM_SRC_S5J_S5J_MCT_H
+#endif                                                 //__MCT_H__
index 6ef60da..36e115e 100644 (file)
@@ -123,7 +123,7 @@ int up_timerisr(int irq, uint32_t *regs)
 #endif
 
        sched_process_timer();
-       mct_isr_lt0_handler();
+       s5j_mct_clear_pending(MCT_L0);
        /* for interrupt debug */
        //lldbg("%s, %llu\n", __func__, g_system_timer);
 #ifdef CONFIG_S5J_WATCHDOG_RESET
@@ -143,11 +143,9 @@ int up_timerisr(int irq, uint32_t *regs)
 
 void up_timer_initialize(void)
 {
-       mct_init();
-
        //enable local0 for tick count
-       mct_local_start_timer0();
-       irq_attach(IRQ_MCT_L0, (xcpt_t)up_timerisr);
+       s5j_mct_local_start_timer0();
+       irq_attach(IRQ_MCT_L0, (xcpt_t) up_timerisr);
 
        /* Enable SysTick interrupts */
        up_enable_irq(IRQ_MCT_L0);