c7bf07971c407d3db9cdea548de48a2806e26309
[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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include <ao.h>
19
20 static void
21 ao_gpio_suspend(void *arg)
22 {
23         struct stm_gpio *port = arg;
24         if (port == &stm_gpioa)
25                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPAEN);
26         else if ((port) == &stm_gpiob)
27                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPBEN);
28         else if ((port) == &stm_gpioc)
29                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPCEN);
30         else if ((port) == &stm_gpiof)
31                 stm_rcc.ahbenr &= ~(1 << STM_RCC_AHBENR_IOPFEN);
32 }
33
34 static void
35 ao_gpio_resume(void *arg)
36 {
37         struct stm_gpio *port = arg;
38         if (port == &stm_gpioa)
39                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPAEN);
40         else if ((port) == &stm_gpiob)
41                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPBEN);
42         else if ((port) == &stm_gpioc)
43                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPCEN);
44         else if ((port) == &stm_gpiof)
45                 stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_IOPFEN);
46 }
47
48 struct ao_power ao_power_gpioa = {
49         .suspend = ao_gpio_suspend,
50         .resume = ao_gpio_resume,
51         .arg = &stm_gpioa
52 };
53
54 struct ao_power ao_power_gpiob = {
55         .suspend = ao_gpio_suspend,
56         .resume = ao_gpio_resume,
57         .arg = &stm_gpiob
58 };
59
60 struct ao_power ao_power_gpioc = {
61         .suspend = ao_gpio_suspend,
62         .resume = ao_gpio_resume,
63         .arg = &stm_gpioc
64 };
65
66 struct ao_power ao_power_gpiof = {
67         .suspend = ao_gpio_suspend,
68         .resume = ao_gpio_resume,
69         .arg = &stm_gpiof
70 };
71