1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/device.h>
7 #include <superio/nsc/pc87384/pc87384.h>
8 #include "ec/acpi/ec.h"
9 #include "ec/lenovo/pmh7/pmh7.h"
10 #include <southbridge/intel/i82801gx/i82801gx.h>
12 #define DLPC_CONTROL 0x164c
14 static void dlpc_write_register(int reg
, int value
)
20 static u8
dlpc_read_register(int reg
)
26 static void dock_write_register(int reg
, int value
)
32 static u8
dock_read_register(int reg
)
38 static void dlpc_gpio_set_mode(int port
, int mode
)
40 dlpc_write_register(0xf0, port
);
41 dlpc_write_register(0xf1, mode
);
44 static void dock_gpio_set_mode(int port
, int mode
, int irq
)
46 dock_write_register(0xf0, port
);
47 dock_write_register(0xf1, mode
);
48 dock_write_register(0xf2, irq
);
51 static void dlpc_gpio_init(void)
53 /* Select GPIO module */
54 dlpc_write_register(0x07, 0x07);
55 /* GPIO Base Address 0x1680 */
56 dlpc_write_register(0x60, 0x16);
57 dlpc_write_register(0x61, 0x80);
60 dlpc_write_register(0x30, 0x01);
62 dlpc_gpio_set_mode(0x00, 3);
63 dlpc_gpio_set_mode(0x01, 3);
64 dlpc_gpio_set_mode(0x02, 0);
65 dlpc_gpio_set_mode(0x03, 3);
66 dlpc_gpio_set_mode(0x04, 4);
67 dlpc_gpio_set_mode(0x20, 4);
68 dlpc_gpio_set_mode(0x21, 4);
69 dlpc_gpio_set_mode(0x23, 4);
76 /* Enable 14.318MHz CLK on CLKIN */
77 dlpc_write_register(0x29, 0xa0);
78 while (!(dlpc_read_register(0x29) & 0x10) && timeout
--)
84 /* Select DLPC module */
85 dlpc_write_register(0x07, 0x19);
86 /* DLPC Base Address */
87 dlpc_write_register(0x60, (DLPC_CONTROL
>> 8) & 0xff);
88 dlpc_write_register(0x61, DLPC_CONTROL
& 0xff);
90 dlpc_write_register(0x30, 0x01);
92 /* Reset docking state */
93 outb(0x00, DLPC_CONTROL
);
99 static int dock_superio_init(void)
102 /* startup 14.318MHz Clock */
103 dock_write_register(0x29, 0xa0);
104 /* wait until clock is settled */
105 while (!(dock_read_register(0x29) & 0x10) && timeout
--)
111 /* set GPIO pins to Serial/Parallel Port
114 dock_write_register(0x22, 0xa9);
116 /* enable serial port */
117 dock_write_register(0x07, PC87384_SP1
);
118 dock_write_register(0x30, 0x01);
120 dock_write_register(0x07, PC87384_GPIO
);
121 dock_write_register(0x60, 0x16);
122 dock_write_register(0x61, 0x20);
124 dock_write_register(0x30, 0x01);
126 dock_gpio_set_mode(0x00, PC87384_GPIO_PIN_DEBOUNCE
|
127 PC87384_GPIO_PIN_PULLUP
, 0x00);
129 dock_gpio_set_mode(0x01, PC87384_GPIO_PIN_TYPE_PUSH_PULL
|
130 PC87384_GPIO_PIN_OE
, 0x00);
132 dock_gpio_set_mode(0x02, PC87384_GPIO_PIN_TYPE_PUSH_PULL
|
133 PC87384_GPIO_PIN_OE
, 0x00);
135 dock_gpio_set_mode(0x03, PC87384_GPIO_PIN_DEBOUNCE
|
136 PC87384_GPIO_PIN_PULLUP
, 0x00);
138 dock_gpio_set_mode(0x04, PC87384_GPIO_PIN_DEBOUNCE
|
139 PC87384_GPIO_PIN_PULLUP
, 0x00);
141 dock_gpio_set_mode(0x05, PC87384_GPIO_PIN_DEBOUNCE
|
142 PC87384_GPIO_PIN_PULLUP
, 0x00);
144 dock_gpio_set_mode(0x06, PC87384_GPIO_PIN_DEBOUNCE
|
145 PC87384_GPIO_PIN_PULLUP
, 0x00);
147 dock_gpio_set_mode(0x07, PC87384_GPIO_PIN_DEBOUNCE
|
148 PC87384_GPIO_PIN_PULLUP
, 0x00);
150 /* no GPIO events enabled for PORT0 */
152 /* clear GPIO events on PORT0 */
155 /* no GPIO events enabled for PORT1 */
158 /* clear GPIO events on PORT1*/
165 int dock_connect(void)
169 outb(0x07, DLPC_CONTROL
);
173 while (!(inb(DLPC_CONTROL
) & 8) && timeout
--)
177 /* docking failed, disable DLPC switch */
178 outb(0x00, DLPC_CONTROL
);
179 dlpc_write_register(0x30, 0x00);
183 /* Assert D_PLTRST# */
186 /* Deassert D_PLTRST# */
190 return dock_superio_init();
193 void dock_disconnect(void)
195 /* disconnect LPC bus */
196 outb(0x00, DLPC_CONTROL
);
197 /* Assert PLTRST and DLPCPD */
201 int dock_present(void)
203 return pmh7_register_read(0x61) & 1;
206 int legacy_io_present(void)
208 return !(inb(DEFAULT_GPIOBASE
+ 0x0c) & 0x40);
211 void legacy_io_init(void)
213 /* Enable Power for Ultrabay slot */
214 pmh7_ultrabay_power_enable(1);