mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 18:11:05 +00:00
In the gpio_info struct, we had a irq_handler pointer defined even
though a majority of the GPIOs did not have irq handlers associated. By
removing the irq_handler pointer out of the struct, we can save some
space with some targets saving more than others. (For example, ~260
bytes for samus_pd).
This change also brings about a new define:
GPIO_INT(name, port, pin, flags, signal)
And the existing GPIO macro has had the signal parameter removed since
they were just NULL.
GPIO(name, port, pin, flags)
In each of the gpio.inc files, all the GPIOs with irq handlers must be
defined at the top of the file. This is because their enum values from
gpio_signal are used as the index to the gpio_irq_handlers table.
BUG=chromium:471331
BRANCH=none
TEST=Flashed ec to samus and samus_pd, verified lightbar tap, lid, power
button, keyboard, charging, all still working.
TEST=Moved a GPIO_INT declaration after a GPIO declaration and watched the build
fail.
TEST=make -j BOARD=peppy tests
TEST=make -j BOARD=auron tests
TEST=make -j BOARD=link tests
Change-Id: Id6e261b0a3cd63223ca92f2e96a80c95e85cdefb
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/263973
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Trybot-Ready: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
74 lines
1.6 KiB
C
74 lines
1.6 KiB
C
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* GPIO module for emulator */
|
|
|
|
#include "console.h"
|
|
|
|
#include "common.h"
|
|
#include "gpio.h"
|
|
#include "timer.h"
|
|
#include "util.h"
|
|
|
|
static int gpio_values[GPIO_COUNT];
|
|
static int gpio_interrupt_enabled[GPIO_COUNT];
|
|
|
|
test_mockable void gpio_pre_init(void)
|
|
{
|
|
/* Nothing */
|
|
}
|
|
|
|
test_mockable int gpio_get_level(enum gpio_signal signal)
|
|
{
|
|
return gpio_values[signal];
|
|
}
|
|
|
|
static int gpio_interrupt_check(uint32_t flags, int old, int new)
|
|
{
|
|
if ((flags & GPIO_INT_F_RISING) && old == 0 && new == 1)
|
|
return 1;
|
|
if ((flags & GPIO_INT_F_FALLING) && old == 1 && new == 0)
|
|
return 1;
|
|
if ((flags & GPIO_INT_F_LOW) && new == 0)
|
|
return 1;
|
|
if ((flags & GPIO_INT_F_HIGH) && new == 1)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
test_mockable void gpio_set_level(enum gpio_signal signal, int value)
|
|
{
|
|
const struct gpio_info *g = gpio_list + signal;
|
|
const uint32_t flags = g->flags;
|
|
const int old_value = gpio_values[signal];
|
|
void (*ih)(enum gpio_signal signal) = gpio_irq_handlers[signal];
|
|
|
|
gpio_values[signal] = value;
|
|
|
|
if (signal >= GPIO_IH_COUNT || !gpio_interrupt_enabled[signal])
|
|
return;
|
|
|
|
if (gpio_interrupt_check(flags, old_value, value))
|
|
ih(signal);
|
|
}
|
|
|
|
test_mockable int gpio_enable_interrupt(enum gpio_signal signal)
|
|
{
|
|
gpio_interrupt_enabled[signal] = 1;
|
|
return EC_SUCCESS;
|
|
}
|
|
|
|
test_mockable void gpio_set_flags_by_mask(uint32_t port, uint32_t mask,
|
|
uint32_t flags)
|
|
{
|
|
/* Nothing */
|
|
}
|
|
|
|
test_mockable void gpio_set_alternate_function(uint32_t port, uint32_t mask,
|
|
int func)
|
|
{
|
|
/* Nothing */
|
|
}
|