altos/telelco-v2.0: A bit fancier with the drag-mode LED show
[fw/altos] / src / stmf0 / ao_gpio.c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include <ao.h>
20
21 static void
22 ao_gpio_suspend(void *arg)
23 {
24         struct stm_gpio *port = arg;
25         if (port == &stm_gpioa)
26                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPAEN);
27         else if ((port) == &stm_gpiob)
28                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPBEN);
29         else if ((port) == &stm_gpioc)
30                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPCEN);
31         else if ((port) == &stm_gpiof)
32                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPFEN);
33 }
34
35 static void
36 ao_gpio_resume(void *arg)
37 {
38         struct stm_gpio *port = arg;
39         if (port == &stm_gpioa)
40                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPAEN);
41         else if ((port) == &stm_gpiob)
42                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPBEN);
43         else if ((port) == &stm_gpioc)
44                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPCEN);
45         else if ((port) == &stm_gpiof)
46                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPFEN);
47 }
48
49 struct ao_power ao_power_gpioa = {
50         .suspend = ao_gpio_suspend,
51         .resume = ao_gpio_resume,
52         .arg = &stm_gpioa
53 };
54
55 struct ao_power ao_power_gpiob = {
56         .suspend = ao_gpio_suspend,
57         .resume = ao_gpio_resume,
58         .arg = &stm_gpiob
59 };
60
61 struct ao_power ao_power_gpioc = {
62         .suspend = ao_gpio_suspend,
63         .resume = ao_gpio_resume,
64         .arg = &stm_gpioc
65 };
66
67 struct ao_power ao_power_gpiof = {
68         .suspend = ao_gpio_suspend,
69         .resume = ao_gpio_resume,
70         .arg = &stm_gpiof
71 };
72