/*
 * base.h
 *
 * Copyright (C) 2012-2020, Samsung Electronics Co., Ltd.
 *
 * Base definitions
 */

#pragma once

#include <stdint.h>
#include <core/page.h>

#define SIZE_4KB                (4 * 1024)
#define SIZE_8KB                (8 * 1024)
#define SIZE_12KB               (12 * 1024)
#define SIZE_16KB               (16 * 1024)
#define SIZE_32KB               (32 * 1024)
#define SIZE_64KB               (64 * 1024)
#define SIZE_128KB              (128 * 1024)
#define SIZE_256KB              (256 * 1024)
#define SIZE_512KB              (512 * 1024)
#define SIZE_1MB                (1024 * 1024)

#define STUI_ALIGN_UP(size, block) ((((size) + (block) - 1) / (block)) * (block))

#define FALSE                   (0)
#define TRUE                    (1)

#define DEV_UNCONFIGURED        0
#define DEV_IRQ_CONFIGURED      1
#define DEV_SFR_CONFIGURED      2
#define DEV_CONFIGURED          (DEV_IRQ_CONFIGURED | DEV_SFR_CONFIGURED)

typedef uint64_t phys_addr_t;   /* physical address datatype. */

#define PHYS_INVALID_ADDRESS    ((phys_addr_t) -1)

struct device;

/* Bus description structure */
typedef struct
{
    uint32_t        slave_address;
    uint32_t        clock_freq;
    struct device   *device;
} bus_t;

/* Device description structure */
typedef struct device
{
    uint32_t        state;
    uint32_t        irq_num;
    bus_t           bus;
} deviceInfo_t;

typedef struct {
    deviceInfo_t i2c;
    deviceInfo_t gpio;
    deviceInfo_t touch;
    deviceInfo_t decon_fb;
} boardInfo_t;

/* Board global variable */
extern boardInfo_t board;

#define HW_REG8(base, offset)       (*(volatile u8 *)((unsigned long)(base) + (offset)))
#define HW_REG16(base, offset)      (*(volatile u16 *)((unsigned long)(base) + (offset)))
#define HW_REG32(base, offset)      (*(volatile uint32_t *)((unsigned long)(base) + (offset)))
#define DEV_REG(dev_id, offset)     HW_REG32(get_dev_addr(dev_id), offset)

