2 * This file is part of the coreboot project.
4 * Copyright (C) 2011-2012 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; version 2 of the License.
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.
16 #include <console/console.h>
20 #include <device/device.h>
21 #include <device/pci.h>
23 #include <southbridge/intel/bd82x6x/pch.h>
24 #include <ec/compal/ene932/ec.h>
29 #include <boot/coreboot_tables.h>
33 void fill_lb_gpios(struct lb_gpios
*gpios
)
35 device_t dev
= dev_find_slot(0, PCI_DEVFN(0x1f,0));
36 u16 gpio_base
= pci_read_config32(dev
, GPIOBASE
) & 0xfffe;
37 u16 gen_pmcon_1
= pci_read_config32(dev
, GEN_PMCON_1
);
42 gpios
->size
= sizeof(*gpios
) + (GPIO_COUNT
* sizeof(struct lb_gpio
));
43 gpios
->count
= GPIO_COUNT
;
45 /* Write Protect: GPIO70 active high */
46 gpios
->gpios
[0].port
= 70;
47 gpios
->gpios
[0].polarity
= ACTIVE_LOW
;
48 gpios
->gpios
[0].value
= !get_write_protect_state();
49 strncpy((char *)gpios
->gpios
[0].name
,"write protect", GPIO_MAX_NAME_LENGTH
);
51 /* Recovery: Virtual GPIO in the EC (Servo GPIO68 active low) */
52 gpios
->gpios
[1].port
= -1;
53 gpios
->gpios
[1].polarity
= ACTIVE_HIGH
;
54 gpios
->gpios
[1].value
= get_recovery_mode_switch();
55 strncpy((char *)gpios
->gpios
[1].name
,"recovery", GPIO_MAX_NAME_LENGTH
);
57 /* Developer: Virtual GPIO in the EC ( Servo GPIO17 active low) */
58 gpios
->gpios
[2].port
= -1;
59 gpios
->gpios
[2].polarity
= ACTIVE_HIGH
;
60 gpios
->gpios
[2].value
= get_developer_mode_switch();
61 strncpy((char *)gpios
->gpios
[2].name
,"developer", GPIO_MAX_NAME_LENGTH
);
63 /* Lid switch GPIO active high (open). */
64 gpios
->gpios
[3].port
= 15;
65 gpios
->gpios
[3].polarity
= ACTIVE_HIGH
;
66 gpios
->gpios
[3].value
= get_lid_switch();
67 strncpy((char *)gpios
->gpios
[3].name
,"lid", GPIO_MAX_NAME_LENGTH
);
70 gpios
->gpios
[4].port
= 101;
71 gpios
->gpios
[4].polarity
= ACTIVE_LOW
;
72 gpios
->gpios
[4].value
= (gen_pmcon_1
>> 9) & 1;
73 strncpy((char *)gpios
->gpios
[4].name
,"power", GPIO_MAX_NAME_LENGTH
);
75 /* Did we load the VGA Option ROM? */
76 gpios
->gpios
[5].port
= -1; /* Indicate that this is a pseudo GPIO */
77 gpios
->gpios
[5].polarity
= ACTIVE_HIGH
;
78 gpios
->gpios
[5].value
= gfx_get_init_done();
79 strncpy((char *)gpios
->gpios
[5].name
,"oprom", GPIO_MAX_NAME_LENGTH
);
84 int get_lid_switch(void)
88 dev
= PCI_DEV(0, 0x1f, 0);
90 dev
= dev_find_slot(0, PCI_DEVFN(0x1f, 0));
92 u16 gpio_base
= pci_read_config32(dev
, GPIOBASE
) & 0xfffe;
97 u32 gp_lvl
= inl(gpio_base
+ GP_LVL
);
98 return (gp_lvl
>> 15) & 1;
101 int get_developer_mode_switch(void)
105 dev
= PCI_DEV(0, 0x1f, 0);
107 dev
= dev_find_slot(0, PCI_DEVFN(0x1f,0));
109 u16 gpio_base
= pci_read_config32(dev
, GPIOBASE
) & 0xfffe;
115 * Dev mode is controled by EC and uboot stores a flag in TPM. This GPIO is only
116 * for the debug header. It is AND'd to the EC request.
119 u32 gp_lvl
= inl(gpio_base
+ GP_LVL
);
120 printk(BIOS_DEBUG
,"DEV MODE GPIO 17: %x\n", !((gp_lvl
>> 17) & 1));
122 /* GPIO17, active low -- return active high reading and let
123 * it be inverted by the caller if needed. */
124 return !((gp_lvl
>> 17) & 1);
127 int get_write_protect_state(void)
131 dev
= PCI_DEV(0, 0x1f, 0);
133 dev
= dev_find_slot(0, PCI_DEVFN(0x1f, 0));
135 u16 gpio_base
= pci_read_config32(dev
, GPIOBASE
) & 0xfffe;
140 u32 gp_lvl3
= inl(gpio_base
+ GP_LVL3
);
142 return !((gp_lvl3
>> (70 - 64)) & 1);
145 int get_recovery_mode_switch(void)
151 dev
= PCI_DEV(0, 0x1f, 0);
153 dev
= dev_find_slot(0, PCI_DEVFN(0x1f,0));
155 u16 gpio_base
= pci_read_config32(dev
, GPIOBASE
) & 0xfffe;
160 /* GPIO68, active low. For Servo support
161 * Treat as active high and let the caller invert if needed. */
162 u32 gp_lvl3
= inl(gpio_base
+ GP_LVL3
);
163 rec_mode
= !((gp_lvl3
>> (68 - 64)) & 1);
164 printk(BIOS_DEBUG
,"REC MODE GPIO 68: %x\n", rec_mode
);
169 int parrot_ec_running_ro(void)
173 dev
= PCI_DEV(0, 0x1f, 0);
175 dev
= dev_find_slot(0, PCI_DEVFN(0x1f,0));
177 u16 gpio_base
= pci_read_config32(dev
, GPIOBASE
) & 0xfffe;
182 /* GPIO68 EC_RW is active low.
183 * Treat as active high and let the caller invert if needed. */
184 u32 gp_lvl3
= inl(gpio_base
+ GP_LVL3
);
185 return !((gp_lvl3
>> (68 - 64)) & 1);