it8320: print error message if gpio triggers are misconfigured
If a GPIO interrupt is misconifgured print out a console message.
BRANCH=none
TEST=verified messages get printed if I try to configure both on GPH6
@@ -305,11 +305,33 @@ void gpio_kbs_pin_gpio_mode(uint32_t port, uint32_t mask, uint32_t flags)
IT83XX_KBS_KSIGCTRL |= mask;
}
+/* Returns true when the falling trigger bit actually mean both trigger. */
+static int group_falling_is_both(const int group)
+{
+ return group == 7 || group == 10 || group == 12;
+}
+
+static const char *get_gpio_string(const int port, const int mask)
+{
+ static char buffer[3];
+ int i;
+
+ buffer[0] = port - GPIO_A + 'A';
+ buffer[1] = '!';
+
+ for (i = 0; i < 8; ++i) {
+ if (mask & (1 << i)) {
+ buffer[1] = i + '0';
+ break;
+ }
+ }
+ return buffer;
+}
+
void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags)
{
uint32_t pin = 0;
uint32_t mask_copy = mask;
- int irq;
/*
* Select open drain first, so that we don't glitch the signal
@@ -363,25 +385,22 @@ void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags)
mask_copy >>= 1;
}
- /* Set rising edge interrupt. */
- if (flags & GPIO_INT_F_RISING) {
+ if (flags & (GPIO_INT_F_RISING | GPIO_INT_F_FALLING)) {
+ int irq, wuc_group, wuc_mask;
irq = gpio_to_irq(port, mask);
+ wuc_group = gpio_irqs[irq].wuc_group;
+ wuc_mask = gpio_irqs[irq].wuc_mask;
- *(wuemr(gpio_irqs[irq].wuc_group)) &= ~gpio_irqs[irq].wuc_mask;
- }
-
- /*
- * Set falling edge or both edges interrupt. Note that pins in WUC
- * groups 7, 10, and 12 can only declare a falling edge trigger. All
- * other pins can only declare both edges as the trigger.
- *
- * TODO: use an assert to catch if a developer tries to declare one
- * type of interrupt on a pin that doesn't support that type.
- */
if (flags & GPIO_INT_F_FALLING) {
- irq = gpio_to_irq(port, mask);
-
- *(wuemr(gpio_irqs[irq].wuc_group)) |= gpio_irqs[irq].wuc_mask;
+ if (!!(flags & GPIO_INT_F_RISING) !=
+ group_falling_is_both(wuc_group)) {
+ ccprintf("!!Fix GPIO %s interrupt config!!\n",
+ get_gpio_string(port, mask));
+ }
+ *(wuemr(wuc_group)) |= wuc_mask;
+ } else {
+ *(wuemr(wuc_group)) &= ~wuc_mask;
+ }
}
}
