summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/pwm-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 13:40:34 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 16:10:52 +0200
commit9d871139583fdd0180f2b6893dee1d160a8593e5 (patch)
treee73aab2f54f1428ab4c8348f0881499d9680d49e /firmware/target/arm/imx233/pwm-imx233.c
parent55e01b8de46555929f62a9eb762d7791786ccc58 (diff)
downloadrockbox-9d871139583fdd0180f2b6893dee1d160a8593e5.tar.gz
rockbox-9d871139583fdd0180f2b6893dee1d160a8593e5.tar.bz2
rockbox-9d871139583fdd0180f2b6893dee1d160a8593e5.zip
imx233: add pwm driver
Change-Id: Ib920b119f52b492247d75e97c5ec9298146d583c
Diffstat (limited to 'firmware/target/arm/imx233/pwm-imx233.c')
-rw-r--r--firmware/target/arm/imx233/pwm-imx233.c64
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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2011 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "pwm-imx233.h"
+#include "clkctrl-imx233.h"
+#include "pinctrl-imx233.h"
+
+void imx233_pwm_init(void)
+{
+ imx233_reset_block(&HW_PWM_CTRL);
+ imx233_clkctrl_enable_xtal(XTAM_PWM, true);
+}
+
+bool imx233_pwm_is_channel_enable(int channel)
+{
+ return HW_PWM_CTRL & HW_PWM_CTRL__PWMx_ENABLE(channel);
+}
+
+void imx233_pwm_enable_channel(int channel, bool enable)
+{
+ if(enable)
+ __REG_SET(HW_PWM_CTRL) = HW_PWM_CTRL__PWMx_ENABLE(channel);
+ else
+ __REG_CLR(HW_PWM_CTRL) = HW_PWM_CTRL__PWMx_ENABLE(channel);
+}
+
+void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active,
+ int active_state, int inactive, int inactive_state)
+{
+ /* stop */
+ bool enable = imx233_pwm_is_channel_enable(channel);
+ if(enable)
+ imx233_pwm_enable_channel(channel, false);
+ /* setup pin */
+ imx233_set_pin_function(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel),
+ PINCTRL_FUNCTION_MAIN);
+ imx233_set_pin_drive_strength(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel),
+ PINCTRL_DRIVE_4mA);
+ /* watch the order ! active THEN period */
+ HW_PWM_ACTIVEx(channel) = active << HW_PWM_ACTIVEx__ACTIVE_BP |
+ inactive << HW_PWM_ACTIVEx__INACTIVE_BP;
+ HW_PWM_PERIODx(channel) = period | active_state << HW_PWM_PERIODx__ACTIVE_STATE_BP |
+ inactive_state << HW_PWM_PERIODx__INACTIVE_STATE_BP |
+ cdiv << HW_PWM_PERIODx__CDIV_BP;
+ /* restore */
+ imx233_pwm_enable_channel(channel, enable);
+}