2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
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; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <device/device.h>
22 #include <device/pnp.h>
24 #include <pc80/keyboard.h>
30 static void pnp_enter_ext_func_mode(device_t dev)
32 u16 port = dev->path.pnp.port;
37 outb((port == 0x4e) ? 0xaa : 0x55, port);
40 static void pnp_exit_ext_func_mode(device_t dev)
42 pnp_write_config(dev, 0x02, 0x02);
45 static inline u8 it8772f_envc_read(struct resource *res, u8 addr)
47 outb(addr, res->base + 5);
48 return inb(res->base + 6);
51 static inline void it8772f_envc_write(struct resource *res, u8 addr, u8 value)
53 outb(addr, res->base + 5);
54 outb(value, res->base + 6);
58 * Setup External Temperature to read via PECI into TMPINx register
60 static void it8772f_enable_peci(struct resource *res, int tmpin)
62 if (tmpin < 1 || tmpin > 3)
65 /* Enable PECI interface */
66 it8772f_envc_write(res, IT8772F_INTERFACE_SELECT,
67 IT8772F_INTERFACE_SEL_PECI |
68 IT8772F_INTERFACE_SPEED_TOLERANCE);
70 /* Setup External Temperature using PECI GetTemp */
71 it8772f_envc_write(res, IT8772F_EXTEMP_ADDRESS,
73 it8772f_envc_write(res, IT8772F_EXTEMP_COMMAND,
74 PECI_GETTEMP_COMMAND);
75 it8772f_envc_write(res, IT8772F_EXTEMP_WRITE_LENGTH,
76 PECI_GETTEMP_WRITE_LENGTH);
77 it8772f_envc_write(res, IT8772F_EXTEMP_READ_LENGTH,
78 PECI_GETTEMP_READ_LENGTH);
79 it8772f_envc_write(res, IT8772F_EXTEMP_CONTROL,
80 IT8772F_EXTEMP_CONTROL_AUTO_4HZ |
81 IT8772F_EXTEMP_CONTROL_AUTO_START);
83 /* External Temperature reported in TMPINx register */
84 it8772f_envc_write(res, IT8772F_ADC_TEMP_CHANNEL_ENABLE,
89 * Setup a FAN PWM interface for software control
91 static void it8772f_enable_fan(struct resource *res, int fan)
95 if (fan < 1 || fan > 3)
98 /* Enable 6MHz (23.43kHz PWM) active high output */
99 reg = it8772f_envc_read(res, IT8772F_FAN_CTL_MODE);
100 reg |= IT8772F_FAN_CTL_ON(fan) |
101 IT8772F_FAN_PWM_CLOCK_6MHZ |
102 IT8772F_FAN_CTL_POLARITY_HIGH;
103 it8772f_envc_write(res, IT8772F_FAN_CTL_MODE, reg);
105 /* Enable output in smart mode */
106 reg = it8772f_envc_read(res, IT8772F_FAN_MAIN_CTL);
107 reg |= IT8772F_FAN_MAIN_CTL_TAC_SMART(fan);
108 reg |= IT8772F_FAN_MAIN_CTL_TAC_EN(fan);
109 it8772f_envc_write(res, IT8772F_FAN_MAIN_CTL, reg);
113 /* Enable software operation */
114 it8772f_envc_write(res, IT8772F_FAN_CTL2_PWM_MODE,
115 IT8772F_FAN_CTL_PWM_MODE_SOFTWARE);
116 /* Disable Smoothing */
117 it8772f_envc_write(res, IT8772F_FAN_CTL2_AUTO_MODE,
118 IT8772F_FAN_CTL_AUTO_SMOOTHING_DIS);
119 /* Set a default medium fan speed */
120 it8772f_envc_write(res, IT8772F_FAN_CTL2_PWM_START, 0x80);
123 /* Enable software operation */
124 it8772f_envc_write(res, IT8772F_FAN_CTL3_PWM_MODE,
125 IT8772F_FAN_CTL_PWM_MODE_SOFTWARE);
126 /* Disable Smoothing */
127 it8772f_envc_write(res, IT8772F_FAN_CTL3_AUTO_MODE,
128 IT8772F_FAN_CTL_AUTO_SMOOTHING_DIS);
129 /* Set a default medium fan speed */
130 it8772f_envc_write(res, IT8772F_FAN_CTL3_PWM_START, 0x80);
135 static void it8772f_init(device_t dev)
137 struct superio_ite_it8772f_config *conf = dev->chip_info;
138 struct resource *res;
143 switch (dev->path.pnp.device) {
145 res = find_resource(dev, PNP_IDX_IO0);
149 /* Enable PECI if configured */
150 it8772f_enable_peci(res, conf->peci_tmpin);
152 /* Enable FANx if configured */
153 if (conf->fan1_enable)
154 it8772f_enable_fan(res, 1);
155 if (conf->fan2_enable)
156 it8772f_enable_fan(res, 2);
157 if (conf->fan3_enable)
158 it8772f_enable_fan(res, 3);
161 /* Set GPIO output levels */
162 res = find_resource(dev, PNP_IDX_IO1);
165 outb(conf->gpio_set1, res->base + 0);
167 outb(conf->gpio_set2, res->base + 1);
169 outb(conf->gpio_set3, res->base + 2);
171 outb(conf->gpio_set4, res->base + 3);
173 outb(conf->gpio_set5, res->base + 4);
175 outb(conf->gpio_set6, res->base + 5);
179 if (!conf->skip_keyboard) {
181 pc_keyboard_init(&conf->keyboard);
191 static void it8772f_pnp_set_resources(device_t dev)
193 pnp_enter_ext_func_mode(dev);
194 pnp_set_resources(dev);
195 pnp_exit_ext_func_mode(dev);
198 static void it8772f_pnp_enable_resources(device_t dev)
200 pnp_enter_ext_func_mode(dev);
201 pnp_enable_resources(dev);
202 pnp_exit_ext_func_mode(dev);
205 static void it8772f_pnp_enable(device_t dev)
207 pnp_enter_ext_func_mode(dev);
208 pnp_set_logical_device(dev);
209 pnp_set_enable(dev, !!dev->enabled);
210 pnp_exit_ext_func_mode(dev);
213 static struct device_operations ops = {
214 .read_resources = pnp_read_resources,
215 .set_resources = it8772f_pnp_set_resources,
216 .enable_resources = it8772f_pnp_enable_resources,
217 .enable = it8772f_pnp_enable,
218 .init = it8772f_init,
221 static struct pnp_info pnp_dev_info[] = {
222 /* Floppy Disk Controller */
223 { &ops, IT8772F_FDC, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
225 { &ops, IT8772F_SP1, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
226 /* Environmental Controller */
227 { &ops, IT8772F_EC, PNP_IO0 | PNP_IO1 | PNP_IRQ0,
228 {0x0ff8, 0}, {0x0ffc, 4}, },
230 { &ops, IT8772F_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0,
231 {0x0fff, 0}, {0x0fff, 4}, },
233 { &ops, IT8772F_KBCM, PNP_IRQ0, },
235 { &ops, IT8772F_GPIO, PNP_IO0 | PNP_IO1,
236 {0x0fff, 0}, {0x0ff8, 0}, },
238 { &ops, IT8772F_IR, PNP_IO0 | PNP_IRQ0, {0x0ff8, 0}, },
241 static void enable_dev(struct device *dev)
243 pnp_enable_devices(dev, &pnp_ops,
244 ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
247 struct chip_operations superio_ite_it8772f_ops = {
248 CHIP_NAME("ITE IT8772F Super I/O")
249 .enable_dev = enable_dev,