// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2012-2015 Panasonic Corporation
 * Copyright (C) 2015-2016 Socionext Inc.
 *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
 */

#include <common.h>
#include <dm.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/io.h>
#include <linux/serial_reg.h>
#include <linux/sizes.h>
#include <linux/errno.h>
#include <serial.h>
#include <fdtdec.h>

#define UNIPHIER_UART_REGSHIFT		2

#define UNIPHIER_UART_RX		(0 << (UNIPHIER_UART_REGSHIFT))
#define UNIPHIER_UART_TX		UNIPHIER_UART_RX
/* bit[15:8] = CHAR, bit[7:0] = FCR */
#define UNIPHIER_UART_CHAR_FCR		(3 << (UNIPHIER_UART_REGSHIFT))
#define   UNIPHIER_UART_FCR_MASK		GENMASK(7, 0)
/* bit[15:8] = LCR, bit[7:0] = MCR */
#define UNIPHIER_UART_LCR_MCR		(4 << (UNIPHIER_UART_REGSHIFT))
#define   UNIPHIER_UART_LCR_MASK		GENMASK(15, 8)
#define UNIPHIER_UART_LSR		(5 << (UNIPHIER_UART_REGSHIFT))
/* Divisor Latch Register */
#define UNIPHIER_UART_DLR		(9 << (UNIPHIER_UART_REGSHIFT))

struct uniphier_serial_priv {
	void __iomem *membase;
	unsigned int uartclk;
};

static int uniphier_serial_setbrg(struct udevice *dev, int baudrate)
{
	struct uniphier_serial_priv *priv = dev_get_priv(dev);
	static const unsigned int mode_x_div = 16;
	unsigned int divisor;

	divisor = DIV_ROUND_CLOSEST(priv->uartclk, mode_x_div * baudrate);

	/* flush the trasmitter before changing hw setting */
	while (!(readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_TEMT))
		;

	writel(divisor, priv->membase + UNIPHIER_UART_DLR);

	return 0;
}

static int uniphier_serial_getc(struct udevice *dev)
{
	struct uniphier_serial_priv *priv = dev_get_priv(dev);

	if (!(readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_DR))
		return -EAGAIN;

	return readl(priv->membase + UNIPHIER_UART_RX);
}

static int uniphier_serial_putc(struct udevice *dev, const char c)
{
	struct uniphier_serial_priv *priv = dev_get_priv(dev);

	if (!(readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_THRE))
		return -EAGAIN;

	writel(c, priv->membase + UNIPHIER_UART_TX);

	return 0;
}

static int uniphier_serial_pending(struct udevice *dev, bool input)
{
	struct uniphier_serial_priv *priv = dev_get_priv(dev);

	if (input)
		return readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_DR;
	else
		return !(readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_THRE);
}

/*
 * SPL does not have enough memory footprint for the clock driver.
 * Hardcode clock frequency for each SoC.
 */
struct uniphier_serial_clk_data {
	const char *compatible;
	unsigned int clk_rate;
};

static const struct uniphier_serial_clk_data uniphier_serial_clk_data[] = {
	{ .compatible = "socionext,uniphier-ld4",  .clk_rate = 36864000 },
	{ .compatible = "socionext,uniphier-pro4", .clk_rate = 73728000 },
	{ .compatible = "socionext,uniphier-sld8", .clk_rate = 80000000 },
	{ .compatible = "socionext,uniphier-pro5", .clk_rate = 73728000 },
	{ .compatible = "socionext,uniphier-pxs2", .clk_rate = 88888888 },
	{ .compatible = "socionext,uniphier-ld6b", .clk_rate = 88888888 },
	{ .compatible = "socionext,uniphier-ld11", .clk_rate = 58823529 },
	{ .compatible = "socionext,uniphier-ld20", .clk_rate = 58823529 },
	{ .compatible = "socionext,uniphier-pxs3", .clk_rate = 58823529 },
	{ /* sentinel */ },
};

static int uniphier_serial_probe(struct udevice *dev)
{
	struct uniphier_serial_priv *priv = dev_get_priv(dev);
	const struct uniphier_serial_clk_data *clk_data;
	ofnode root_node;
	fdt_addr_t base;
	u32 tmp;

	base = devfdt_get_addr(dev);
	if (base == FDT_ADDR_T_NONE)
		return -EINVAL;

	priv->membase = devm_ioremap(dev, base, SZ_64);
	if (!priv->membase)
		return -ENOMEM;

	root_node = ofnode_path("/");
	clk_data = uniphier_serial_clk_data;
	while (clk_data->compatible) {
		if (ofnode_device_is_compatible(root_node,
						clk_data->compatible))
			break;
		clk_data++;
	}

	if (WARN_ON(!clk_data->compatible))
		return -ENOTSUPP;

	priv->uartclk = clk_data->clk_rate;

	/* flush the trasmitter empty before changing hw setting */
	while (!(readl(priv->membase + UNIPHIER_UART_LSR) & UART_LSR_TEMT))
		;

	/* enable FIFO */
	tmp = readl(priv->membase + UNIPHIER_UART_CHAR_FCR);
	tmp &= ~UNIPHIER_UART_FCR_MASK;
	tmp |= FIELD_PREP(UNIPHIER_UART_FCR_MASK, UART_FCR_ENABLE_FIFO);
	writel(tmp, priv->membase + UNIPHIER_UART_CHAR_FCR);

	tmp = readl(priv->membase + UNIPHIER_UART_LCR_MCR);
	tmp &= ~UNIPHIER_UART_LCR_MASK;
	tmp |= FIELD_PREP(UNIPHIER_UART_LCR_MASK, UART_LCR_WLEN8);
	writel(tmp, priv->membase + UNIPHIER_UART_LCR_MCR);

	return 0;
}

static const struct udevice_id uniphier_uart_of_match[] = {
	{ .compatible = "socionext,uniphier-uart" },
	{ /* sentinel */ }
};

static const struct dm_serial_ops uniphier_serial_ops = {
	.setbrg = uniphier_serial_setbrg,
	.getc = uniphier_serial_getc,
	.putc = uniphier_serial_putc,
	.pending = uniphier_serial_pending,
};

U_BOOT_DRIVER(uniphier_serial) = {
	.name = "uniphier-uart",
	.id = UCLASS_SERIAL,
	.of_match = uniphier_uart_of_match,
	.probe = uniphier_serial_probe,
	.priv_auto_alloc_size = sizeof(struct uniphier_serial_priv),
	.ops = &uniphier_serial_ops,
};
