xref: /rk3399_rockchip-uboot/board/freescale/p1022ds/diu.c (revision 326ea986ac150acdc7656d57fca647db80b50158)
1d5e01e49STimur Tabi /*
2aa8d3fb8STimur Tabi  * Copyright 2010-2011 Freescale Semiconductor, Inc.
3d5e01e49STimur Tabi  * Authors: Timur Tabi <timur@freescale.com>
4d5e01e49STimur Tabi  *
5d5e01e49STimur Tabi  * FSL DIU Framebuffer driver
6d5e01e49STimur Tabi  *
7*1a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
8d5e01e49STimur Tabi  */
9d5e01e49STimur Tabi 
10d5e01e49STimur Tabi #include <common.h>
11d5e01e49STimur Tabi #include <command.h>
12ba8e76bdSTimur Tabi #include <linux/ctype.h>
13d5e01e49STimur Tabi #include <asm/io.h>
14d5e01e49STimur Tabi #include <stdio_dev.h>
15d5e01e49STimur Tabi #include <video_fb.h>
16d5e01e49STimur Tabi #include "../common/ngpixis.h"
17d5e01e49STimur Tabi #include <fsl_diu_fb.h>
18d5e01e49STimur Tabi 
1955b05237STimur Tabi /* The CTL register is called 'csr' in the ngpixis_t structure */
2055b05237STimur Tabi #define PX_CTL_ALTACC		0x80
2155b05237STimur Tabi 
2255b05237STimur Tabi #define PX_BRDCFG0_ELBC_SPI_MASK	0xc0
2355b05237STimur Tabi #define PX_BRDCFG0_ELBC_SPI_ELBC	0x00
2455b05237STimur Tabi #define PX_BRDCFG0_ELBC_SPI_NULL	0xc0
25d5e01e49STimur Tabi #define PX_BRDCFG0_ELBC_DIU		0x02
26d5e01e49STimur Tabi 
27d5e01e49STimur Tabi #define PX_BRDCFG1_DVIEN	0x80
28d5e01e49STimur Tabi #define PX_BRDCFG1_DFPEN	0x40
29d5e01e49STimur Tabi #define PX_BRDCFG1_BACKLIGHT	0x20
30d5e01e49STimur Tabi 
3155b05237STimur Tabi #define PMUXCR_ELBCDIU_MASK	0xc0000000
3255b05237STimur Tabi #define PMUXCR_ELBCDIU_NOR16	0x80000000
33fdb9482bSTimur Tabi #define PMUXCR_ELBCDIU_DIU	0x40000000
3455b05237STimur Tabi 
35d5e01e49STimur Tabi /*
36d5e01e49STimur Tabi  * DIU Area Descriptor
37d5e01e49STimur Tabi  *
38d5e01e49STimur Tabi  * Note that we need to byte-swap the value before it's written to the AD
39d5e01e49STimur Tabi  * register.  So even though the registers don't look like they're in the same
40d5e01e49STimur Tabi  * bit positions as they are on the MPC8610, the same value is written to the
41d5e01e49STimur Tabi  * AD register on the MPC8610 and on the P1022.
42d5e01e49STimur Tabi  */
43d5e01e49STimur Tabi #define AD_BYTE_F		0x10000000
44d5e01e49STimur Tabi #define AD_ALPHA_C_SHIFT	25
45d5e01e49STimur Tabi #define AD_BLUE_C_SHIFT		23
46d5e01e49STimur Tabi #define AD_GREEN_C_SHIFT	21
47d5e01e49STimur Tabi #define AD_RED_C_SHIFT		19
48d5e01e49STimur Tabi #define AD_PIXEL_S_SHIFT	16
49d5e01e49STimur Tabi #define AD_COMP_3_SHIFT		12
50d5e01e49STimur Tabi #define AD_COMP_2_SHIFT		8
51d5e01e49STimur Tabi #define AD_COMP_1_SHIFT		4
52d5e01e49STimur Tabi #define AD_COMP_0_SHIFT		0
53d5e01e49STimur Tabi 
5455b05237STimur Tabi /*
5555b05237STimur Tabi  * Variables used by the DIU/LBC switching code.  It's safe to makes these
5655b05237STimur Tabi  * global, because the DIU requires DDR, so we'll only run this code after
5755b05237STimur Tabi  * relocation.
5855b05237STimur Tabi  */
5955b05237STimur Tabi static u8 px_brdcfg0;
6055b05237STimur Tabi static u32 pmuxcr;
6155b05237STimur Tabi static void *lbc_lcs0_ba;
6255b05237STimur Tabi static void *lbc_lcs1_ba;
637a946961STimur Tabi static u32 old_br0, old_or0, old_br1, old_or1;
647a946961STimur Tabi static u32 new_br0, new_or0, new_br1, new_or1;
6555b05237STimur Tabi 
diu_set_pixel_clock(unsigned int pixclock)66d5e01e49STimur Tabi void diu_set_pixel_clock(unsigned int pixclock)
67d5e01e49STimur Tabi {
68d5e01e49STimur Tabi 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
69d5e01e49STimur Tabi 	unsigned long speed_ccb, temp;
70d5e01e49STimur Tabi 	u32 pixval;
71d5e01e49STimur Tabi 
72d5e01e49STimur Tabi 	speed_ccb = get_bus_freq(0);
73d5e01e49STimur Tabi 	temp = 1000000000 / pixclock;
74d5e01e49STimur Tabi 	temp *= 1000;
75d5e01e49STimur Tabi 	pixval = speed_ccb / temp;
761f09b44cSMarek Vasut 	debug("DIU pixval = %u\n", pixval);
77d5e01e49STimur Tabi 
78d5e01e49STimur Tabi 	/* Modify PXCLK in GUTS CLKDVDR */
79d5e01e49STimur Tabi 	temp = in_be32(&gur->clkdvdr) & 0x2000FFFF;
80d5e01e49STimur Tabi 	out_be32(&gur->clkdvdr, temp);			/* turn off clock */
81d5e01e49STimur Tabi 	out_be32(&gur->clkdvdr, temp | 0x80000000 | ((pixval & 0x1F) << 16));
82d5e01e49STimur Tabi }
83d5e01e49STimur Tabi 
platform_diu_init(unsigned int xres,unsigned int yres,const char * port)84ba8e76bdSTimur Tabi int platform_diu_init(unsigned int xres, unsigned int yres, const char *port)
85d5e01e49STimur Tabi {
86d5e01e49STimur Tabi 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
87ba8e76bdSTimur Tabi 	const char *name;
88d5e01e49STimur Tabi 	u32 pixel_format;
89d5e01e49STimur Tabi 	u8 temp;
907a946961STimur Tabi 	phys_addr_t phys0, phys1; /* BR0/BR1 physical addresses */
917a946961STimur Tabi 
927a946961STimur Tabi 	/*
937a946961STimur Tabi 	 * Indirect mode requires both BR0 and BR1 to be set to "GPCM",
947a946961STimur Tabi 	 * otherwise writes to these addresses won't actually appear on the
957a946961STimur Tabi 	 * local bus, and so the PIXIS won't see them.
967a946961STimur Tabi 	 *
977a946961STimur Tabi 	 * In FCM mode, writes go to the NAND controller, which does not pass
987a946961STimur Tabi 	 * them to the localbus directly.  So we force BR0 and BR1 into GPCM
997a946961STimur Tabi 	 * mode, since we don't care about what's behind the localbus any
1007a946961STimur Tabi 	 * more.  However, we save those registers first, so that we can
1017a946961STimur Tabi 	 * restore them when necessary.
1027a946961STimur Tabi 	 */
1037a946961STimur Tabi 	new_br0 = old_br0 = get_lbc_br(0);
1047a946961STimur Tabi 	new_br1 = old_br1 = get_lbc_br(1);
1057a946961STimur Tabi 	new_or0 = old_or0 = get_lbc_or(0);
1067a946961STimur Tabi 	new_or1 = old_or1 = get_lbc_or(1);
1077a946961STimur Tabi 
1087a946961STimur Tabi 	/*
1097a946961STimur Tabi 	 * Use the existing BRx/ORx values if it's already GPCM. Otherwise,
1107a946961STimur Tabi 	 * force the values to simple 32KB GPCM windows with the most
1117a946961STimur Tabi 	 * conservative timing.
1127a946961STimur Tabi 	 */
1137a946961STimur Tabi 	if ((old_br0 & BR_MSEL) != BR_MS_GPCM) {
1147a946961STimur Tabi 		new_br0 = (get_lbc_br(0) & BR_BA) | BR_V;
1157a946961STimur Tabi 		new_or0 = OR_AM_32KB | 0xFF7;
1167a946961STimur Tabi 		set_lbc_br(0, new_br0);
1177a946961STimur Tabi 		set_lbc_or(0, new_or0);
1187a946961STimur Tabi 	}
1197a946961STimur Tabi 	if ((old_br1 & BR_MSEL) != BR_MS_GPCM) {
1207a946961STimur Tabi 		new_br1 = (get_lbc_br(1) & BR_BA) | BR_V;
1217a946961STimur Tabi 		new_or1 = OR_AM_32KB | 0xFF7;
1227a946961STimur Tabi 		set_lbc_br(1, new_br1);
1237a946961STimur Tabi 		set_lbc_or(1, new_or1);
1247a946961STimur Tabi 	}
1257a946961STimur Tabi 
1267a946961STimur Tabi 	/*
1277a946961STimur Tabi 	 * Determine the physical addresses for Chip Selects 0 and 1.  The
1287a946961STimur Tabi 	 * BR0/BR1 registers contain the truncated physical addresses for the
1297a946961STimur Tabi 	 * chip selects, mapped via the localbus LAW.  Since the BRx registers
1307a946961STimur Tabi 	 * only contain the lower 32 bits of the address, we have to determine
1317a946961STimur Tabi 	 * the upper 4 bits some other way.  The proper way is to scan the LAW
1327a946961STimur Tabi 	 * table looking for a matching localbus address. Instead, we cheat.
1337a946961STimur Tabi 	 * We know that the upper bits are 0 for 32-bit addressing, or 0xF for
1347a946961STimur Tabi 	 * 36-bit addressing.
1357a946961STimur Tabi 	 */
1367a946961STimur Tabi #ifdef CONFIG_PHYS_64BIT
1377a946961STimur Tabi 	phys0 = 0xf00000000ULL | (old_br0 & old_or0 & BR_BA);
1387a946961STimur Tabi 	phys1 = 0xf00000000ULL | (old_br1 & old_or1 & BR_BA);
1397a946961STimur Tabi #else
1407a946961STimur Tabi 	phys0 = old_br0 & old_or0 & BR_BA;
1417a946961STimur Tabi 	phys1 = old_br1 & old_or1 & BR_BA;
1427a946961STimur Tabi #endif
143d5e01e49STimur Tabi 
14455b05237STimur Tabi 	 /* Save the LBC LCS0 and LCS1 addresses for the DIU mux functions */
1457a946961STimur Tabi 	lbc_lcs0_ba = map_physmem(phys0, 1, 0);
1467a946961STimur Tabi 	lbc_lcs1_ba = map_physmem(phys1, 1, 0);
14755b05237STimur Tabi 
148d5e01e49STimur Tabi 	pixel_format = cpu_to_le32(AD_BYTE_F | (3 << AD_ALPHA_C_SHIFT) |
149d5e01e49STimur Tabi 		(0 << AD_BLUE_C_SHIFT) | (1 << AD_GREEN_C_SHIFT) |
150d5e01e49STimur Tabi 		(2 << AD_RED_C_SHIFT) | (8 << AD_COMP_3_SHIFT) |
151d5e01e49STimur Tabi 		(8 << AD_COMP_2_SHIFT) | (8 << AD_COMP_1_SHIFT) |
152d5e01e49STimur Tabi 		(8 << AD_COMP_0_SHIFT) | (3 << AD_PIXEL_S_SHIFT));
153d5e01e49STimur Tabi 
154d5e01e49STimur Tabi 	temp = in_8(&pixis->brdcfg1);
155d5e01e49STimur Tabi 
156ba8e76bdSTimur Tabi 	if (strncmp(port, "lvds", 4) == 0) {
157ba8e76bdSTimur Tabi 		/* Single link LVDS */
158ba8e76bdSTimur Tabi 		temp &= ~PX_BRDCFG1_DVIEN;
159ba8e76bdSTimur Tabi 		/*
160ba8e76bdSTimur Tabi 		 * LVDS also needs backlight enabled, otherwise the display
161ba8e76bdSTimur Tabi 		 * will be blank.
162ba8e76bdSTimur Tabi 		 */
163ba8e76bdSTimur Tabi 		temp |= (PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT);
164ba8e76bdSTimur Tabi 		name = "Single-Link LVDS";
165d5e01e49STimur Tabi 	} else {	/* DVI */
166d5e01e49STimur Tabi 		/* Enable the DVI port, disable the DFP and the backlight */
167d5e01e49STimur Tabi 		temp &= ~(PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT);
168d5e01e49STimur Tabi 		temp |= PX_BRDCFG1_DVIEN;
169ba8e76bdSTimur Tabi 		name = "DVI";
170d5e01e49STimur Tabi 	}
171d5e01e49STimur Tabi 
172ba8e76bdSTimur Tabi 	printf("DIU:   Switching to %s monitor @ %ux%u\n", name, xres, yres);
173d5e01e49STimur Tabi 	out_8(&pixis->brdcfg1, temp);
174d5e01e49STimur Tabi 
175d5e01e49STimur Tabi 	/*
17655b05237STimur Tabi 	 * Enable PIXIS indirect access mode.  This is a hack that allows us to
17755b05237STimur Tabi 	 * access PIXIS registers even when the LBC pins have been muxed to the
17855b05237STimur Tabi 	 * DIU.
17955b05237STimur Tabi 	 */
18055b05237STimur Tabi 	setbits_8(&pixis->csr, PX_CTL_ALTACC);
18155b05237STimur Tabi 
18255b05237STimur Tabi 	/*
183d5e01e49STimur Tabi 	 * Route the LAD pins to the DIU.  This will disable access to the eLBC,
184d5e01e49STimur Tabi 	 * which means we won't be able to read/write any NOR flash addresses!
185d5e01e49STimur Tabi 	 */
18655b05237STimur Tabi 	out_8(lbc_lcs0_ba, offsetof(ngpixis_t, brdcfg0));
18755b05237STimur Tabi 	px_brdcfg0 = in_8(lbc_lcs1_ba);
18855b05237STimur Tabi 	out_8(lbc_lcs1_ba, px_brdcfg0 | PX_BRDCFG0_ELBC_DIU);
1897a946961STimur Tabi 	in_8(lbc_lcs1_ba);
190d5e01e49STimur Tabi 
191fdb9482bSTimur Tabi 	/* Set PMUXCR to switch the muxed pins from the LBC to the DIU */
192fdb9482bSTimur Tabi 	clrsetbits_be32(&gur->pmuxcr, PMUXCR_ELBCDIU_MASK, PMUXCR_ELBCDIU_DIU);
19355b05237STimur Tabi 	pmuxcr = in_be32(&gur->pmuxcr);
194d5e01e49STimur Tabi 
1953b4a2263STimur Tabi 	return fsl_diu_init(xres, yres, pixel_format, 0);
196d5e01e49STimur Tabi }
19755b05237STimur Tabi 
19855b05237STimur Tabi /*
19955b05237STimur Tabi  * set_mux_to_lbc - disable the DIU so that we can read/write to elbc
20055b05237STimur Tabi  *
20155b05237STimur Tabi  * On the Freescale P1022, the DIU video signal and the LBC address/data lines
20255b05237STimur Tabi  * share the same pins, which means that when the DIU is active (e.g. the
20355b05237STimur Tabi  * console is on the DVI display), NOR flash cannot be accessed.  So we use the
20455b05237STimur Tabi  * weak accessor feature of the CFI flash code to temporarily switch the pin
20555b05237STimur Tabi  * mux from DIU to LBC whenever we want to read or write flash.  This has a
20655b05237STimur Tabi  * significant performance penalty, but it's the only way to make it work.
20755b05237STimur Tabi  *
20855b05237STimur Tabi  * There are two muxes: one on the chip, and one on the board. The chip mux
20955b05237STimur Tabi  * controls whether the pins are used for the DIU or the LBC, and it is
21055b05237STimur Tabi  * set via PMUXCR.  The board mux controls whether those signals go to
21155b05237STimur Tabi  * the video connector or the NOR flash chips, and it is set via the ngPIXIS.
21255b05237STimur Tabi  */
set_mux_to_lbc(void)21355b05237STimur Tabi static int set_mux_to_lbc(void)
21455b05237STimur Tabi {
21555b05237STimur Tabi 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
21655b05237STimur Tabi 
21755b05237STimur Tabi 	/* Switch the muxes only if they're currently set to DIU mode */
218fdb9482bSTimur Tabi 	if ((in_be32(&gur->pmuxcr) & PMUXCR_ELBCDIU_MASK) !=
21955b05237STimur Tabi 	    PMUXCR_ELBCDIU_NOR16) {
22055b05237STimur Tabi 		/*
22155b05237STimur Tabi 		 * In DIU mode, the PIXIS can only be accessed indirectly
22255b05237STimur Tabi 		 * since we can't read/write the LBC directly.
22355b05237STimur Tabi 		 */
22455b05237STimur Tabi 		/* Set the board mux to LBC.  This will disable the display. */
22555b05237STimur Tabi 		out_8(lbc_lcs0_ba, offsetof(ngpixis_t, brdcfg0));
2267a946961STimur Tabi 		out_8(lbc_lcs1_ba, px_brdcfg0);
2277a946961STimur Tabi 		in_8(lbc_lcs1_ba);
22855b05237STimur Tabi 
22955b05237STimur Tabi 		/* Disable indirect PIXIS mode */
23055b05237STimur Tabi 		out_8(lbc_lcs0_ba, offsetof(ngpixis_t, csr));
23155b05237STimur Tabi 		clrbits_8(lbc_lcs1_ba, PX_CTL_ALTACC);
23255b05237STimur Tabi 
23355b05237STimur Tabi 		/* Set the chip mux to LBC mode, so that writes go to flash. */
23455b05237STimur Tabi 		out_be32(&gur->pmuxcr, (pmuxcr & ~PMUXCR_ELBCDIU_MASK) |
23555b05237STimur Tabi 			 PMUXCR_ELBCDIU_NOR16);
23655b05237STimur Tabi 		in_be32(&gur->pmuxcr);
23755b05237STimur Tabi 
2387a946961STimur Tabi 		/* Restore the BR0 and BR1 settings */
2397a946961STimur Tabi 		set_lbc_br(0, old_br0);
2407a946961STimur Tabi 		set_lbc_or(0, old_or0);
2417a946961STimur Tabi 		set_lbc_br(1, old_br1);
2427a946961STimur Tabi 		set_lbc_or(1, old_or1);
2437a946961STimur Tabi 
24455b05237STimur Tabi 		return 1;
24555b05237STimur Tabi 	}
24655b05237STimur Tabi 
24755b05237STimur Tabi 	return 0;
24855b05237STimur Tabi }
24955b05237STimur Tabi 
25055b05237STimur Tabi /*
25155b05237STimur Tabi  * set_mux_to_diu - re-enable the DIU muxing
25255b05237STimur Tabi  *
25355b05237STimur Tabi  * This function restores the chip and board muxing to point to the DIU.
25455b05237STimur Tabi  */
set_mux_to_diu(void)25555b05237STimur Tabi static void set_mux_to_diu(void)
25655b05237STimur Tabi {
25755b05237STimur Tabi 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
25855b05237STimur Tabi 
2597a946961STimur Tabi 	/* Set BR0 and BR1 to GPCM mode */
2607a946961STimur Tabi 	set_lbc_br(0, new_br0);
2617a946961STimur Tabi 	set_lbc_or(0, new_or0);
2627a946961STimur Tabi 	set_lbc_br(1, new_br1);
2637a946961STimur Tabi 	set_lbc_or(1, new_or1);
2647a946961STimur Tabi 
26555b05237STimur Tabi 	/* Enable indirect PIXIS mode */
26655b05237STimur Tabi 	setbits_8(&pixis->csr, PX_CTL_ALTACC);
26755b05237STimur Tabi 
26855b05237STimur Tabi 	/* Set the board mux to DIU.  This will enable the display. */
26955b05237STimur Tabi 	out_8(lbc_lcs0_ba, offsetof(ngpixis_t, brdcfg0));
2707a946961STimur Tabi 	out_8(lbc_lcs1_ba, px_brdcfg0 | PX_BRDCFG0_ELBC_DIU);
27155b05237STimur Tabi 	in_8(lbc_lcs1_ba);
27255b05237STimur Tabi 
27355b05237STimur Tabi 	/* Set the chip mux to DIU mode. */
27455b05237STimur Tabi 	out_be32(&gur->pmuxcr, pmuxcr);
27555b05237STimur Tabi 	in_be32(&gur->pmuxcr);
27655b05237STimur Tabi }
27755b05237STimur Tabi 
278aa8d3fb8STimur Tabi /*
279aa8d3fb8STimur Tabi  * pixis_read - board-specific function to read from the PIXIS
280aa8d3fb8STimur Tabi  *
281aa8d3fb8STimur Tabi  * This function overrides the generic pixis_read() function, so that it can
282aa8d3fb8STimur Tabi  * use PIXIS indirect mode if necessary.
283aa8d3fb8STimur Tabi  */
pixis_read(unsigned int reg)284aa8d3fb8STimur Tabi u8 pixis_read(unsigned int reg)
285aa8d3fb8STimur Tabi {
286aa8d3fb8STimur Tabi 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
287aa8d3fb8STimur Tabi 
288aa8d3fb8STimur Tabi 	/* Use indirect mode if the mux is currently set to DIU mode */
289aa8d3fb8STimur Tabi 	if ((in_be32(&gur->pmuxcr) & PMUXCR_ELBCDIU_MASK) !=
290aa8d3fb8STimur Tabi 	    PMUXCR_ELBCDIU_NOR16) {
291aa8d3fb8STimur Tabi 		out_8(lbc_lcs0_ba, reg);
292aa8d3fb8STimur Tabi 		return in_8(lbc_lcs1_ba);
293aa8d3fb8STimur Tabi 	} else {
294aa8d3fb8STimur Tabi 		void *p = (void *)PIXIS_BASE;
295aa8d3fb8STimur Tabi 
296aa8d3fb8STimur Tabi 		return in_8(p + reg);
297aa8d3fb8STimur Tabi 	}
298aa8d3fb8STimur Tabi }
299aa8d3fb8STimur Tabi 
300aa8d3fb8STimur Tabi /*
301aa8d3fb8STimur Tabi  * pixis_write - board-specific function to write to the PIXIS
302aa8d3fb8STimur Tabi  *
303aa8d3fb8STimur Tabi  * This function overrides the generic pixis_write() function, so that it can
304aa8d3fb8STimur Tabi  * use PIXIS indirect mode if necessary.
305aa8d3fb8STimur Tabi  */
pixis_write(unsigned int reg,u8 value)306aa8d3fb8STimur Tabi void pixis_write(unsigned int reg, u8 value)
307aa8d3fb8STimur Tabi {
308aa8d3fb8STimur Tabi 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
309aa8d3fb8STimur Tabi 
310aa8d3fb8STimur Tabi 	/* Use indirect mode if the mux is currently set to DIU mode */
311aa8d3fb8STimur Tabi 	if ((in_be32(&gur->pmuxcr) & PMUXCR_ELBCDIU_MASK) !=
312aa8d3fb8STimur Tabi 	    PMUXCR_ELBCDIU_NOR16) {
313aa8d3fb8STimur Tabi 		out_8(lbc_lcs0_ba, reg);
314aa8d3fb8STimur Tabi 		out_8(lbc_lcs1_ba, value);
315aa8d3fb8STimur Tabi 		/* Do a read-back to ensure the write completed */
316aa8d3fb8STimur Tabi 		in_8(lbc_lcs1_ba);
317aa8d3fb8STimur Tabi 	} else {
318aa8d3fb8STimur Tabi 		void *p = (void *)PIXIS_BASE;
319aa8d3fb8STimur Tabi 
320aa8d3fb8STimur Tabi 		out_8(p + reg, value);
321aa8d3fb8STimur Tabi 	}
322aa8d3fb8STimur Tabi }
323aa8d3fb8STimur Tabi 
pixis_bank_reset(void)324aa8d3fb8STimur Tabi void pixis_bank_reset(void)
325aa8d3fb8STimur Tabi {
326aa8d3fb8STimur Tabi 	/*
327aa8d3fb8STimur Tabi 	 * For some reason, a PIXIS bank reset does not work if the PIXIS is
328aa8d3fb8STimur Tabi 	 * in indirect mode, so switch to direct mode first.
329aa8d3fb8STimur Tabi 	 */
330aa8d3fb8STimur Tabi 	set_mux_to_lbc();
331aa8d3fb8STimur Tabi 
332aa8d3fb8STimur Tabi 	out_8(&pixis->vctl, 0);
333aa8d3fb8STimur Tabi 	out_8(&pixis->vctl, 1);
334aa8d3fb8STimur Tabi 
335aa8d3fb8STimur Tabi 	while (1);
336aa8d3fb8STimur Tabi }
337aa8d3fb8STimur Tabi 
338aa8d3fb8STimur Tabi #ifdef CONFIG_CFI_FLASH_USE_WEAK_ACCESSORS
339aa8d3fb8STimur Tabi 
flash_write8(u8 value,void * addr)34055b05237STimur Tabi void flash_write8(u8 value, void *addr)
34155b05237STimur Tabi {
34255b05237STimur Tabi 	int sw = set_mux_to_lbc();
34355b05237STimur Tabi 
34455b05237STimur Tabi 	__raw_writeb(value, addr);
345fdb9482bSTimur Tabi 	if (sw) {
346fdb9482bSTimur Tabi 		/*
347fdb9482bSTimur Tabi 		 * To ensure the post-write is completed to eLBC, software must
348fdb9482bSTimur Tabi 		 * perform a dummy read from one valid address from eLBC space
349fdb9482bSTimur Tabi 		 * before changing the eLBC_DIU from NOR mode to DIU mode.
350fdb9482bSTimur Tabi 		 * set_mux_to_diu() includes a sync that will ensure the
351fdb9482bSTimur Tabi 		 * __raw_readb() completes before it switches the mux.
352fdb9482bSTimur Tabi 		 */
353fdb9482bSTimur Tabi 		__raw_readb(addr);
35455b05237STimur Tabi 		set_mux_to_diu();
35555b05237STimur Tabi 	}
356fdb9482bSTimur Tabi }
35755b05237STimur Tabi 
flash_write16(u16 value,void * addr)35855b05237STimur Tabi void flash_write16(u16 value, void *addr)
35955b05237STimur Tabi {
36055b05237STimur Tabi 	int sw = set_mux_to_lbc();
36155b05237STimur Tabi 
36255b05237STimur Tabi 	__raw_writew(value, addr);
363fdb9482bSTimur Tabi 	if (sw) {
364fdb9482bSTimur Tabi 		/*
365fdb9482bSTimur Tabi 		 * To ensure the post-write is completed to eLBC, software must
366fdb9482bSTimur Tabi 		 * perform a dummy read from one valid address from eLBC space
367fdb9482bSTimur Tabi 		 * before changing the eLBC_DIU from NOR mode to DIU mode.
368fdb9482bSTimur Tabi 		 * set_mux_to_diu() includes a sync that will ensure the
369fdb9482bSTimur Tabi 		 * __raw_readb() completes before it switches the mux.
370fdb9482bSTimur Tabi 		 */
371fdb9482bSTimur Tabi 		__raw_readb(addr);
37255b05237STimur Tabi 		set_mux_to_diu();
37355b05237STimur Tabi 	}
374fdb9482bSTimur Tabi }
37555b05237STimur Tabi 
flash_write32(u32 value,void * addr)37655b05237STimur Tabi void flash_write32(u32 value, void *addr)
37755b05237STimur Tabi {
37855b05237STimur Tabi 	int sw = set_mux_to_lbc();
37955b05237STimur Tabi 
38055b05237STimur Tabi 	__raw_writel(value, addr);
381fdb9482bSTimur Tabi 	if (sw) {
382fdb9482bSTimur Tabi 		/*
383fdb9482bSTimur Tabi 		 * To ensure the post-write is completed to eLBC, software must
384fdb9482bSTimur Tabi 		 * perform a dummy read from one valid address from eLBC space
385fdb9482bSTimur Tabi 		 * before changing the eLBC_DIU from NOR mode to DIU mode.
386fdb9482bSTimur Tabi 		 * set_mux_to_diu() includes a sync that will ensure the
387fdb9482bSTimur Tabi 		 * __raw_readb() completes before it switches the mux.
388fdb9482bSTimur Tabi 		 */
389fdb9482bSTimur Tabi 		__raw_readb(addr);
39055b05237STimur Tabi 		set_mux_to_diu();
39155b05237STimur Tabi 	}
392fdb9482bSTimur Tabi }
39355b05237STimur Tabi 
flash_write64(u64 value,void * addr)39455b05237STimur Tabi void flash_write64(u64 value, void *addr)
39555b05237STimur Tabi {
39655b05237STimur Tabi 	int sw = set_mux_to_lbc();
397fdb9482bSTimur Tabi 	uint32_t *p = addr;
39855b05237STimur Tabi 
399fdb9482bSTimur Tabi 	/*
400fdb9482bSTimur Tabi 	 * There is no __raw_writeq(), so do the write manually.  We don't trust
401fdb9482bSTimur Tabi 	 * the compiler, so we use inline assembly.
402fdb9482bSTimur Tabi 	 */
403fdb9482bSTimur Tabi 	__asm__ __volatile__(
404fdb9482bSTimur Tabi 		"stw%U0%X0 %2,%0;\n"
405fdb9482bSTimur Tabi 		"stw%U1%X1 %3,%1;\n"
406fdb9482bSTimur Tabi 		: "=m" (*p), "=m" (*(p + 1))
407fdb9482bSTimur Tabi 		: "r" ((uint32_t) (value >> 32)), "r" ((uint32_t) (value)));
408fdb9482bSTimur Tabi 
409fdb9482bSTimur Tabi 	if (sw) {
410fdb9482bSTimur Tabi 		/*
411fdb9482bSTimur Tabi 		 * To ensure the post-write is completed to eLBC, software must
412fdb9482bSTimur Tabi 		 * perform a dummy read from one valid address from eLBC space
413fdb9482bSTimur Tabi 		 * before changing the eLBC_DIU from NOR mode to DIU mode.  We
414fdb9482bSTimur Tabi 		 * read addr+4 because we just wrote to addr+4, so that's how we
415fdb9482bSTimur Tabi 		 * maintain execution order.  set_mux_to_diu() includes a sync
416fdb9482bSTimur Tabi 		 * that will ensure the __raw_readb() completes before it
417fdb9482bSTimur Tabi 		 * switches the mux.
418fdb9482bSTimur Tabi 		 */
419fdb9482bSTimur Tabi 		__raw_readb(addr + 4);
42055b05237STimur Tabi 		set_mux_to_diu();
42155b05237STimur Tabi 	}
422fdb9482bSTimur Tabi }
42355b05237STimur Tabi 
flash_read8(void * addr)42455b05237STimur Tabi u8 flash_read8(void *addr)
42555b05237STimur Tabi {
42655b05237STimur Tabi 	u8 ret;
42755b05237STimur Tabi 
42855b05237STimur Tabi 	int sw = set_mux_to_lbc();
42955b05237STimur Tabi 
43055b05237STimur Tabi 	ret = __raw_readb(addr);
43155b05237STimur Tabi 	if (sw)
43255b05237STimur Tabi 		set_mux_to_diu();
43355b05237STimur Tabi 
43455b05237STimur Tabi 	return ret;
43555b05237STimur Tabi }
43655b05237STimur Tabi 
flash_read16(void * addr)43755b05237STimur Tabi u16 flash_read16(void *addr)
43855b05237STimur Tabi {
43955b05237STimur Tabi 	u16 ret;
44055b05237STimur Tabi 
44155b05237STimur Tabi 	int sw = set_mux_to_lbc();
44255b05237STimur Tabi 
44355b05237STimur Tabi 	ret = __raw_readw(addr);
44455b05237STimur Tabi 	if (sw)
44555b05237STimur Tabi 		set_mux_to_diu();
44655b05237STimur Tabi 
44755b05237STimur Tabi 	return ret;
44855b05237STimur Tabi }
44955b05237STimur Tabi 
flash_read32(void * addr)45055b05237STimur Tabi u32 flash_read32(void *addr)
45155b05237STimur Tabi {
45255b05237STimur Tabi 	u32 ret;
45355b05237STimur Tabi 
45455b05237STimur Tabi 	int sw = set_mux_to_lbc();
45555b05237STimur Tabi 
45655b05237STimur Tabi 	ret = __raw_readl(addr);
45755b05237STimur Tabi 	if (sw)
45855b05237STimur Tabi 		set_mux_to_diu();
45955b05237STimur Tabi 
46055b05237STimur Tabi 	return ret;
46155b05237STimur Tabi }
46255b05237STimur Tabi 
flash_read64(void * addr)46355b05237STimur Tabi u64 flash_read64(void *addr)
46455b05237STimur Tabi {
46555b05237STimur Tabi 	u64 ret;
46655b05237STimur Tabi 
46755b05237STimur Tabi 	int sw = set_mux_to_lbc();
46855b05237STimur Tabi 
46955b05237STimur Tabi 	/* There is no __raw_readq(), so do the read manually */
47055b05237STimur Tabi 	ret = *(volatile u64 *)addr;
47155b05237STimur Tabi 	if (sw)
47255b05237STimur Tabi 		set_mux_to_diu();
47355b05237STimur Tabi 
47455b05237STimur Tabi 	return ret;
47555b05237STimur Tabi }
47655b05237STimur Tabi 
47755b05237STimur Tabi #endif
478