blob: 48bbfb2019fb4ef02603742d907ea1e1181e7e91 [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;
Felix Helde37d7712018-07-26 20:02:38 +020036 u8 value;
Samuel Hollandc622dc52018-03-30 15:14:17 -050037
38 get_option(&power_on, "power_on_after_fail");
Felix Helde37d7712018-07-26 20:02:38 +020039
Samuel Hollandc622dc52018-03-30 15:14:17 -050040 pnp_enter_conf_mode(dev);
41 pnp_set_logical_device(dev);
Felix Helde37d7712018-07-26 20:02:38 +020042
43 value = pnp_read_config(dev, IT8720F_EC_PCR1);
44 if (power_on == MAINBOARD_POWER_KEEP)
45 value |= (1 << 5);
46 else
47 value &= ~(1 << 5);
48 pnp_write_config(dev, IT8720F_EC_PCR1, value);
49
50 value = pnp_read_config(dev, IT8720F_EC_PCR2);
51 if (power_on == MAINBOARD_POWER_ON)
52 value |= (1 << 5);
53 else
54 value &= ~(1 << 5);
55 pnp_write_config(dev, IT8720F_EC_PCR2, value);
56
Samuel Hollandc622dc52018-03-30 15:14:17 -050057 pnp_exit_conf_mode(dev);
58}
59
Samuel Holland1318ea62017-06-03 03:52:57 -050060static void it8720f_init(struct device *dev)
61{
62 const struct superio_ite_it8720f_config *conf;
63 const struct resource *res;
64
65 if (!dev->enabled)
66 return;
67
68 switch (dev->path.pnp.device) {
69 case IT8720F_EC:
70 conf = dev->chip_info;
71 res = find_resource(dev, PNP_IDX_IO0);
72 if (!conf || !res)
73 break;
74 ite_ec_init(res->base, &conf->ec);
Samuel Hollandc622dc52018-03-30 15:14:17 -050075 power_control_init(dev);
Samuel Holland1318ea62017-06-03 03:52:57 -050076 break;
77 case IT8720F_KBCK:
78 pc_keyboard_init(NO_AUX_DEVICE);
79 break;
80 default:
81 break;
82 }
83}
84
85static struct device_operations ops = {
86 .read_resources = pnp_read_resources,
87 .set_resources = pnp_set_resources,
88 .enable_resources = pnp_enable_resources,
89 .enable = pnp_enable,
90 .init = it8720f_init,
91 .ops_pnp_mode = &pnp_conf_mode_870155_aa,
92};
93
94static struct pnp_info pnp_dev_info[] = {
Felix Heldc40275b2017-12-27 22:11:30 +010095 { NULL, IT8720F_FDC,
Samuel Holland1318ea62017-06-03 03:52:57 -050096 PNP_IO0 | PNP_IRQ0 | PNP_DRQ0 | PNP_MSC0 | PNP_MSC1,
Samuel Holland7daac912017-06-06 22:55:01 -050097 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +010098 { NULL, IT8720F_SP1,
Samuel Holland1318ea62017-06-03 03:52:57 -050099 PNP_IO0 | PNP_IRQ0 | PNP_MSC0 | PNP_MSC1,
Samuel Holland7daac912017-06-06 22:55:01 -0500100 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +0100101 { NULL, IT8720F_SP2,
Samuel Holland1318ea62017-06-03 03:52:57 -0500102 PNP_IO0 | PNP_IRQ0 | PNP_MSC0 | PNP_MSC1,
Samuel Holland7daac912017-06-06 22:55:01 -0500103 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +0100104 { NULL, IT8720F_PP,
Samuel Holland1318ea62017-06-03 03:52:57 -0500105 PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_DRQ0 | PNP_MSC0,
Samuel Holland7daac912017-06-06 22:55:01 -0500106 0x0ff8, 0x0ffc, },
Felix Heldc40275b2017-12-27 22:11:30 +0100107 { NULL, IT8720F_EC,
Samuel Holland1318ea62017-06-03 03:52:57 -0500108 PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_MSC0 | PNP_MSC1 | PNP_MSC2 |
109 PNP_MSC3 | PNP_MSC4 | PNP_MSC5 | PNP_MSC6,
Samuel Holland7daac912017-06-06 22:55:01 -0500110 0x0ff8, 0x0ffc, },
Felix Heldc40275b2017-12-27 22:11:30 +0100111 { NULL, IT8720F_KBCK,
Samuel Holland1318ea62017-06-03 03:52:57 -0500112 PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_MSC0,
Samuel Holland7daac912017-06-06 22:55:01 -0500113 0x0fff, 0x0fff, },
Felix Heldc40275b2017-12-27 22:11:30 +0100114 { NULL, IT8720F_KBCM,
Samuel Holland1318ea62017-06-03 03:52:57 -0500115 PNP_IRQ0 | PNP_MSC0, },
Felix Heldc40275b2017-12-27 22:11:30 +0100116 { NULL, IT8720F_GPIO,
Samuel Holland1318ea62017-06-03 03:52:57 -0500117 PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_MSC0 | PNP_MSC1 | PNP_MSC2 |
118 PNP_MSC3 | PNP_MSC4 | PNP_MSC5 | PNP_MSC6 | PNP_MSC7 |
119 PNP_MSC8 | PNP_MSC9 | PNP_MSCA | PNP_MSCB | PNP_MSCD | PNP_MSCE,
Samuel Holland7daac912017-06-06 22:55:01 -0500120 0x0ff8, 0x0ff8, 0x0ff8, },
Felix Heldc40275b2017-12-27 22:11:30 +0100121 { NULL, IT8720F_CIR,
Samuel Holland1318ea62017-06-03 03:52:57 -0500122 PNP_IO0 | PNP_IRQ0 | PNP_MSC0,
Samuel Holland7daac912017-06-06 22:55:01 -0500123 0x0ff8, },
Samuel Holland1318ea62017-06-03 03:52:57 -0500124};
125
126static void enable_dev(struct device *dev)
127{
Felix Heldc40275b2017-12-27 22:11:30 +0100128 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
Samuel Holland1318ea62017-06-03 03:52:57 -0500129}
130
131struct chip_operations superio_ite_it8720f_ops = {
132 CHIP_NAME("ITE IT8720F Super I/O")
133 .enable_dev = enable_dev,
134};