// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2014 Freescale Semiconductor, Inc.
 *
 * FSL DCU Framebuffer driver
 */

#include <common.h>
#include <fsl_dcu_fb.h>
#include <asm/global_data.h>
#include "div64.h"
#include "../common/dcu_sii9022a.h"

DECLARE_GLOBAL_DATA_PTR;

unsigned int dcu_set_pixel_clock(unsigned int pixclock)
{
	unsigned long long div;

	div = (unsigned long long)(gd->bus_clk / 1000);
	div *= (unsigned long long)pixclock;
	do_div(div, 1000000000);

	return div;
}

int platform_dcu_init(struct fb_info *fbinfo,
		      unsigned int xres, unsigned int yres,
		      const char *port,
		      struct fb_videomode *dcu_fb_videomode)
{
	const char *name;
	unsigned int pixel_format;

	if (strncmp(port, "twr_lcd", 4) == 0) {
		name = "TWR_LCD_RGB card";
	} else {
		name = "HDMI";
		dcu_set_dvi_encoder(dcu_fb_videomode);
	}

	printf("DCU: Switching to %s monitor @ %ux%u\n", name, xres, yres);

	pixel_format = 32;
	fsl_dcu_init(fbinfo, xres, yres, pixel_format);

	return 0;
}
