coreboot-v2: drop this ugly historic union name in v2 that was dropped in v3
[coreboot.git] / src / superio / nsc / pc97317 / superio.c
1 /* Copyright 2000  AG Electronics Ltd. */
2 /* This code is distributed without warranty under the GPL v2 (see COPYING) */
3
4 #include <arch/io.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <device/pnp.h>
8 #include <stdlib.h>
9 #include "chip.h"
10 #include "pc97317.h"
11
12 static void init(device_t dev)
13 {
14         struct superio_nsc_pc97317_config *conf;
15         struct resource *res0, *res1;
16
17         if (!dev->enabled) {
18                 return;
19         }
20         conf = dev->chip_info;
21         switch(dev->path.pnp.device) {
22         case PC97317_SP1:
23                 res0 = find_resource(dev, PNP_IDX_IO0);
24                 init_uart8250(res0->base, &conf->com1);
25                 break;
26
27         case PC97317_SP2:
28                 res0 = find_resource(dev, PNP_IDX_IO0);
29                 init_uart8250(res0->base, &conf->com2);
30                 break;
31
32         case PC97317_KBCK:
33                 /* Enable keyboard */
34                 pnp_set_logical_device(dev);
35                 pnp_set_enable(dev, 0); /* Disable keyboard */
36                 pnp_write_config(dev, 0xf0, 0x40); /* Set KBC clock to 8 Mhz */
37                 pnp_set_enable(dev, 1); /* Enable keyboard */
38
39                 res0 = find_resource(dev, PNP_IDX_IO0);
40                 res1 = find_resource(dev, PNP_IDX_IO1);
41                 init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
42                 break;
43
44 #if 0
45         case PC97317_FDC:
46         {
47                 unsigned reg;
48                 /* Set up floppy in PS/2 mode */
49                 outb(0x09, SIO_CONFIG_RA);
50                 reg = inb(SIO_CONFIG_RD);
51                 reg = (reg & 0x3F) | 0x40;
52                 outb(reg, SIO_CONFIG_RD);
53                 outb(reg, SIO_CONFIG_RD);       /* Have to write twice to change! */
54                 break;
55         }
56 #endif
57         default:
58                 break;
59         }
60 }
61
62 static struct device_operations ops = {
63         .read_resources   = pnp_read_resources,
64         .set_resources    = pnp_set_resources,
65         .enable_resources = pnp_enable_resources,
66         .enable           = pnp_enable,
67         .init             = init,
68 };
69
70 static struct pnp_info pnp_dev_info[] = {
71  { &ops, PC97317_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0, { 0xffb, 0 }, { 0xffb, 0x4}, },
72  { &ops, PC97317_KBCM, PNP_IRQ0 },
73  { &ops, PC97317_RTC,  PNP_IO0 | PNP_IRQ0, { 0xfffe, 0}, },
74  { &ops, PC97317_FDC,  PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0xfffa, 0}, },
75  { &ops, PC97317_PP,   PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x03fc, 0}, },
76  { &ops, PC97317_SP2,  PNP_IO0 | PNP_IRQ0 | PNP_DRQ0 | PNP_DRQ1, { 0xfff8, 0 }, },
77  { &ops, PC97317_SP1,  PNP_IO0 | PNP_IRQ0, { 0xfff8, 0 }, },
78  { &ops, PC97317_GPIO, PNP_IO0, { 0xfff8, 0 } },
79  { &ops, PC97317_PM,   PNP_IO0, { 0xfffe, 0 } },
80 };
81
82 static void enable_dev(struct device *dev)
83 {
84         pnp_enable_devices(dev, &ops,
85                 ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
86 }
87
88 struct chip_operations superio_nsc_pc97317_ops = {
89         CHIP_NAME("NSC PC97317 Super I/O")
90         .enable_dev = enable_dev,
91 };