summaryrefslogtreecommitdiff
path: root/firmware/target/arm
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
parent55e01b8de46555929f62a9eb762d7791786ccc58 (diff)
downloadrockbox-9d871139583fdd0180f2b6893dee1d160a8593e5.tar.gz
rockbox-9d871139583fdd0180f2b6893dee1d160a8593e5.zip
imx233: add pwm driver
Change-Id: Ib920b119f52b492247d75e97c5ec9298146d583c
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/imx233/pwm-imx233.c64
-rw-r--r--firmware/target/arm/imx233/pwm-imx233.h68
-rw-r--r--firmware/target/arm/imx233/system-imx233.c2
3 files changed, 134 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
25void imx233_pwm_init(void)
26{
27 imx233_reset_block(&HW_PWM_CTRL);
28 imx233_clkctrl_enable_xtal(XTAM_PWM, true);
29}
30
31bool imx233_pwm_is_channel_enable(int channel)
32{
33 return HW_PWM_CTRL & HW_PWM_CTRL__PWMx_ENABLE(channel);
34}
35
36void 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
44void 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}
diff --git a/firmware/target/arm/imx233/pwm-imx233.h b/firmware/target/arm/imx233/pwm-imx233.h
new file mode 100644
index 0000000000..48c7811d47
--- /dev/null
+++ b/firmware/target/arm/imx233/pwm-imx233.h
@@ -0,0 +1,68 @@
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#ifndef __PWM_IMX233_H__
22#define __PWM_IMX233_H__
23
24#include "system.h"
25
26#define HW_PWM_BASE 0x80064000
27
28#define HW_PWM_CTRL (*(volatile uint32_t *)(HW_PWM_BASE + 0x0))
29#define HW_PWM_CTRL__PWMx_ENABLE(x) (1 << (x))
30
31#define HW_PWM_ACTIVEx(x) (*(volatile uint32_t *)(HW_PWM_BASE + 0x10 + (x) * 0x20))
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
37#define HW_PWM_PERIODx(x) (*(volatile uint32_t *)(HW_PWM_BASE + 0x20 + (x) * 0x20))
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
59#define IMX233_PWM_PIN_BANK(channel) 1
60#define IMX233_PWM_PIN(channel) (26 + (channel))
61
62void imx233_pwm_init(void);
63void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active,
64 int active_state, int inactive, int inactive_state);
65void imx233_pwm_enable_channel(int channel, bool enable);
66bool imx233_pwm_is_channel_enable(int channel);
67
68#endif /* __PWM_IMX233_H__ */
diff --git a/firmware/target/arm/imx233/system-imx233.c b/firmware/target/arm/imx233/system-imx233.c
index a06ecab9f5..eb9a3f8ee0 100644
--- a/firmware/target/arm/imx233/system-imx233.c
+++ b/firmware/target/arm/imx233/system-imx233.c
@@ -31,6 +31,7 @@
31#include "ssp-imx233.h" 31#include "ssp-imx233.h"
32#include "i2c-imx233.h" 32#include "i2c-imx233.h"
33#include "dcp-imx233.h" 33#include "dcp-imx233.h"
34#include "pwm-imx233.h"
34#include "icoll-imx233.h" 35#include "icoll-imx233.h"
35#include "lradc-imx233.h" 36#include "lradc-imx233.h"
36#include "rtc-imx233.h" 37#include "rtc-imx233.h"
@@ -99,6 +100,7 @@ void system_init(void)
99 imx233_dma_init(); 100 imx233_dma_init();
100 imx233_ssp_init(); 101 imx233_ssp_init();
101 imx233_dcp_init(); 102 imx233_dcp_init();
103 imx233_pwm_init();
102 imx233_lradc_init(); 104 imx233_lradc_init();
103 imx233_i2c_init(); 105 imx233_i2c_init();
104#if defined(SANSA_FUZEPLUS) && !defined(BOOTLOADER) 106#if defined(SANSA_FUZEPLUS) && !defined(BOOTLOADER)