/**
 * @file   fcUART.h
 * @brief  Contains common definitions for DMC control
 *
 * Copyright Samsung Electronic
 */

#ifndef __FCUART_H__
#define __FCUART_H__

#undef FC_DR_DEBUG

#if defined(FC_DR_DEBUG)
#define UART_PS(...) uart_ps(__VA_ARGS__)
#define UART_PSD(...) uart_psd(__VA_ARGS__)
#define UART_PSH(...) uart_psh(__VA_ARGS__)
#else
#define UART_PS(...)
#define UART_PSD(...)
#define UART_PSH(...)
#endif

/* Physical address of the UART controler */
#if defined(CONFIG_EXYNOS5260)
#define UART1_SFR_BASE		((uint32_t)0x12C10000)
#elif defined(CONFIG_EXYNOS5430) || defined(CONFIG_EXYNOS5433) || defined(CONFIG_EXYNOS7420) || defined(CONFIG_EXYNOS3475)
#define UART1_SFR_BASE		((uint32_t)0x14c20000)
#elif defined(CONFIG_EXYNOS7580) || defined(CONFIG_EXYNOS7870) || defined(CONFIG_EXYNOS7880)
#define UART1_SFR_BASE		((uint32_t)0x13810000)
#elif defined(CONFIG_EXYNOS7570)
#define UART1_SFR_BASE		((uint32_t)0x13820000)
#elif defined(CONFIG_EXYNOS5422)
#define UART2_SFR_BASE		((uint32_t)0x12C20000)
#elif defined(CONFIG_EXYNOS3470) || defined(CONFIG_EXYNOS3472) || defined(CONFIG_EXYNOS3250)
#define UART2_SFR_BASE		((uint32_t)0x13820000)
#elif defined(CONFIG_EXYNOS4415)
#define UART3_SFR_BASE		((uint32_t)0x13830000)
#elif defined(CONFIG_EXYNOS3475) || defined(CONFIG_EXYNOS7885)
#define UART2_SFR_BASE		((uint32_t)0x13820000)
#elif defined(CONFIG_EXYNOS8890)
#define UART1_SFR_BASE		((uint32_t)0x14c50000)
#elif defined(CONFIG_EXYNOS8895)
#define UART1_SFR_BASE		((uint32_t)0x10430000)
#elif defined(CONFIG_EXYNOS9810)
#define UART1_SFR_BASE		((uint32_t)0x10440000)
#endif

#define UART_SFR_VA		((uint32_t)0x50000)

/* Convenience functions for random reg registers */
#define PTR_OFFS(ptr,offset)   ( (addr_t)( (word_t)(ptr) + (offset) ) )
#define REG_WRITE32( addr, wdata ) do { *((volatile unsigned long *)(addr)) = (wdata); } while(0)
#define REG_OFF_WRITE32( addr, off, wdata ) do { *((volatile unsigned long *)(PTR_OFFS(addr, off))) = (wdata); } while(0)
#define REG_OFF_WRITE8( addr, off, wdata ) do { *((volatile unsigned char *)(PTR_OFFS(addr, off))) = (wdata); } while(0)

#define REG_READ32( addr )         (*((volatile unsigned long *)(addr)))
#define REG_OFF_READ32( addr, off )         (*((volatile unsigned long *)(PTR_OFFS(addr, off))))

void uart_ps(char *s);
void uart_psd(char *s, ...);
void uart_psh(char *s, ...);

#endif /* __FCUART_H__ */
