diff options
Diffstat (limited to 'firmware/target/arm/imx233')
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 @@ | |||
28 | 28 | ||
29 | void _backlight_set_brightness(int brightness) | 29 | void _backlight_set_brightness(int brightness) |
30 | { | 30 | { |
31 | imx233_pwm_setup_channel(4, 1024, HW_PWM_PERIODx__CDIV__DIV_1, | 31 | imx233_pwm_setup_channel(4, 1024, BV_PWM_PERIODn_CDIV__DIV_1, |
32 | 0, HW_PWM_PERIODx__STATE__HIGH, | 32 | 0, BV_PWM_PERIODn_ACTIVE_STATE__1, |
33 | (brightness * 1024) / 100, HW_PWM_PERIODx__STATE__LOW); | 33 | (brightness * 1024) / 100, BV_PWM_PERIODn_INACTIVE_STATE__0); |
34 | imx233_pwm_enable_channel(4, true); | 34 | imx233_pwm_enable_channel(4, true); |
35 | } | 35 | } |
36 | 36 | ||
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 @@ | |||
29 | 29 | ||
30 | void _backlight_set_brightness(int brightness) | 30 | void _backlight_set_brightness(int brightness) |
31 | { | 31 | { |
32 | imx233_pwm_setup_channel(2, 1024, HW_PWM_PERIODx__CDIV__DIV_1, | 32 | imx233_pwm_setup_channel(2, 1024, BV_PWM_PERIODn_CDIV__DIV_1, |
33 | 0, HW_PWM_PERIODx__STATE__HIGH, | 33 | 0, BV_PWM_PERIODn_ACTIVE_STATE__1, |
34 | (brightness * 1024) / 100, HW_PWM_PERIODx__STATE__LOW); | 34 | (brightness * 1024) / 100, BV_PWM_PERIODn_INACTIVE_STATE__0); |
35 | imx233_pwm_enable_channel(2, true); | 35 | imx233_pwm_enable_channel(2, true); |
36 | } | 36 | } |
37 | 37 | ||
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) | |||
30 | 30 | ||
31 | bool imx233_pwm_is_channel_enable(int channel) | 31 | bool imx233_pwm_is_channel_enable(int channel) |
32 | { | 32 | { |
33 | return HW_PWM_CTRL & HW_PWM_CTRL__PWMx_ENABLE(channel); | 33 | return BF_RD(PWM_CTRL, PWMx_ENABLE(channel)); |
34 | } | 34 | } |
35 | 35 | ||
36 | void imx233_pwm_enable_channel(int channel, bool enable) | 36 | void imx233_pwm_enable_channel(int channel, bool enable) |
37 | { | 37 | { |
38 | if(enable) | 38 | if(enable) |
39 | __REG_SET(HW_PWM_CTRL) = HW_PWM_CTRL__PWMx_ENABLE(channel); | 39 | BF_SET(PWM_CTRL, PWMx_ENABLE(channel)); |
40 | else | 40 | else |
41 | __REG_CLR(HW_PWM_CTRL) = HW_PWM_CTRL__PWMx_ENABLE(channel); | 41 | BF_CLR(PWM_CTRL, PWMx_ENABLE(channel)); |
42 | } | 42 | } |
43 | 43 | ||
44 | void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active, | 44 | 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, | |||
56 | imx233_set_pin_drive_strength(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel), | 56 | imx233_set_pin_drive_strength(IMX233_PWM_PIN_BANK(channel), IMX233_PWM_PIN(channel), |
57 | PINCTRL_DRIVE_4mA); | 57 | PINCTRL_DRIVE_4mA); |
58 | /* watch the order ! active THEN period */ | 58 | /* watch the order ! active THEN period */ |
59 | HW_PWM_ACTIVEx(channel) = active << HW_PWM_ACTIVEx__ACTIVE_BP | | 59 | HW_PWM_ACTIVEn(channel) = BF_OR2(PWM_ACTIVEn, ACTIVE(active), INACTIVE(inactive)); |
60 | inactive << HW_PWM_ACTIVEx__INACTIVE_BP; | 60 | HW_PWM_PERIODn(channel) = BF_OR4(PWM_PERIODn, PERIOD(period - 1), |
61 | HW_PWM_PERIODx(channel) = period | active_state << HW_PWM_PERIODx__ACTIVE_STATE_BP | | 61 | ACTIVE_STATE(active_state), INACTIVE_STATE(inactive_state), CDIV(cdiv)); |
62 | inactive_state << HW_PWM_PERIODx__INACTIVE_STATE_BP | | ||
63 | cdiv << HW_PWM_PERIODx__CDIV_BP; | ||
64 | /* restore */ | 62 | /* restore */ |
65 | imx233_pwm_enable_channel(channel, enable); | 63 | imx233_pwm_enable_channel(channel, enable); |
66 | } | 64 | } |
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 @@ | |||
23 | 23 | ||
24 | #include "system.h" | 24 | #include "system.h" |
25 | 25 | ||
26 | #define HW_PWM_BASE 0x80064000 | 26 | #include "regs/regs-pwm.h" |
27 | 27 | ||
28 | #define HW_PWM_CTRL (*(volatile uint32_t *)(HW_PWM_BASE + 0x0)) | 28 | /* fake field for simpler programming */ |
29 | #define HW_PWM_CTRL__PWMx_ENABLE(x) (1 << (x)) | 29 | #define BP_PWM_CTRL_PWMx_ENABLE(x) (x) |
30 | #define BM_PWM_CTRL_PWMx_ENABLE(x) (1 << (x)) | ||
30 | 31 | ||
31 | #define HW_PWM_ACTIVEx(x) (*(volatile uint32_t *)(HW_PWM_BASE + 0x10 + (x) * 0x20)) | 32 | #define IMX233_PWM_MAX_PERIOD (1 << 16) |
32 | #define HW_PWM_ACTIVEx__ACTIVE_BP 0 | ||
33 | #define HW_PWM_ACTIVEx__ACTIVE_BM 0xffff | ||
34 | #define HW_PWM_ACTIVEx__INACTIVE_BP 16 | ||
35 | #define HW_PWM_ACTIVEx__INACTIVE_BM 0xffff0000 | ||
36 | 33 | ||
37 | #define HW_PWM_PERIODx(x) (*(volatile uint32_t *)(HW_PWM_BASE + 0x20 + (x) * 0x20)) | 34 | #define IMX233_PWM_NR_CHANNELS 5 |
38 | #define HW_PWM_PERIODx__PERIOD_BP 0 | ||
39 | #define HW_PWM_PERIODx__PERIOD_BM 0xffff | ||
40 | #define HW_PWM_PERIODx__ACTIVE_STATE_BP 16 | ||
41 | #define HW_PWM_PERIODx__ACTIVE_STATE_BM (0x3 << 16) | ||
42 | #define HW_PWM_PERIODx__INACTIVE_STATE_BP 18 | ||
43 | #define HW_PWM_PERIODx__INACTIVE_STATE_BM (0x3 << 18) | ||
44 | #define HW_PWM_PERIODx__CDIV_BP 20 | ||
45 | #define HW_PWM_PERIODx__CDIV_BM (0x7 << 20) | ||
46 | #define HW_PWM_PERIODx__CDIV__DIV_1 0 | ||
47 | #define HW_PWM_PERIODx__CDIV__DIV_2 1 | ||
48 | #define HW_PWM_PERIODx__CDIV__DIV_4 2 | ||
49 | #define HW_PWM_PERIODx__CDIV__DIV_8 3 | ||
50 | #define HW_PWM_PERIODx__CDIV__DIV_16 4 | ||
51 | #define HW_PWM_PERIODx__CDIV__DIV_64 5 | ||
52 | #define HW_PWM_PERIODx__CDIV__DIV_256 6 | ||
53 | #define HW_PWM_PERIODx__CDIV__DIV_1024 7 | ||
54 | |||
55 | #define HW_PWM_PERIODx__STATE__HI_Z 0 | ||
56 | #define HW_PWM_PERIODx__STATE__LOW 2 | ||
57 | #define HW_PWM_PERIODx__STATE__HIGH 3 | ||
58 | 35 | ||
59 | #define IMX233_PWM_PIN_BANK(channel) 1 | 36 | #define IMX233_PWM_PIN_BANK(channel) 1 |
60 | #define IMX233_PWM_PIN(channel) (26 + (channel)) | 37 | #define IMX233_PWM_PIN(channel) (26 + (channel)) |