1 /*
2  * Copyright (C) 2016 Stefan Roese <sr@denx.de>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <asm/io.h>
9 #include <asm/pnp_def.h>
10 
11 #define WINBOND_ENTRY_KEY	0x87
12 #define WINBOND_EXIT_KEY	0xaa
13 
14 /* Enable configuration: pass entry key '0x87' into index port dev twice */
15 static void pnp_enter_conf_state(u16 dev)
16 {
17 	u16 port = dev >> 8;
18 
19 	outb(WINBOND_ENTRY_KEY, port);
20 	outb(WINBOND_ENTRY_KEY, port);
21 }
22 
23 /* Disable configuration: pass exit key '0xAA' into index port dev */
24 static void pnp_exit_conf_state(u16 dev)
25 {
26 	u16 port = dev >> 8;
27 
28 	outb(WINBOND_EXIT_KEY, port);
29 }
30 
31 /* Bring up early serial debugging output before the RAM is initialized */
32 void winbond_enable_serial(uint dev, uint iobase, uint irq)
33 {
34 	pnp_enter_conf_state(dev);
35 	pnp_set_logical_device(dev);
36 	pnp_set_enable(dev, 0);
37 	pnp_set_iobase(dev, PNP_IDX_IO0, iobase);
38 	pnp_set_irq(dev, PNP_IDX_IRQ0, irq);
39 	pnp_set_enable(dev, 1);
40 	pnp_exit_conf_state(dev);
41 }
42