summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-16 17:19:20 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-16 18:21:48 +0200
commit3e8c2dc46d843575096e92bd82886c7d6d44855d (patch)
tree9857f96bf2fbcf0300b8269aecc55e3ced6176bd
parent7c5b65b9d234f819447195e3f852d9b59a225813 (diff)
downloadrockbox-3e8c2dc46d843575096e92bd82886c7d6d44855d.tar.gz
rockbox-3e8c2dc46d843575096e92bd82886c7d6d44855d.tar.bz2
rockbox-3e8c2dc46d843575096e92bd82886c7d6d44855d.zip
imx233: rewrite pwm using new registers
Change-Id: Ie222f0b25f4b8af9ccf21aecd82a7f4eba40aa3c
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c6
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c6
-rw-r--r--firmware/target/arm/imx233/pwm-imx233.c14
-rw-r--r--firmware/target/arm/imx233/pwm-imx233.h35
4 files changed, 18 insertions, 43 deletions
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c b/firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c
index 8fcdd8ba32..3322098fa2 100644
--- a/firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c
+++ b/firmware/target/arm/imx233/creative-zenxfi2/backlight-zenxfi2.c
@@ -28,9 +28,9 @@
void _backlight_set_brightness(int brightness)
{
- imx233_pwm_setup_channel(4, 1024, HW_PWM_PERIODx__CDIV__DIV_1,
- 0, HW_PWM_PERIODx__STATE__HIGH,
- (brightness * 1024) / 100, HW_PWM_PERIODx__STATE__LOW);
+ imx233_pwm_setup_channel(4, 1024, BV_PWM_PERIODn_CDIV__DIV_1,
+ 0, BV_PWM_PERIODn_ACTIVE_STATE__1,
+ (brightness * 1024) / 100, BV_PWM_PERIODn_INACTIVE_STATE__0);
imx233_pwm_enable_channel(4, true);
}
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c b/firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c
index 59c3c133aa..7b9327b695 100644
--- a/firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c
+++ b/firmware/target/arm/imx233/creative-zenxfi3/backlight-zenxfi3.c
@@ -29,9 +29,9 @@
void _backlight_set_brightness(int brightness)
{
- imx233_pwm_setup_channel(2, 1024, HW_PWM_PERIODx__CDIV__DIV_1,
- 0, HW_PWM_PERIODx__STATE__HIGH,
- (brightness * 1024) / 100, HW_PWM_PERIODx__STATE__LOW);
+ imx233_pwm_setup_channel(2, 1024, BV_PWM_PERIODn_CDIV__DIV_1,
+ 0, BV_PWM_PERIODn_ACTIVE_STATE__1,
+ (brightness * 1024) / 100, BV_PWM_PERIODn_INACTIVE_STATE__0);
imx233_pwm_enable_channel(2, true);
}
diff --git a/firmware/target/arm/imx233/pwm-imx233.c b/firmware/target/arm/imx233/pwm-imx233.c
index 1ebfe02a1c..c0417c55d0 100644
--- a/firmware/target/arm/imx233/pwm-imx233.c
+++ b/firmware/target/arm/imx233/pwm-imx233.c
@@ -30,15 +30,15 @@ void imx233_pwm_init(void)
bool imx233_pwm_is_channel_enable(int channel)
{
- return HW_PWM_CTRL & HW_PWM_CTRL__PWMx_ENABLE(channel);
+ return BF_RD(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);
+ BF_SET(PWM_CTRL, PWMx_ENABLE(channel));
else
- __REG_CLR(HW_PWM_CTRL) = HW_PWM_CTRL__PWMx_ENABLE(channel);
+ BF_CLR(PWM_CTRL, PWMx_ENABLE(channel));
}
void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active,
@@ -56,11 +56,9 @@ void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active,
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;
+ HW_PWM_ACTIVEn(channel) = BF_OR2(PWM_ACTIVEn, ACTIVE(active), INACTIVE(inactive));
+ HW_PWM_PERIODn(channel) = BF_OR4(PWM_PERIODn, PERIOD(period - 1),
+ ACTIVE_STATE(active_state), INACTIVE_STATE(inactive_state), CDIV(cdiv));
/* restore */
imx233_pwm_enable_channel(channel, enable);
}
diff --git a/firmware/target/arm/imx233/pwm-imx233.h b/firmware/target/arm/imx233/pwm-imx233.h
index 48c7811d47..c7ec4c27c5 100644
--- a/firmware/target/arm/imx233/pwm-imx233.h
+++ b/firmware/target/arm/imx233/pwm-imx233.h
@@ -23,38 +23,15 @@
#include "system.h"
-#define HW_PWM_BASE 0x80064000
+#include "regs/regs-pwm.h"
-#define HW_PWM_CTRL (*(volatile uint32_t *)(HW_PWM_BASE + 0x0))
-#define HW_PWM_CTRL__PWMx_ENABLE(x) (1 << (x))
+/* fake field for simpler programming */
+#define BP_PWM_CTRL_PWMx_ENABLE(x) (x)
+#define BM_PWM_CTRL_PWMx_ENABLE(x) (1 << (x))
-#define HW_PWM_ACTIVEx(x) (*(volatile uint32_t *)(HW_PWM_BASE + 0x10 + (x) * 0x20))
-#define HW_PWM_ACTIVEx__ACTIVE_BP 0
-#define HW_PWM_ACTIVEx__ACTIVE_BM 0xffff
-#define HW_PWM_ACTIVEx__INACTIVE_BP 16
-#define HW_PWM_ACTIVEx__INACTIVE_BM 0xffff0000
+#define IMX233_PWM_MAX_PERIOD (1 << 16)
-#define HW_PWM_PERIODx(x) (*(volatile uint32_t *)(HW_PWM_BASE + 0x20 + (x) * 0x20))
-#define HW_PWM_PERIODx__PERIOD_BP 0
-#define HW_PWM_PERIODx__PERIOD_BM 0xffff
-#define HW_PWM_PERIODx__ACTIVE_STATE_BP 16
-#define HW_PWM_PERIODx__ACTIVE_STATE_BM (0x3 << 16)
-#define HW_PWM_PERIODx__INACTIVE_STATE_BP 18
-#define HW_PWM_PERIODx__INACTIVE_STATE_BM (0x3 << 18)
-#define HW_PWM_PERIODx__CDIV_BP 20
-#define HW_PWM_PERIODx__CDIV_BM (0x7 << 20)
-#define HW_PWM_PERIODx__CDIV__DIV_1 0
-#define HW_PWM_PERIODx__CDIV__DIV_2 1
-#define HW_PWM_PERIODx__CDIV__DIV_4 2
-#define HW_PWM_PERIODx__CDIV__DIV_8 3
-#define HW_PWM_PERIODx__CDIV__DIV_16 4
-#define HW_PWM_PERIODx__CDIV__DIV_64 5
-#define HW_PWM_PERIODx__CDIV__DIV_256 6
-#define HW_PWM_PERIODx__CDIV__DIV_1024 7
-
-#define HW_PWM_PERIODx__STATE__HI_Z 0
-#define HW_PWM_PERIODx__STATE__LOW 2
-#define HW_PWM_PERIODx__STATE__HIGH 3
+#define IMX233_PWM_NR_CHANNELS 5
#define IMX233_PWM_PIN_BANK(channel) 1
#define IMX233_PWM_PIN(channel) (26 + (channel))