bd330bac4aa9e97b8d587e01d966b6e35716abd2
[coreboot.git] / src / superio / smsc / kbc1100 / superio.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 Advanced Micro Devices, 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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /* RAM driver for the SMSC KBC1100 Super I/O chip */
21
22 #include <arch/io.h>
23 #include <device/device.h>
24 #include <device/pnp.h>
25 #include <console/console.h>
26 #include <device/smbus.h>
27 #include <string.h>
28 #include <bitops.h>
29 #include <uart8250.h>
30 #include <pc80/keyboard.h>
31 #include <stdlib.h>
32 #include "chip.h"
33 #include "kbc1100.h"
34
35 /* Forward declarations */
36 static void enable_dev(device_t dev);
37 static void kbc1100_pnp_set_resources(device_t dev);
38 static void kbc1100_pnp_enable_resources(device_t dev);
39 static void kbc1100_pnp_enable(device_t dev);
40 static void kbc1100_init(device_t dev);
41
42 static void pnp_enter_conf_state(device_t dev);
43 static void pnp_exit_conf_state(device_t dev);
44
45 struct chip_operations superio_smsc_kbc1100_ops = {
46   CHIP_NAME("SMSC KBC1100 Super I/O")
47   .enable_dev = enable_dev
48 };
49
50 static struct device_operations ops = {
51   .read_resources   = pnp_read_resources,
52   .set_resources    = kbc1100_pnp_set_resources,
53   .enable_resources = kbc1100_pnp_enable_resources,
54   .enable           = kbc1100_pnp_enable,
55   .init             = kbc1100_init,
56 };
57
58 static struct pnp_info pnp_dev_info[] = {
59   { &ops, KBC1100_KBC,  PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, },
60 };
61
62 static void enable_dev(device_t dev)
63 {
64   pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
65 }
66
67 static void kbc1100_pnp_set_resources(device_t dev)
68 {
69   pnp_enter_conf_state(dev);
70   pnp_set_resources(dev);
71   pnp_exit_conf_state(dev);
72 }
73
74 static void kbc1100_pnp_enable_resources(device_t dev)
75 {
76   pnp_enter_conf_state(dev);
77   pnp_enable_resources(dev);
78   pnp_exit_conf_state(dev);
79 }
80
81 static void kbc1100_pnp_enable(device_t dev)
82 {
83   pnp_enter_conf_state(dev);
84   pnp_set_logical_device(dev);
85
86   if(dev->enabled) {
87     pnp_set_enable(dev, 1);
88   }
89   else {
90     pnp_set_enable(dev, 0);
91   }
92   pnp_exit_conf_state(dev);
93 }
94
95 static void kbc1100_init(device_t dev)
96 {
97   struct superio_smsc_kbc1100_config *conf = dev->chip_info;
98   struct resource *res0, *res1;
99
100   
101    
102   if (!dev->enabled) {
103     return;
104   }
105
106   switch(dev->path.pnp.device) {
107   
108   case KBC1100_KBC:
109     res0 = find_resource(dev, PNP_IDX_IO0);
110     res1 = find_resource(dev, PNP_IDX_IO1);
111     pc_keyboard_init(&conf->keyboard);
112     break;
113   }
114 }
115
116 static void pnp_enter_conf_state(device_t dev)
117 {
118   outb(0x55, dev->path.pnp.port);
119 }
120
121 static void pnp_exit_conf_state(device_t dev)
122 {
123   outb(0xaa, dev->path.pnp.port);
124 }