blob: 3ef6a5d9064c207bcb88936794856dee5f0f4093 [file] [log] [blame]
Andrew Wu00bf6472013-06-26 21:24:59 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 DMP Electronics Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Andrew Wu00bf6472013-06-26 21:24:59 +080014 */
15
16#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ops.h>
20#include <device/pci_ids.h>
21#include <pc80/mc146818rtc.h>
Andrew Wu3fa1a132013-10-09 18:57:20 +080022#include <pc80/keyboard.h>
Andrew Wu00bf6472013-06-26 21:24:59 +080023#include <string.h>
Andrew Wu1fefa842013-10-24 20:37:48 +080024#include <delay.h>
Andrew Wu00bf6472013-06-26 21:24:59 +080025#include "arch/io.h"
26#include "chip.h"
27#include "southbridge.h"
Andrew Wu33b09562013-10-25 16:22:57 +080028#include "cpu/dmp/dmp_post_code.h"
Andrew Wu00bf6472013-06-26 21:24:59 +080029
30/* IRQ number to S/B PCI Interrupt routing table reg(0x58/0xb4) mapping table. */
31static const unsigned char irq_to_int_routing[16] = {
32 0x0, 0x0, 0x0, 0x2, // IRQ0-2 is unmappable, IRQ3 = 2.
33 0x4, 0x5, 0x7, 0x6, // IRQ4-7 = 4, 5, 7, 6.
34 0x0, 0x1, 0x3, 0x9, // IRQ8 is unmappable, IRQ9-11 = 1, 3, 9.
35 0xb, 0x0, 0xd, 0xf // IRQ12 = b, IRQ13 is unmappable, IRQ14-15 = d, f.
36};
37
38/* S/B PCI Interrupt routing table reg(0x58) field bit shift. */
39#define EHCIH_IRQ_SHIFT 28
40#define OHCII_IRQ_SHIFT 24
41#define MAC_IRQ_SHIFT 16
42#define RT3_IRQ_SHIFT 12
43#define RT2_IRQ_SHIFT 8
44#define RT1_IRQ_SHIFT 4
45#define RT0_IRQ_SHIFT 0
46
47/* S/B Extend PCI Interrupt routing table reg(0xb4) field bit shift. */
Andrew Wu52914322013-07-09 21:29:25 +080048#define CAN_IRQ_SHIFT 28
49#define HDA_IRQ_SHIFT 20
Andrew Wu00bf6472013-06-26 21:24:59 +080050#define USBD_IRQ_SHIFT 16
51#define SIDE_IRQ_SHIFT 12
52#define PIDE_IRQ_SHIFT 8
53
Andrew Wu52914322013-07-09 21:29:25 +080054/* S/B function 1 Extend PCI Interrupt routing table reg 2(0xb4)
55 * field bit shift.
56 */
57#define SPI1_IRQ_SHIFT 8
58#define MOTOR_IRQ_SHIFT 0
59
Andrew Wu00bf6472013-06-26 21:24:59 +080060/* in-chip PCI device IRQs(0 for disabled). */
61#define EHCII_IRQ 5
62#define OHCII_IRQ 5
63#define MAC_IRQ 6
64
Andrew Wu52914322013-07-09 21:29:25 +080065#define CAN_IRQ 10
66#define HDA_IRQ 7
67#define USBD_IRQ 6
Andrew Wu00bf6472013-06-26 21:24:59 +080068#define PIDE_IRQ 5
69
Andrew Wu52914322013-07-09 21:29:25 +080070#define SPI1_IRQ 10
Andrew Wua4ae3102013-12-23 19:54:26 +080071#define I2C0_IRQ 10
Andrew Wu52914322013-07-09 21:29:25 +080072#define MOTOR_IRQ 11
73
Andrew Wu00bf6472013-06-26 21:24:59 +080074/* RT0-3 IRQs. */
75#define RT3_IRQ 3
76#define RT2_IRQ 4
77#define RT1_IRQ 5
78#define RT0_IRQ 6
79
80/* IDE legacy mode IRQs. */
81#define IDE1_LEGACY_IRQ 14
82#define IDE2_LEGACY_IRQ 15
83
84/* Internal parallel port */
85#define LPT_INT_C 0
86#define LPT_INT_ACK_SET 0
87#define LPT_UE 1
88#define LPT_PDMAS 0
89#define LPT_DREQS 0
90
Andrew Wu1fefa842013-10-24 20:37:48 +080091/* keyboard controller system flag timeout : 400 ms */
92#define KBC_TIMEOUT_SYS_FLAG 400
93
Andrew Wu00bf6472013-06-26 21:24:59 +080094static u8 get_pci_dev_func(device_t dev)
95{
96 return PCI_FUNC(dev->path.pci.devfn);
97}
98
99static void verify_dmp_keyboard_error(void)
100{
Andrew Wu33b09562013-10-25 16:22:57 +0800101 post_code(POST_DMP_KBD_FW_VERIFY_ERR);
Andrew Wu00bf6472013-06-26 21:24:59 +0800102 die("Internal keyboard firmware verify error!\n");
103}
104
105static void upload_dmp_keyboard_firmware(struct device *dev)
106{
107 u32 reg_sb_c0;
108 u32 fwptr;
109
110 // enable firmware uploading function by set bit 10.
Andrew Wu33b09562013-10-25 16:22:57 +0800111 post_code(POST_DMP_KBD_FW_UPLOAD);
Andrew Wu00bf6472013-06-26 21:24:59 +0800112 reg_sb_c0 = pci_read_config32(dev, SB_REG_IPFCR);
113 pci_write_config32(dev, SB_REG_IPFCR, reg_sb_c0 | 0x400);
114
115 outw(0, 0x62); // reset upload address to 0.
116 // upload 4096 bytes from 0xFFFFE000.
117 outsb(0x66, (u8 *) 0xffffe000, 4096);
118 // upload 4096 bytes from 0xFFFFC000.
119 outsb(0x66, (u8 *) 0xffffc000, 4096);
120
121 outw(0, 0x62); // reset upload address to 0.
122 // verify 4096 bytes from 0xFFFFE000.
123 for (fwptr = 0xffffe000; fwptr < 0xfffff000; fwptr++) {
124 if (inb(0x66) != *(u8 *) fwptr) {
125 verify_dmp_keyboard_error();
126 }
127 }
128 // verify 4096 bytes from 0xFFFFC000.
129 for (fwptr = 0xffffc000; fwptr < 0xffffd000; fwptr++) {
130 if (inb(0x66) != *(u8 *) fwptr) {
131 verify_dmp_keyboard_error();
132 }
133 }
134
135 // disable firmware uploading.
136 pci_write_config32(dev, SB_REG_IPFCR, reg_sb_c0 & ~0x400L);
Andrew Wu1ce48602013-10-19 01:33:08 +0800137}
138
Andrew Wu1fefa842013-10-24 20:37:48 +0800139static int kbc_wait_system_flag(void)
Andrew Wu1ce48602013-10-19 01:33:08 +0800140{
141 /* wait keyboard controller ready by checking system flag
142 * (status port bit 2).
143 */
Andrew Wu33b09562013-10-25 16:22:57 +0800144 post_code(POST_DMP_KBD_CHK_READY);
Andrew Wu1fefa842013-10-24 20:37:48 +0800145 u32 timeout;
146 for (timeout = KBC_TIMEOUT_SYS_FLAG;
147 timeout && ((inb(0x64) & 0x4) == 0); timeout--)
148 mdelay(1);
149
150 if (!timeout) {
151 printk(BIOS_WARNING, "Keyboard controller system flag timeout\n");
Andrew Wu00bf6472013-06-26 21:24:59 +0800152 }
Andrew Wu1fefa842013-10-24 20:37:48 +0800153 return !!timeout;
Andrew Wu00bf6472013-06-26 21:24:59 +0800154}
155
156static void pci_routing_fixup(struct device *dev)
157{
158 const unsigned slot[3] = { 0 };
159 const unsigned char slot_irqs[1][4] = {
160 {RT0_IRQ, RT1_IRQ, RT2_IRQ, RT3_IRQ},
161 };
162 const int slot_num = 1;
163 int i;
164 u32 int_routing = 0;
165 u32 ext_int_routing = 0;
166
167 /* assign PCI-e bridge (bus#0, dev#1, fn#0) IRQ to RT0. */
168 pci_assign_irqs(0, 1, slot_irqs[0]);
169
170 /* RT0 is enabled. */
171 int_routing |= irq_to_int_routing[RT0_IRQ] << RT0_IRQ_SHIFT;
172
173 /* assign PCI slot IRQs. */
174 for (i = 0; i < slot_num; i++) {
175 pci_assign_irqs(1, slot[i], slot_irqs[i]);
176 }
177
178 /* Read PCI slot IRQs to see if RT1-3 is used, and enables it */
179 for (i = 0; i < slot_num; i++) {
180 unsigned int funct;
181 device_t pdev;
182 u8 irq;
183
184 /* Each slot may contain up to eight functions. */
185 for (funct = 0; funct < 8; funct++) {
186 pdev = dev_find_slot(1, (slot[i] << 3) + funct);
187 if (!pdev)
188 continue;
189 irq = pci_read_config8(pdev, PCI_INTERRUPT_LINE);
190 if (irq == RT1_IRQ) {
191 int_routing |= irq_to_int_routing[RT1_IRQ] << RT1_IRQ_SHIFT;
192 } else if (irq == RT2_IRQ) {
193 int_routing |= irq_to_int_routing[RT2_IRQ] << RT2_IRQ_SHIFT;
194 } else if (irq == RT3_IRQ) {
195 int_routing |= irq_to_int_routing[RT3_IRQ] << RT3_IRQ_SHIFT;
196 }
197 }
198 }
199
200 /* Setup S/B PCI Interrupt routing table reg(0x58). */
201 int_routing |= irq_to_int_routing[EHCII_IRQ] << EHCIH_IRQ_SHIFT;
202 int_routing |= irq_to_int_routing[OHCII_IRQ] << OHCII_IRQ_SHIFT;
203 int_routing |= irq_to_int_routing[MAC_IRQ] << MAC_IRQ_SHIFT;
Andrew Wu52914322013-07-09 21:29:25 +0800204 pci_write_config32(dev, SB_REG_PIRQ_ROUTE, int_routing);
Andrew Wu00bf6472013-06-26 21:24:59 +0800205
206 /* Setup S/B PCI Extend Interrupt routing table reg(0xb4). */
Andrew Wu52914322013-07-09 21:29:25 +0800207 ext_int_routing |= irq_to_int_routing[CAN_IRQ] << CAN_IRQ_SHIFT;
208 ext_int_routing |= irq_to_int_routing[HDA_IRQ] << HDA_IRQ_SHIFT;
Andrew Wu00bf6472013-06-26 21:24:59 +0800209 ext_int_routing |= irq_to_int_routing[USBD_IRQ] << USBD_IRQ_SHIFT;
210#if CONFIG_IDE_NATIVE_MODE
211 /* IDE in native mode, only uses one IRQ. */
212 ext_int_routing |= irq_to_int_routing[0] << SIDE_IRQ_SHIFT;
213 ext_int_routing |= irq_to_int_routing[PIDE_IRQ] << PIDE_IRQ_SHIFT;
214#else
215 /* IDE in legacy mode, use IRQ 14, 15. */
216 ext_int_routing |= irq_to_int_routing[IDE2_LEGACY_IRQ] << SIDE_IRQ_SHIFT;
217 ext_int_routing |= irq_to_int_routing[IDE1_LEGACY_IRQ] << PIDE_IRQ_SHIFT;
218#endif
Andrew Wu52914322013-07-09 21:29:25 +0800219 pci_write_config32(dev, SB_REG_EXT_PIRQ_ROUTE, ext_int_routing);
Andrew Wu00bf6472013-06-26 21:24:59 +0800220
221 /* Assign in-chip PCI device IRQs. */
222 if (MAC_IRQ) {
223 unsigned char irqs[4] = { MAC_IRQ, 0, 0, 0 };
224 pci_assign_irqs(0, 0x8, irqs);
225 }
Edward O'Callaghanfc3643f2014-12-08 04:41:39 +1100226 if ((OHCII_IRQ != 0) && (EHCII_IRQ != 0)) {
Andrew Wu00bf6472013-06-26 21:24:59 +0800227 unsigned char irqs[4] = { OHCII_IRQ, EHCII_IRQ, 0, 0 };
228 pci_assign_irqs(0, 0xa, irqs);
229 }
Edward O'Callaghanfc3643f2014-12-08 04:41:39 +1100230 if ((CONFIG_IDE_NATIVE_MODE != 0) && (PIDE_IRQ != 0)) {
Andrew Wu00bf6472013-06-26 21:24:59 +0800231 /* IDE in native mode, setup PCI IRQ. */
232 unsigned char irqs[4] = { PIDE_IRQ, 0, 0, 0 };
233 pci_assign_irqs(0, 0xc, irqs);
234 }
Andrew Wu52914322013-07-09 21:29:25 +0800235 if (CAN_IRQ) {
236 unsigned char irqs[4] = { CAN_IRQ, 0, 0, 0 };
237 pci_assign_irqs(0, 0x11, irqs);
238 }
239 if (HDA_IRQ) {
240 unsigned char irqs[4] = { HDA_IRQ, 0, 0, 0 };
241 pci_assign_irqs(0, 0xe, irqs);
242 }
Andrew Wu00bf6472013-06-26 21:24:59 +0800243 if (USBD_IRQ) {
244 unsigned char irqs[4] = { USBD_IRQ, 0, 0, 0 };
245 pci_assign_irqs(0, 0xf, irqs);
246 }
247}
248
249static void vortex_sb_init(struct device *dev)
250{
251 u32 lpt_reg = 0;
252
253#if CONFIG_LPT_ENABLE
254 int ppmod = 0;
255#if CONFIG_LPT_MODE_BPP
256 ppmod = 0;
257#elif CONFIG_LPT_MODE_EPP_19_AND_SPP
258 ppmod = 1;
259#elif CONFIG_LPT_MODE_ECP
260 ppmod = 2;
261#elif CONFIG_LPT_MODE_ECP_AND_EPP_19
262 ppmod = 3;
263#elif CONFIG_LPT_MODE_SPP
264 ppmod = 4;
265#elif CONFIG_LPT_MODE_EPP_17_AND_SPP
266 ppmod = 5;
267#elif CONFIG_LPT_MODE_ECP_AND_EPP_17
268 ppmod = 7;
269#else
270#error CONFIG_LPT_MODE error.
271#endif
272
273 /* Setup internal parallel port */
274 lpt_reg |= (LPT_INT_C << 28);
275 lpt_reg |= (LPT_INT_ACK_SET << 27);
276 lpt_reg |= (ppmod << 24);
277 lpt_reg |= (LPT_UE << 23);
278 lpt_reg |= (LPT_PDMAS << 22);
279 lpt_reg |= (LPT_DREQS << 20);
280 lpt_reg |= (irq_to_int_routing[CONFIG_LPT_IRQ] << 16);
281 lpt_reg |= (CONFIG_LPT_IO << 0);
282#endif // CONFIG_LPT_ENABLE
283 pci_write_config32(dev, SB_REG_IPPCR, lpt_reg);
284}
285
286#define SETUP_GPIO_ADDR(n) \
287 u32 cfg##n = (CONFIG_GPIO_P##n##_DIR_ADDR << 16) | (CONFIG_GPIO_P##n##_DATA_ADDR);\
288 outl(cfg##n, base + 4 + (n * 4));\
289 gpio_enable_mask |= (1 << n);
290
291#define INIT_GPIO(n) \
292 outb(CONFIG_GPIO_P##n##_INIT_DIR, CONFIG_GPIO_P##n##_DIR_ADDR);\
293 outb(CONFIG_GPIO_P##n##_INIT_DATA, CONFIG_GPIO_P##n##_DATA_ADDR);
294
295static void ex_sb_gpio_init(struct device *dev)
296{
297 const int base = 0xb00;
298 u32 gpio_enable_mask = 0;
299 /* S/B register 63h - 62h : GPIO Port Config IO Base Address */
300 pci_write_config16(dev, SB_REG_GPIO_CFG_IO_BASE, base | 1);
301 /* Set GPIO port 0~9 base address.
302 * Config Base + 04h, 08h, 0ch... : GPIO port 0~9 data/dir decode addr.
303 * Bit 31-16 : DBA, GPIO direction base address.
304 * Bit 15-0 : DPBA, GPIO data port base address.
305 * */
306#if CONFIG_GPIO_P0_ENABLE
307 SETUP_GPIO_ADDR(0)
308#endif
309#if CONFIG_GPIO_P1_ENABLE
310 SETUP_GPIO_ADDR(1)
311#endif
312#if CONFIG_GPIO_P2_ENABLE
313 SETUP_GPIO_ADDR(2)
314#endif
315#if CONFIG_GPIO_P3_ENABLE
316 SETUP_GPIO_ADDR(3)
317#endif
318#if CONFIG_GPIO_P4_ENABLE
319 SETUP_GPIO_ADDR(4)
320#endif
321#if CONFIG_GPIO_P5_ENABLE
322 SETUP_GPIO_ADDR(5)
323#endif
324#if CONFIG_GPIO_P6_ENABLE
325 SETUP_GPIO_ADDR(6)
326#endif
327#if CONFIG_GPIO_P7_ENABLE
328 SETUP_GPIO_ADDR(7)
329#endif
330#if CONFIG_GPIO_P8_ENABLE
331 SETUP_GPIO_ADDR(8)
332#endif
333#if CONFIG_GPIO_P9_ENABLE
334 SETUP_GPIO_ADDR(9)
335#endif
336 /* Enable GPIO port 0~9. */
337 outl(gpio_enable_mask, base);
338 /* Set GPIO port 0-9 initial dir and data. */
339#if CONFIG_GPIO_P0_ENABLE
340 INIT_GPIO(0)
341#endif
342#if CONFIG_GPIO_P1_ENABLE
343 INIT_GPIO(1)
344#endif
345#if CONFIG_GPIO_P2_ENABLE
346 INIT_GPIO(2)
347#endif
348#if CONFIG_GPIO_P3_ENABLE
349 INIT_GPIO(3)
350#endif
351#if CONFIG_GPIO_P4_ENABLE
352 INIT_GPIO(4)
353#endif
354#if CONFIG_GPIO_P5_ENABLE
355 INIT_GPIO(5)
356#endif
357#if CONFIG_GPIO_P6_ENABLE
358 INIT_GPIO(6)
359#endif
360#if CONFIG_GPIO_P7_ENABLE
361 INIT_GPIO(7)
362#endif
363#if CONFIG_GPIO_P8_ENABLE
364 INIT_GPIO(8)
365#endif
366#if CONFIG_GPIO_P9_ENABLE
367 INIT_GPIO(9)
368#endif
369 /* Disable GPIO Port Config IO Base Address. */
370 pci_write_config16(dev, SB_REG_GPIO_CFG_IO_BASE, 0x0);
371}
372
373static u32 make_uart_config(u16 base, u8 irq)
374{
375 u8 mapped_irq = irq_to_int_routing[irq];
376 u32 cfg = 0;
377 cfg |= 1 << 23; // UE = enabled.
378 cfg |= (mapped_irq << 16); // UIRT.
379 cfg |= base; // UIOA.
380 return cfg;
381}
382
383#define SETUP_UART(n) \
384 uart_cfg = make_uart_config(CONFIG_UART##n##_IO, CONFIG_UART##n##_IRQ);\
Kyösti Mälkkia4c7b7a2014-02-16 06:55:41 +0200385 outl(uart_cfg, base + (n - 1) * 4);
Andrew Wu00bf6472013-06-26 21:24:59 +0800386
387static void ex_sb_uart_init(struct device *dev)
388{
389 const int base = 0xc00;
390 u32 uart_cfg = 0;
391 /* S/B register 61h - 60h : UART Config IO Base Address */
392 pci_write_config16(dev, SB_REG_UART_CFG_IO_BASE, base | 1);
393 /* setup UART */
394#if CONFIG_UART1_ENABLE
395 SETUP_UART(1)
396#endif
397#if CONFIG_UART2_ENABLE
398 SETUP_UART(2)
399#endif
400#if CONFIG_UART3_ENABLE
401 SETUP_UART(3)
402#endif
403#if CONFIG_UART4_ENABLE
404 SETUP_UART(4)
405#endif
406#if CONFIG_UART5_ENABLE
407 SETUP_UART(5)
408#endif
409#if CONFIG_UART6_ENABLE
410 SETUP_UART(6)
411#endif
412#if CONFIG_UART7_ENABLE
413 SETUP_UART(7)
414#endif
415#if CONFIG_UART8_ENABLE
416 SETUP_UART(8)
417#endif
418#if CONFIG_UART9_ENABLE
419 SETUP_UART(9)
420#endif
421#if CONFIG_UART10_ENABLE
422 SETUP_UART(10)
423#endif
424 /* Keep UART Config I/O base address */
425 //pci_write_config16(SB, SB_REG_UART_CFG_IO_BASE, 0x0);
426}
427
Andrew Wua4ae3102013-12-23 19:54:26 +0800428static void i2c_init(struct device *dev)
429{
430 u8 mapped_irq = irq_to_int_routing[I2C0_IRQ];
431 u32 cfg = 0;
432 cfg |= 1 << 31; // UE = enabled.
433 cfg |= (mapped_irq << 16); // IIRT0.
434 cfg |= CONFIG_I2C_BASE; // UIOA.
435 pci_write_config32(dev, SB_REG_II2CCR, cfg);
436}
437
Andrew Wu00bf6472013-06-26 21:24:59 +0800438static int get_rtc_update_in_progress(void)
439{
440 if (cmos_read(RTC_REG_A) & RTC_UIP)
441 return 1;
442 return 0;
443}
444
445static void unsafe_read_cmos_rtc(u8 rtc[7])
446{
447 rtc[0] = cmos_read(RTC_CLK_ALTCENTURY);
448 rtc[1] = cmos_read(RTC_CLK_YEAR);
449 rtc[2] = cmos_read(RTC_CLK_MONTH);
450 rtc[3] = cmos_read(RTC_CLK_DAYOFMONTH);
451 rtc[4] = cmos_read(RTC_CLK_HOUR);
452 rtc[5] = cmos_read(RTC_CLK_MINUTE);
453 rtc[6] = cmos_read(RTC_CLK_SECOND);
454}
455
456static void read_cmos_rtc(u8 rtc[7])
457{
458 /* Read RTC twice and check update-in-progress flag, to make
459 * sure RTC is correct */
460 u8 rtc_old[7], rtc_new[7];
461 while (get_rtc_update_in_progress()) ;
462 unsafe_read_cmos_rtc(rtc_new);
463 do {
464 memcpy(rtc_old, rtc_new, 7);
465 while (get_rtc_update_in_progress()) ;
466 unsafe_read_cmos_rtc(rtc_new);
467 } while (memcmp(rtc_new, rtc_old, 7) != 0);
468}
469
470/*
471 * Convert a number in decimal format into the BCD format.
472 * Return 255 if not a valid BCD value.
473 */
474static u8 bcd2dec(u8 bcd)
475{
476 u8 h, l;
477 h = bcd >> 4;
478 l = bcd & 0xf;
479 if (h > 9 || l > 9)
480 return 255;
481 return h * 10 + l;
482}
483
484static void fix_cmos_rtc_time(void)
485{
486 /* Read RTC data. */
487 u8 rtc[7];
488 read_cmos_rtc(rtc);
489
490 /* Convert RTC from BCD format to binary. */
491 u8 bin_rtc[7];
492 int i;
Daniele Forsic2519e52014-07-26 11:17:03 +0200493 for (i = 0; i < 7; i++) {
Andrew Wu00bf6472013-06-26 21:24:59 +0800494 bin_rtc[i] = bcd2dec(rtc[i]);
495 }
496
497 /* If RTC date is invalid, fix it. */
498 if (bin_rtc[0] > 99 || bin_rtc[1] > 99 || bin_rtc[2] > 12 || bin_rtc[3] > 31) {
499 /* Set PC compatible timing mode. */
500 cmos_write(0x26, RTC_REG_A);
501 cmos_write(0x02, RTC_REG_B);
502 /* Now setup a default date 2008/08/08 08:08:08. */
503 cmos_write(0x8, RTC_CLK_SECOND);
504 cmos_write(0x8, RTC_CLK_MINUTE);
505 cmos_write(0x8, RTC_CLK_HOUR);
506 cmos_write(0x6, RTC_CLK_DAYOFWEEK); /* Friday */
507 cmos_write(0x8, RTC_CLK_DAYOFMONTH);
508 cmos_write(0x8, RTC_CLK_MONTH);
509 cmos_write(0x8, RTC_CLK_YEAR);
510 cmos_write(0x20, RTC_CLK_ALTCENTURY);
511 }
512}
513
Andrew Wufea5b502013-10-31 20:12:09 +0800514static void vortex86_sb_set_io_resv(device_t dev, unsigned index, u32 base, u32 size)
Andrew Wu00bf6472013-06-26 21:24:59 +0800515{
516 struct resource *res;
Andrew Wufea5b502013-10-31 20:12:09 +0800517 res = new_resource(dev, index);
518 res->base = base;
519 res->size = size;
Andrew Wu00bf6472013-06-26 21:24:59 +0800520 res->limit = 0xffffUL;
521 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
522}
523
Andrew Wufea5b502013-10-31 20:12:09 +0800524static void vortex86_sb_set_spi_flash_size(device_t dev, unsigned index, u32 flash_size)
Andrew Wu00bf6472013-06-26 21:24:59 +0800525{
526 /* SPI flash is in topmost of 4G memory space */
527 struct resource *res;
Andrew Wufea5b502013-10-31 20:12:09 +0800528 res = new_resource(dev, index);
Andrew Wu00bf6472013-06-26 21:24:59 +0800529 res->base = 0x100000000LL - flash_size;
530 res->size = flash_size;
531 res->limit = 0xffffffffUL;
532 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
533}
534
535static void vortex86_sb_read_resources(device_t dev)
536{
537 u32 flash_size = 8 * 1024 * 1024;
538
539 pci_dev_read_resources(dev);
540
541 if (dev->device == 0x6011) {
542 /* It is EX CPU southbridge */
543 if (get_pci_dev_func(dev) != 0) {
544 /* only for function 0, skip function 1 */
545 return;
546 }
547 /* default SPI flash ROM is 64MB */
548 flash_size = 64 * 1024 * 1024;
549 }
550
Andrew Wufea5b502013-10-31 20:12:09 +0800551 /* Reserve space for legacy I/O */
552 vortex86_sb_set_io_resv(dev, 1, 0, 0x1000UL);
Andrew Wu00bf6472013-06-26 21:24:59 +0800553
554 /* Reserve space for flash */
Andrew Wufea5b502013-10-31 20:12:09 +0800555 vortex86_sb_set_spi_flash_size(dev, 2, flash_size);
Andrew Wua4ae3102013-12-23 19:54:26 +0800556
557 /* Reserve space for I2C */
558 vortex86_sb_set_io_resv(dev, 3, CONFIG_I2C_BASE, 8);
Andrew Wu00bf6472013-06-26 21:24:59 +0800559}
560
Andrew Wu52914322013-07-09 21:29:25 +0800561static void southbridge_init_func1(struct device *dev)
562{
563 /* Handle S/B function 1 PCI IRQ routing. (SPI1/MOTOR) */
564 u32 ext_int_routing2 = 0;
565 /* Setup S/B function 1 PCI Extend Interrupt routing table reg 2(0xb4). */
566 ext_int_routing2 |= irq_to_int_routing[SPI1_IRQ] << SPI1_IRQ_SHIFT;
567 ext_int_routing2 |= irq_to_int_routing[MOTOR_IRQ] << MOTOR_IRQ_SHIFT;
568 pci_write_config32(dev, SB1_REG_EXT_PIRQ_ROUTE2, ext_int_routing2);
569
570 /* Assign in-chip PCI device IRQs. */
Edward O'Callaghanfc3643f2014-12-08 04:41:39 +1100571 if ((SPI1_IRQ != 0) || (MOTOR_IRQ != 0)) {
Andrew Wu52914322013-07-09 21:29:25 +0800572 unsigned char irqs[4] = { MOTOR_IRQ, SPI1_IRQ, 0, 0 };
573 pci_assign_irqs(0, 0x10, irqs);
574 }
575}
576
Andrew Wu00bf6472013-06-26 21:24:59 +0800577static void southbridge_init(struct device *dev)
578{
Andrew Wu52914322013-07-09 21:29:25 +0800579 /* Check it is function 0 or 1. (Same Vendor/Device ID) */
580 if (get_pci_dev_func(dev) != 0) {
581 southbridge_init_func1(dev);
582 return;
Andrew Wu00bf6472013-06-26 21:24:59 +0800583 }
584 upload_dmp_keyboard_firmware(dev);
585 vortex_sb_init(dev);
586 if (dev->device == 0x6011) {
587 ex_sb_gpio_init(dev);
588 ex_sb_uart_init(dev);
Andrew Wua4ae3102013-12-23 19:54:26 +0800589 i2c_init(dev);
Andrew Wu00bf6472013-06-26 21:24:59 +0800590 }
591 pci_routing_fixup(dev);
592
593 fix_cmos_rtc_time();
Gabe Blackb3f08c62014-04-30 17:12:25 -0700594 cmos_init(0);
Andrew Wu1fefa842013-10-24 20:37:48 +0800595 /* Check keyboard controller ready. If timeout, reload firmware code
596 * and try again.
597 */
598 u32 retries = 10;
599 while (!kbc_wait_system_flag()) {
600 if (!retries) {
601 post_code(POST_DMP_KBD_IS_BAD);
602 die("The keyboard timeout occurred too often. "
603 "Your CPU is probably defect. "
604 "Contact your dealer to replace it\n");
605 }
606 upload_dmp_keyboard_firmware(dev);
607 retries--;
608 }
609 post_code(POST_DMP_KBD_IS_READY);
Edward O'Callaghandef00be2014-04-30 05:01:52 +1000610 pc_keyboard_init();
Andrew Wu00bf6472013-06-26 21:24:59 +0800611}
612
613static struct device_operations vortex_sb_ops = {
614 .read_resources = vortex86_sb_read_resources,
615 .set_resources = pci_dev_set_resources,
616 .enable_resources = pci_dev_enable_resources,
617 .init = &southbridge_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200618 .scan_bus = scan_lpc_bus,
Andrew Wu00bf6472013-06-26 21:24:59 +0800619 .enable = 0,
620 .ops_pci = 0,
621};
622
623static const struct pci_driver pci_driver_6011 __pci_driver = {
624 .ops = &vortex_sb_ops,
625 .vendor = PCI_VENDOR_ID_RDC,
626 .device = 0x6011, /* EX CPU S/B ID */
627};
628
629struct chip_operations southbridge_dmp_vortex86ex_ops = {
630 CHIP_NAME("DMP Vortex86EX Southbridge")
631 .enable_dev = 0
632};