/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Copyright (c) 2021 Loongson Technology Co., Ltd.
 * This program is free software; you can redistribute  it and/or modify it
 * under  the terms of  the GNU General  Public License as published by the
 * Free Software Foundation;  either version 2 of the  License, or (at your
 * option) any later version.
 */

#ifndef __MS7210_REGS_H__
#define __MS7210_REGS_H__

#include "bridge_phy.h"
#include "bridge_phy_interface.h"
#include "ms7210_drv.h"

/**
 * @brief Config ms7210 registers attribute
 */
static const u8 ms7210_reg_defaults_raw[] = {
};

static bool ms7210_register_volatile(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case MS7210_REG_END:
		return false;
	default:
		return true;
	}
}

static bool ms7210_register_readable(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case MS7210_REG_END:
		return false;
	case MS7210_REG_START:
	default:
		return true;
	}
}

static const struct regmap_range ms7210_rw_regs_range[] = {
	regmap_reg_range(MS7210_REG_START, MS7210_REG_END),
};

static const struct regmap_range ms7210_wo_regs_range[] = {
	regmap_reg_range(0x00FF, 0x00FF),
};

static const struct regmap_range ms7210_ro_regs_range[] = {
	regmap_reg_range(MS7210_REG_CHIP_VERSION_BASE,
			 MS7210_REG_CHIP_VERSION_BASE + CHIP_VERSION_LEN),
};

static const struct regmap_range ms7210_vo_regs_range[] = {
	regmap_reg_range(MS7210_REG_START, MS7210_REG_END),
};

/**
 * @brief ms7210 val sequence
 *
 */
static const u8 ms7210_pll_range_timing[][3][3] = {
	{
		{ 0x00, 0x9e, 0xaa },
		{ 0x00, 0x9e, 0x99 },
		{ 0x00, 0x9e, 0x88 },
	},
	{
		{ 0x00, 0x94, 0xaa },
		{ 0x01, 0x94, 0x99 },
		{ 0x03, 0x94, 0x88 },
	},
};

static const u8 ms7210_pll_timing_u3[][3] = {
	{ 0x00, 0x9e, 0xaa },
	{ 0x00, 0x9e, 0x99 },
	{ 0x00, 0x9e, 0x88 },
};

/**
 * @brief ms7210 regmap sequence
 */
static const struct reg_sequence ms7210_reg_init_seq[] = {
	/* Reset PLL Rx logic */
	{ 0x8112, 0x04 },
	{ 0x1600, 0x04 },
	{ 0x0900, 0x01 },
	{ 0x0700, 0x09 },
	{ 0x0800, 0xF0 },
	{ 0x0A00, 0xF0 },
	{ 0x0600, 0x11 },
	{ 0x3105, 0x84 },
	{ 0x0A05, 0x82 },
	{ 0x0905, 0x02 },
	{ 0x0B05, 0x0D },
	/* Reset TTL video process */
	{ 0x0D05, 0x04 },
	{ 0x0D05, 0x11 },
	{ 0x0D05, 0x58 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0E05, 0x40 },
	{ 0x0A05, 0x84 },
	{ 0x0905, 0x01 },
	{ 0x0B05, 0x0A },
	{ 0x0D05, 0x70 },
	{ 0x0D05, 0x01 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0E05, 0x60 },
	{ 0x0009, 0x20 },
	{ 0x0109, 0x47 },
	{ 0x0409, 0x09 },
	{ 0x2309, 0x07 },
	{ 0x2409, 0x44 },
	{ 0x2509, 0x44 },
	{ 0x0F09, 0x80 },
	{ 0x1F09, 0x07 },
	{ 0x2009, 0x1E }
};

static const struct reg_sequence ms7210_afe_low_seq[] = {
	/* pll low */
	{ 0x0B00, 0x00 },
	{ 0x0705, 0x06 },
	{ 0x0609, 0x00 },
	{ 0x2009, 0x1E },
	{ 0x2609, 0x11 },
	/* pclk < 100M */
	{ 0x2709, 0x01 },
	{ 0x2809, 0x11 },
	{ 0x2909, 0x01 },
	{ 0x1009, 0x01 },
	{ 0x0E05, 0x20 },
	{ 0x0A05, 0x82 },
	{ 0x0905, 0x02 },
	{ 0x0B05, 0x0D },
	{ 0x0D05, 0x04 },
	{ 0x0D05, 0x11 },
	{ 0x0D05, 0x58 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0E05, 0x60 },
	{ 0x0B00, 0x11 },
	{ 0x0705, 0x00 }

};

static const struct reg_sequence ms7210_afe_high_seq[] = {
	/* pll high */
	{ 0x0B00, 0x00 },
	{ 0x0705, 0x06 },
	{ 0x0609, 0x04 },
	{ 0x2009, 0x5E },
	{ 0x2609, 0xDD },
	{ 0x2709, 0x0D },
	/* pclk > 100M */
	{ 0x2809, 0x88 },
	{ 0x2909, 0x08 },
	{ 0x1009, 0x01 },
	{ 0x0E05, 0x20 },
	{ 0x0A05, 0x82 },
	{ 0x0905, 0x02 },
	{ 0x0B05, 0x0D },
	{ 0x0D05, 0x04 },
	{ 0x0D05, 0x11 },
	{ 0x0D05, 0x58 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0D05, 0x00 },
	{ 0x0E05, 0x60 },
	{ 0x0B00, 0x11 },
	{ 0x0705, 0x00 }
};

static const struct reg_sequence ms7210_audio_init_seq[] = {
	{ 0x0c00, 0x8c },
	{ 0x0604, 0xf0 },
	{ 0x0400, 0x01 },
	{ 0x0104, 0x1c },
	{ 0x0904, 0x43 },
	{ 0x0800, 0xf3 },
	{ 0xa500, 0x10 },
	{ 0x0a00, 0xf2 },
	{ 0x3005, 0x31 },
	{ 0x0004, 0x16 },
	{ 0x7005, 0x81 },
};

#endif
