Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 1 | /* |
| 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 Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 14 | */ |
| 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 Wu | 3fa1a13 | 2013-10-09 18:57:20 +0800 | [diff] [blame] | 22 | #include <pc80/keyboard.h> |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 23 | #include <string.h> |
Andrew Wu | 1fefa84 | 2013-10-24 20:37:48 +0800 | [diff] [blame] | 24 | #include <delay.h> |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 25 | #include "arch/io.h" |
| 26 | #include "chip.h" |
| 27 | #include "southbridge.h" |
Andrew Wu | 33b0956 | 2013-10-25 16:22:57 +0800 | [diff] [blame] | 28 | #include "cpu/dmp/dmp_post_code.h" |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 29 | |
| 30 | /* IRQ number to S/B PCI Interrupt routing table reg(0x58/0xb4) mapping table. */ |
| 31 | static 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 Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 48 | #define CAN_IRQ_SHIFT 28 |
| 49 | #define HDA_IRQ_SHIFT 20 |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 50 | #define USBD_IRQ_SHIFT 16 |
| 51 | #define SIDE_IRQ_SHIFT 12 |
| 52 | #define PIDE_IRQ_SHIFT 8 |
| 53 | |
Andrew Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 54 | /* 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 Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 60 | /* 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 Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 65 | #define CAN_IRQ 10 |
| 66 | #define HDA_IRQ 7 |
| 67 | #define USBD_IRQ 6 |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 68 | #define PIDE_IRQ 5 |
| 69 | |
Andrew Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 70 | #define SPI1_IRQ 10 |
Andrew Wu | a4ae310 | 2013-12-23 19:54:26 +0800 | [diff] [blame] | 71 | #define I2C0_IRQ 10 |
Andrew Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 72 | #define MOTOR_IRQ 11 |
| 73 | |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 74 | /* 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 Wu | 1fefa84 | 2013-10-24 20:37:48 +0800 | [diff] [blame] | 91 | /* keyboard controller system flag timeout : 400 ms */ |
| 92 | #define KBC_TIMEOUT_SYS_FLAG 400 |
| 93 | |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 94 | static u8 get_pci_dev_func(device_t dev) |
| 95 | { |
| 96 | return PCI_FUNC(dev->path.pci.devfn); |
| 97 | } |
| 98 | |
| 99 | static void verify_dmp_keyboard_error(void) |
| 100 | { |
Andrew Wu | 33b0956 | 2013-10-25 16:22:57 +0800 | [diff] [blame] | 101 | post_code(POST_DMP_KBD_FW_VERIFY_ERR); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 102 | die("Internal keyboard firmware verify error!\n"); |
| 103 | } |
| 104 | |
| 105 | static 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 Wu | 33b0956 | 2013-10-25 16:22:57 +0800 | [diff] [blame] | 111 | post_code(POST_DMP_KBD_FW_UPLOAD); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 112 | 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 Wu | 1ce4860 | 2013-10-19 01:33:08 +0800 | [diff] [blame] | 137 | } |
| 138 | |
Andrew Wu | 1fefa84 | 2013-10-24 20:37:48 +0800 | [diff] [blame] | 139 | static int kbc_wait_system_flag(void) |
Andrew Wu | 1ce4860 | 2013-10-19 01:33:08 +0800 | [diff] [blame] | 140 | { |
| 141 | /* wait keyboard controller ready by checking system flag |
| 142 | * (status port bit 2). |
| 143 | */ |
Andrew Wu | 33b0956 | 2013-10-25 16:22:57 +0800 | [diff] [blame] | 144 | post_code(POST_DMP_KBD_CHK_READY); |
Andrew Wu | 1fefa84 | 2013-10-24 20:37:48 +0800 | [diff] [blame] | 145 | 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 Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 152 | } |
Andrew Wu | 1fefa84 | 2013-10-24 20:37:48 +0800 | [diff] [blame] | 153 | return !!timeout; |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static 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 Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 204 | pci_write_config32(dev, SB_REG_PIRQ_ROUTE, int_routing); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 205 | |
| 206 | /* Setup S/B PCI Extend Interrupt routing table reg(0xb4). */ |
Andrew Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 207 | 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 Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 209 | 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 Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 219 | pci_write_config32(dev, SB_REG_EXT_PIRQ_ROUTE, ext_int_routing); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 220 | |
| 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'Callaghan | fc3643f | 2014-12-08 04:41:39 +1100 | [diff] [blame] | 226 | if ((OHCII_IRQ != 0) && (EHCII_IRQ != 0)) { |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 227 | unsigned char irqs[4] = { OHCII_IRQ, EHCII_IRQ, 0, 0 }; |
| 228 | pci_assign_irqs(0, 0xa, irqs); |
| 229 | } |
Edward O'Callaghan | fc3643f | 2014-12-08 04:41:39 +1100 | [diff] [blame] | 230 | if ((CONFIG_IDE_NATIVE_MODE != 0) && (PIDE_IRQ != 0)) { |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 231 | /* 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 Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 235 | 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 Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 243 | if (USBD_IRQ) { |
| 244 | unsigned char irqs[4] = { USBD_IRQ, 0, 0, 0 }; |
| 245 | pci_assign_irqs(0, 0xf, irqs); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | static 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 | |
| 295 | static 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 | |
| 373 | static 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älkki | a4c7b7a | 2014-02-16 06:55:41 +0200 | [diff] [blame] | 385 | outl(uart_cfg, base + (n - 1) * 4); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 386 | |
| 387 | static 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 Wu | a4ae310 | 2013-12-23 19:54:26 +0800 | [diff] [blame] | 428 | static 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 Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 438 | static 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 | |
| 445 | static 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 | |
| 456 | static 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 | */ |
| 474 | static 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 | |
| 484 | static 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 Forsi | c2519e5 | 2014-07-26 11:17:03 +0200 | [diff] [blame] | 493 | for (i = 0; i < 7; i++) { |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 494 | 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 Wu | fea5b50 | 2013-10-31 20:12:09 +0800 | [diff] [blame] | 514 | static void vortex86_sb_set_io_resv(device_t dev, unsigned index, u32 base, u32 size) |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 515 | { |
| 516 | struct resource *res; |
Andrew Wu | fea5b50 | 2013-10-31 20:12:09 +0800 | [diff] [blame] | 517 | res = new_resource(dev, index); |
| 518 | res->base = base; |
| 519 | res->size = size; |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 520 | res->limit = 0xffffUL; |
| 521 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 522 | } |
| 523 | |
Andrew Wu | fea5b50 | 2013-10-31 20:12:09 +0800 | [diff] [blame] | 524 | static void vortex86_sb_set_spi_flash_size(device_t dev, unsigned index, u32 flash_size) |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 525 | { |
| 526 | /* SPI flash is in topmost of 4G memory space */ |
| 527 | struct resource *res; |
Andrew Wu | fea5b50 | 2013-10-31 20:12:09 +0800 | [diff] [blame] | 528 | res = new_resource(dev, index); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 529 | 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 | |
| 535 | static 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 Wu | fea5b50 | 2013-10-31 20:12:09 +0800 | [diff] [blame] | 551 | /* Reserve space for legacy I/O */ |
| 552 | vortex86_sb_set_io_resv(dev, 1, 0, 0x1000UL); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 553 | |
| 554 | /* Reserve space for flash */ |
Andrew Wu | fea5b50 | 2013-10-31 20:12:09 +0800 | [diff] [blame] | 555 | vortex86_sb_set_spi_flash_size(dev, 2, flash_size); |
Andrew Wu | a4ae310 | 2013-12-23 19:54:26 +0800 | [diff] [blame] | 556 | |
| 557 | /* Reserve space for I2C */ |
| 558 | vortex86_sb_set_io_resv(dev, 3, CONFIG_I2C_BASE, 8); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 559 | } |
| 560 | |
Andrew Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 561 | static 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'Callaghan | fc3643f | 2014-12-08 04:41:39 +1100 | [diff] [blame] | 571 | if ((SPI1_IRQ != 0) || (MOTOR_IRQ != 0)) { |
Andrew Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 572 | unsigned char irqs[4] = { MOTOR_IRQ, SPI1_IRQ, 0, 0 }; |
| 573 | pci_assign_irqs(0, 0x10, irqs); |
| 574 | } |
| 575 | } |
| 576 | |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 577 | static void southbridge_init(struct device *dev) |
| 578 | { |
Andrew Wu | 5291432 | 2013-07-09 21:29:25 +0800 | [diff] [blame] | 579 | /* 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 Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 583 | } |
| 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 Wu | a4ae310 | 2013-12-23 19:54:26 +0800 | [diff] [blame] | 589 | i2c_init(dev); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 590 | } |
| 591 | pci_routing_fixup(dev); |
| 592 | |
| 593 | fix_cmos_rtc_time(); |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 594 | cmos_init(0); |
Andrew Wu | 1fefa84 | 2013-10-24 20:37:48 +0800 | [diff] [blame] | 595 | /* 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); |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 610 | pc_keyboard_init(NO_AUX_DEVICE); |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static 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älkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 618 | .scan_bus = scan_lpc_bus, |
Andrew Wu | 00bf647 | 2013-06-26 21:24:59 +0800 | [diff] [blame] | 619 | .enable = 0, |
| 620 | .ops_pci = 0, |
| 621 | }; |
| 622 | |
| 623 | static 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 | |
| 629 | struct chip_operations southbridge_dmp_vortex86ex_ops = { |
| 630 | CHIP_NAME("DMP Vortex86EX Southbridge") |
| 631 | .enable_dev = 0 |
| 632 | }; |