diff options
Diffstat (limited to 'firmware/target/arm/imx233/pwm-imx233.c')
-rw-r--r-- | firmware/target/arm/imx233/pwm-imx233.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/pwm-imx233.c b/firmware/target/arm/imx233/pwm-imx233.c new file mode 100644 index 0000000000..1c5e4657de --- /dev/null +++ b/firmware/target/arm/imx233/pwm-imx233.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Amaury Pouly | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "pwm-imx233.h" | ||
22 | #include "clkctrl-imx233.h" | ||
23 | #include "pinctrl-imx233.h" | ||
24 | |||
25 | void imx233_pwm_init(void) | ||
26 | { | ||
27 | imx233_reset_block(&HW_PWM_CTRL); | ||
28 | imx233_clkctrl_enable_xtal(XTAM_PWM, true); | ||
29 | } | ||
30 | |||
31 | bool imx233_pwm_is_channel_enable(int channel) | ||
32 | { | ||
33 | return HW_PWM_CTRL & HW_PWM_CTRL__PWMx_ENABLE(channel); | ||
34 | } | ||
35 | |||
36 | void imx233_pwm_enable_channel(int channel, bool enable) | ||
37 | { | ||
38 | if(enable) | ||
39 | __REG_SET(HW_PWM_CTRL) = HW_PWM_CTRL__PWMx_ENABLE(channel); | ||
40 | else | ||
41 | __REG_CLR(HW_PWM_CTRL) = HW_PWM_CTRL__PWMx_ENABLE(channel); | ||
42 | } | ||
43 | |||
44 | void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active, | ||
45 | int active_state, int inactive, int inactive_state) | ||
46 | { | ||
47 | /* stop */ | ||
48 | bool enable = imx233_pwm_is_channel_enable(channel); | ||
49 | if(enable) | ||
50 | imx233_pwm_enable_channel(channel, false); | ||
51 | /* setup pin */ | ||
52 | imx233_set_pin_function(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel), | ||
53 | PINCTRL_FUNCTION_MAIN); | ||
54 | imx233_set_pin_drive_strength(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel), | ||
55 | PINCTRL_DRIVE_4mA); | ||
56 | /* watch the order ! active THEN period */ | ||
57 | HW_PWM_ACTIVEx(channel) = active << HW_PWM_ACTIVEx__ACTIVE_BP | | ||
58 | inactive << HW_PWM_ACTIVEx__INACTIVE_BP; | ||
59 | HW_PWM_PERIODx(channel) = period | active_state << HW_PWM_PERIODx__ACTIVE_STATE_BP | | ||
60 | inactive_state << HW_PWM_PERIODx__INACTIVE_STATE_BP | | ||
61 | cdiv << HW_PWM_PERIODx__CDIV_BP; | ||
62 | /* restore */ | ||
63 | imx233_pwm_enable_channel(channel, enable); | ||
64 | } | ||