imx233: add pwm driver

Change-Id: Ib920b119f52b492247d75e97c5ec9298146d583c
This commit is contained in:
Amaury Pouly 2012-05-19 13:40:34 +02:00
parent 55e01b8de4
commit 9d87113958
4 changed files with 135 additions and 0 deletions

View file

@ -515,6 +515,7 @@ target/arm/imx233/power-imx233.c
target/arm/imx233/powermgmt-imx233.c target/arm/imx233/powermgmt-imx233.c
target/arm/imx233/adc-imx233.c target/arm/imx233/adc-imx233.c
target/arm/imx233/lradc-imx233.c target/arm/imx233/lradc-imx233.c
target/arm/imx233/pwm-imx233.c
target/arm/imx233/rtc-imx233.c target/arm/imx233/rtc-imx233.c
target/arm/imx233/dcp-imx233.c target/arm/imx233/dcp-imx233.c
#ifndef BOOTLOADER #ifndef BOOTLOADER

View file

@ -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);
}

View file

@ -0,0 +1,68 @@
/***************************************************************************
* __________ __ ___.
* 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.
*
****************************************************************************/
#ifndef __PWM_IMX233_H__
#define __PWM_IMX233_H__
#include "system.h"
#define HW_PWM_BASE 0x80064000
#define HW_PWM_CTRL (*(volatile uint32_t *)(HW_PWM_BASE + 0x0))
#define HW_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 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_PIN_BANK(channel) 1
#define IMX233_PWM_PIN(channel) (26 + (channel))
void imx233_pwm_init(void);
void imx233_pwm_setup_channel(int channel, int period, int cdiv, int active,
int active_state, int inactive, int inactive_state);
void imx233_pwm_enable_channel(int channel, bool enable);
bool imx233_pwm_is_channel_enable(int channel);
#endif /* __PWM_IMX233_H__ */

View file

@ -31,6 +31,7 @@
#include "ssp-imx233.h" #include "ssp-imx233.h"
#include "i2c-imx233.h" #include "i2c-imx233.h"
#include "dcp-imx233.h" #include "dcp-imx233.h"
#include "pwm-imx233.h"
#include "icoll-imx233.h" #include "icoll-imx233.h"
#include "lradc-imx233.h" #include "lradc-imx233.h"
#include "rtc-imx233.h" #include "rtc-imx233.h"
@ -99,6 +100,7 @@ void system_init(void)
imx233_dma_init(); imx233_dma_init();
imx233_ssp_init(); imx233_ssp_init();
imx233_dcp_init(); imx233_dcp_init();
imx233_pwm_init();
imx233_lradc_init(); imx233_lradc_init();
imx233_i2c_init(); imx233_i2c_init();
#if defined(SANSA_FUZEPLUS) && !defined(BOOTLOADER) #if defined(SANSA_FUZEPLUS) && !defined(BOOTLOADER)