blob: 142686e939f1e00d3c4b78bfab848015bcd8a645 [file] [log] [blame]
Samuel Holland1318ea62017-06-03 03:52:57 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2016 secunet Security Networks AG
5 * Copyright (C) 2017 Samuel Holland <samuel@sholland.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <device/device.h>
19#include <device/pnp.h>
20#include <pc80/keyboard.h>
Samuel Hollandc622dc52018-03-30 15:14:17 -050021#include <pc80/mc146818rtc.h>
Samuel Holland1318ea62017-06-03 03:52:57 -050022#include <superio/ite/common/env_ctrl.h>
23#include <superio/conf_mode.h>
Samuel Hollandc622dc52018-03-30 15:14:17 -050024#include <types.h>
Samuel Holland1318ea62017-06-03 03:52:57 -050025
26#include "chip.h"
27#include "it8720f.h"
28
Samuel Hollandc622dc52018-03-30 15:14:17 -050029#define MAINBOARD_POWER_OFF 0
30#define MAINBOARD_POWER_ON 1
31#define MAINBOARD_POWER_KEEP 2
32
33static void power_control_init(struct device *dev)
34{
35 int power_on = MAINBOARD_POWER_OFF;
36 u8 addr, value;
37
38 get_option(&power_on, "power_on_after_fail");
39 if (power_on == MAINBOARD_POWER_OFF)
40 return;
41 pnp_enter_conf_mode(dev);
42 pnp_set_logical_device(dev);
43 addr = power_on == MAINBOARD_POWER_KEEP ? 0xf2 : 0xf4;
44 value = pnp_read_config(dev, addr);
45 value |= BIT(5);
46 pnp_write_config(dev, addr, value);
47 pnp_exit_conf_mode(dev);
48}
49
Samuel Holland1318ea62017-06-03 03:52:57 -050050static void it8720f_init(struct device *dev)
51{
52 const struct superio_ite_it8720f_config *conf;
53 const struct resource *res;
54
55 if (!dev->enabled)
56 return;
57
58 switch (dev->path.pnp.device) {
59 case IT8720F_EC:
60 conf = dev->chip_info;
61 res = find_resource(dev, PNP_IDX_IO0);
62 if (!conf || !res)
63 break;
64 ite_ec_init(res->base, &conf->ec);
Samuel Hollandc622dc52018-03-30 15:14:17 -050065 power_control_init(dev);
Samuel Holland1318ea62017-06-03 03:52:57 -050066 break;
67 case IT8720F_KBCK:
68 pc_keyboard_init(NO_AUX_DEVICE);
69 break;
70 default:
71 break;
72 }
73}
74
75static struct device_operations ops = {
76 .read_resources = pnp_read_resources,
77 .set_resources = pnp_set_resources,
78 .enable_resources = pnp_enable_resources,
79 .enable = pnp_enable,
80 .init = it8720f_init,
81 .ops_pnp_mode = &pnp_conf_mode_870155_aa,
82};
83
84static struct pnp_info pnp_dev_info[] = {
Felix Heldc40275b2017-12-27 22:11:30 +010085 { NULL, IT8720F_FDC,
Samuel Holland1318ea62017-06-03 03:52:57 -050086 PNP_IO0 | PNP_IRQ0 | PNP_DRQ0 | PNP_MSC0 | PNP_MSC1,
Samuel Holland7daac912017-06-06 22:55:01 -050087 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +010088 { NULL, IT8720F_SP1,
Samuel Holland1318ea62017-06-03 03:52:57 -050089 PNP_IO0 | PNP_IRQ0 | PNP_MSC0 | PNP_MSC1,
Samuel Holland7daac912017-06-06 22:55:01 -050090 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +010091 { NULL, IT8720F_SP2,
Samuel Holland1318ea62017-06-03 03:52:57 -050092 PNP_IO0 | PNP_IRQ0 | PNP_MSC0 | PNP_MSC1,
Samuel Holland7daac912017-06-06 22:55:01 -050093 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +010094 { NULL, IT8720F_PP,
Samuel Holland1318ea62017-06-03 03:52:57 -050095 PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_DRQ0 | PNP_MSC0,
Samuel Holland7daac912017-06-06 22:55:01 -050096 0x0ff8, 0x0ffc, },
Felix Heldc40275b2017-12-27 22:11:30 +010097 { NULL, IT8720F_EC,
Samuel Holland1318ea62017-06-03 03:52:57 -050098 PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_MSC0 | PNP_MSC1 | PNP_MSC2 |
99 PNP_MSC3 | PNP_MSC4 | PNP_MSC5 | PNP_MSC6,
Samuel Holland7daac912017-06-06 22:55:01 -0500100 0x0ff8, 0x0ffc, },
Felix Heldc40275b2017-12-27 22:11:30 +0100101 { NULL, IT8720F_KBCK,
Samuel Holland1318ea62017-06-03 03:52:57 -0500102 PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_MSC0,
Samuel Holland7daac912017-06-06 22:55:01 -0500103 0x0fff, 0x0fff, },
Felix Heldc40275b2017-12-27 22:11:30 +0100104 { NULL, IT8720F_KBCM,
Samuel Holland1318ea62017-06-03 03:52:57 -0500105 PNP_IRQ0 | PNP_MSC0, },
Felix Heldc40275b2017-12-27 22:11:30 +0100106 { NULL, IT8720F_GPIO,
Samuel Holland1318ea62017-06-03 03:52:57 -0500107 PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_MSC0 | PNP_MSC1 | PNP_MSC2 |
108 PNP_MSC3 | PNP_MSC4 | PNP_MSC5 | PNP_MSC6 | PNP_MSC7 |
109 PNP_MSC8 | PNP_MSC9 | PNP_MSCA | PNP_MSCB | PNP_MSCD | PNP_MSCE,
Samuel Holland7daac912017-06-06 22:55:01 -0500110 0x0ff8, 0x0ff8, 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +0100111 { NULL, IT8720F_CIR,
Samuel Holland1318ea62017-06-03 03:52:57 -0500112 PNP_IO0 | PNP_IRQ0 | PNP_MSC0,
Samuel Holland7daac912017-06-06 22:55:01 -0500113 0x0ff8, },
Samuel Holland1318ea62017-06-03 03:52:57 -0500114};
115
116static void enable_dev(struct device *dev)
117{
Felix Heldc40275b2017-12-27 22:11:30 +0100118 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Samuel Holland1318ea62017-06-03 03:52:57 -0500119}
120
121struct chip_operations superio_ite_it8720f_ops = {
122 CHIP_NAME("ITE IT8720F Super I/O")
123 .enable_dev = enable_dev,
124};