2011-05-01 13:02:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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 __PINCTRL_IMX233_H__
|
|
|
|
#define __PINCTRL_IMX233_H__
|
|
|
|
|
2012-05-09 22:08:03 +00:00
|
|
|
#include "config.h"
|
2013-06-16 14:56:34 +00:00
|
|
|
#include "system.h"
|
imx233: generate register headers using headergen_v2 and update code for it
NOTE: this commit does not introduce any change, ideally even the binary should
be almost the same. I checked the disassembly by hand and there are only a few
differences here and there, mostly the compiler decides to compile very close
expressions slightly differently. I tried to run the new code on several targets
to make sure and saw no difference.
The major syntax changes of the new headers are as follows:
- BF_{WR,SET,CLR} are now superpowerful and allows to set several fileds at once:
BF_WR(reg, field1(value1), field2(value2), ...)
- BF_CS (use like BF_WR) does a write to reg_CLR and then reg_SET instead of RMW
- there is no more need for macros like BF_{WR_,SET,CLR}_V, since one can simply
BF_WR with field_V(name)
- the old BF_SETV macro has no trivial equivalent and is replaced with its
its equivalent for BF_WR(reg_SET, ...)
I also rename the register headers: "regs/regs-x.h" -> "regs/x.h" to avoid the
redundant "regs".
Final note: the registers were generated using the following command:
./headergen_v2 -g imx -o ../../firmware/target/arm/imx233/regs/ desc/regs-stmp3{600,700,780}.xml
Change-Id: I7485e8b4315a0929a8edb63e7fa1edcaa54b1edc
2016-05-24 19:29:56 +00:00
|
|
|
#include "regs/pinctrl.h"
|
2012-05-09 22:08:03 +00:00
|
|
|
|
|
|
|
// set to debug pinctrl use
|
|
|
|
#define IMX233_PINCTRL_DEBUG
|
2011-05-01 13:02:46 +00:00
|
|
|
|
|
|
|
#define PINCTRL_FUNCTION_MAIN 0
|
|
|
|
#define PINCTRL_FUNCTION_ALT1 1
|
|
|
|
#define PINCTRL_FUNCTION_ALT2 2
|
|
|
|
#define PINCTRL_FUNCTION_GPIO 3
|
|
|
|
|
2013-06-16 19:15:09 +00:00
|
|
|
#if IMX233_SUBTARGET >= 3700
|
2011-05-01 13:02:46 +00:00
|
|
|
#define PINCTRL_DRIVE_4mA 0
|
|
|
|
#define PINCTRL_DRIVE_8mA 1
|
|
|
|
#define PINCTRL_DRIVE_12mA 2
|
|
|
|
#define PINCTRL_DRIVE_16mA 3 /* not available on all pins */
|
2013-06-16 19:15:09 +00:00
|
|
|
#else
|
|
|
|
#define PINCTRL_DRIVE_4mA 0
|
|
|
|
#define PINCTRL_DRIVE_8mA 1
|
|
|
|
#endif
|
2011-05-01 13:02:46 +00:00
|
|
|
|
2012-05-09 22:08:03 +00:00
|
|
|
#ifdef IMX233_PINCTRL_DEBUG
|
2013-06-16 17:18:56 +00:00
|
|
|
void imx233_pinctrl_acquire(unsigned bank, unsigned pin, const char *name);
|
|
|
|
void imx233_pinctrl_release(unsigned bank, unsigned pin, const char *name);
|
|
|
|
const char *imx233_pinctrl_blame(unsigned bank, unsigned pin);
|
2012-05-09 22:08:03 +00:00
|
|
|
#else
|
2013-06-16 17:18:56 +00:00
|
|
|
#define imx233_pinctrl_acquire(...)
|
|
|
|
#define imx233_pinctrl_release(...)
|
2013-06-16 19:15:09 +00:00
|
|
|
#define imx233_pinctrl_get_pin_use(...) NULL
|
2012-05-09 22:08:03 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-16 17:32:21 +00:00
|
|
|
typedef void (*pin_irq_cb_t)(int bank, int pin, intptr_t user);
|
2011-07-22 15:45:50 +00:00
|
|
|
|
2011-05-01 13:02:46 +00:00
|
|
|
static inline void imx233_pinctrl_init(void)
|
|
|
|
{
|
imx233: generate register headers using headergen_v2 and update code for it
NOTE: this commit does not introduce any change, ideally even the binary should
be almost the same. I checked the disassembly by hand and there are only a few
differences here and there, mostly the compiler decides to compile very close
expressions slightly differently. I tried to run the new code on several targets
to make sure and saw no difference.
The major syntax changes of the new headers are as follows:
- BF_{WR,SET,CLR} are now superpowerful and allows to set several fileds at once:
BF_WR(reg, field1(value1), field2(value2), ...)
- BF_CS (use like BF_WR) does a write to reg_CLR and then reg_SET instead of RMW
- there is no more need for macros like BF_{WR_,SET,CLR}_V, since one can simply
BF_WR with field_V(name)
- the old BF_SETV macro has no trivial equivalent and is replaced with its
its equivalent for BF_WR(reg_SET, ...)
I also rename the register headers: "regs/regs-x.h" -> "regs/x.h" to avoid the
redundant "regs".
Final note: the registers were generated using the following command:
./headergen_v2 -g imx -o ../../firmware/target/arm/imx233/regs/ desc/regs-stmp3{600,700,780}.xml
Change-Id: I7485e8b4315a0929a8edb63e7fa1edcaa54b1edc
2016-05-24 19:29:56 +00:00
|
|
|
BF_CLR(PINCTRL_CTRL, CLKGATE, SFTRST);
|
2011-05-01 13:02:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 19:15:09 +00:00
|
|
|
#if IMX233_SUBTARGET >= 3700
|
2013-06-16 17:18:56 +00:00
|
|
|
static inline void imx233_pinctrl_set_drive(unsigned bank, unsigned pin, unsigned strength)
|
2011-05-01 13:02:46 +00:00
|
|
|
{
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_DRIVEn_CLR(4 * bank + pin / 8) = 3 << (4 * (pin % 8));
|
|
|
|
HW_PINCTRL_DRIVEn_SET(4 * bank + pin / 8) = strength << (4 * (pin % 8));
|
2011-05-01 13:02:46 +00:00
|
|
|
}
|
2013-06-16 19:15:09 +00:00
|
|
|
#else
|
|
|
|
static inline void imx233_pinctrl_set_drive(unsigned bank, unsigned pin, unsigned strength)
|
|
|
|
{
|
|
|
|
HW_PINCTRL_DRIVEn_CLR(bank) = 1 << pin;
|
|
|
|
HW_PINCTRL_DRIVEn_SET(bank) = strength << pin;
|
|
|
|
}
|
|
|
|
#endif
|
2011-05-01 13:02:46 +00:00
|
|
|
|
2013-06-16 17:18:56 +00:00
|
|
|
static inline void imx233_pinctrl_enable_gpio(unsigned bank, unsigned pin, bool enable)
|
2011-05-01 13:02:46 +00:00
|
|
|
{
|
2013-06-16 17:32:21 +00:00
|
|
|
if(enable)
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_DOEn_SET(bank) = 1 << pin;
|
2011-05-01 13:02:46 +00:00
|
|
|
else
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_DOEn_CLR(bank) = 1 << pin;
|
2011-05-01 13:02:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 17:18:56 +00:00
|
|
|
static inline void imx233_pinctrl_set_gpio(unsigned bank, unsigned pin, bool value)
|
2011-05-01 13:02:46 +00:00
|
|
|
{
|
|
|
|
if(value)
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_DOUTn_SET(bank) = 1 << pin;
|
2011-05-01 13:02:46 +00:00
|
|
|
else
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_DOUTn_CLR(bank) = 1 << pin;
|
2011-05-01 13:02:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 19:15:09 +00:00
|
|
|
static inline bool imx233_pinctrl_get_gpio(unsigned bank, unsigned pin)
|
2011-05-01 13:02:46 +00:00
|
|
|
{
|
2013-06-16 19:15:09 +00:00
|
|
|
return (HW_PINCTRL_DINn(bank) >> pin) & 1;
|
2011-05-01 13:02:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 17:18:56 +00:00
|
|
|
static inline void imx233_pinctrl_set_function(unsigned bank, unsigned pin, unsigned function)
|
2011-05-01 13:02:46 +00:00
|
|
|
{
|
2013-06-16 19:15:09 +00:00
|
|
|
#if IMX233_SUBTARGET >= 3700
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_MUXSELn_CLR(2 * bank + pin / 16) = 3 << (2 * (pin % 16));
|
|
|
|
HW_PINCTRL_MUXSELn_SET(2 * bank + pin / 16) = function << (2 * (pin % 16));
|
2013-06-16 19:15:09 +00:00
|
|
|
#else
|
|
|
|
if(pin < 16)
|
|
|
|
{
|
|
|
|
HW_PINCTRL_MUXSELLn_CLR(bank) = 3 << (2 * pin);
|
|
|
|
HW_PINCTRL_MUXSELLn_SET(bank) = function << (2 * pin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pin -= 16;
|
|
|
|
HW_PINCTRL_MUXSELHn_CLR(bank) = 3 << (2 * pin);
|
|
|
|
HW_PINCTRL_MUXSELHn_SET(bank) = function << (2 * pin);
|
|
|
|
}
|
|
|
|
#endif
|
2011-05-01 13:02:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 19:15:09 +00:00
|
|
|
#if IMX233_SUBTARGET >= 3700
|
2013-06-16 17:18:56 +00:00
|
|
|
static inline void imx233_pinctrl_enable_pullup(unsigned bank, unsigned pin, bool enable)
|
2011-06-17 22:30:58 +00:00
|
|
|
{
|
|
|
|
if(enable)
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_PULLn_SET(bank) = 1 << pin;
|
2011-06-17 22:30:58 +00:00
|
|
|
else
|
2013-06-16 14:56:34 +00:00
|
|
|
HW_PINCTRL_PULLn_CLR(bank) = 1 << pin;
|
2011-06-17 22:30:58 +00:00
|
|
|
}
|
2013-06-16 19:15:09 +00:00
|
|
|
#else
|
|
|
|
static inline void imx233_pinctrl_enable_pullup(unsigned bank, unsigned pin, bool enable)
|
2011-06-17 22:30:58 +00:00
|
|
|
{
|
2013-06-16 19:15:09 +00:00
|
|
|
(void) bank;
|
|
|
|
(void) pin;
|
|
|
|
(void) enable;
|
2011-06-17 22:30:58 +00:00
|
|
|
}
|
2013-06-16 19:15:09 +00:00
|
|
|
#endif
|
2011-06-17 22:30:58 +00:00
|
|
|
|
2011-07-22 15:45:50 +00:00
|
|
|
/** On irq, the pin irq interrupt is disable and then cb is called;
|
|
|
|
* the setup_pin_irq function needs to be called again to enable it again */
|
2013-06-16 17:32:21 +00:00
|
|
|
void imx233_pinctrl_setup_irq(unsigned bank, unsigned pin, bool enable_int,
|
|
|
|
bool level, bool polarity, pin_irq_cb_t cb, intptr_t user);
|
2011-07-22 15:45:50 +00:00
|
|
|
|
2013-06-16 17:43:32 +00:00
|
|
|
/**
|
|
|
|
* Virtual pin interface
|
|
|
|
*
|
|
|
|
* This interface provides an easy way to configure standard pins for
|
|
|
|
* devices like SSP, LCD, etc
|
|
|
|
* The point here is that these pins can or cannot exist depending on the
|
|
|
|
* chip and the package and the drivers don't want to mess with that.
|
|
|
|
*
|
|
|
|
* A virtual pin is described by a bank, a pin and the function.
|
|
|
|
*/
|
|
|
|
typedef unsigned vpin_t;
|
|
|
|
#define VPIN_PACK(bank, pin, mux) \
|
|
|
|
((vpin_t)((bank) << 5 | (pin) | PINCTRL_FUNCTION_##mux << 7))
|
|
|
|
#define VPIN_UNPACK_BANK(vpin) (((vpin) >> 5) & 3)
|
|
|
|
#define VPIN_UNPACK_PIN(vpin) (((vpin) >> 0) & 0x1f)
|
|
|
|
#define VPIN_UNPACK_MUX(vpin) (((vpin) >> 7) & 3)
|
|
|
|
|
|
|
|
static inline void imx233_pinctrl_setup_vpin(vpin_t vpin, const char *name,
|
|
|
|
unsigned drive, bool pullup)
|
|
|
|
{
|
|
|
|
unsigned bank = VPIN_UNPACK_BANK(vpin), pin = VPIN_UNPACK_PIN(vpin);
|
|
|
|
imx233_pinctrl_acquire(bank, pin, name);
|
|
|
|
imx233_pinctrl_set_function(bank, pin, VPIN_UNPACK_MUX(vpin));
|
|
|
|
imx233_pinctrl_set_drive(bank, pin, drive);
|
|
|
|
imx233_pinctrl_enable_pullup(bank, pin, pullup);
|
|
|
|
}
|
|
|
|
|
2013-06-16 19:15:09 +00:00
|
|
|
#if IMX233_SUBTARGET < 3700
|
|
|
|
#include "pins/pins-stmp3600.h"
|
|
|
|
#elif IMX233_SUBTARGET < 3770
|
|
|
|
#include "pins/pins-stmp3700.h"
|
|
|
|
#elif IMX233_SUBTARGET < 3780
|
|
|
|
#error implement this
|
|
|
|
#else
|
2013-06-16 17:43:32 +00:00
|
|
|
#include "pins/pins-imx233.h"
|
2013-06-16 19:15:09 +00:00
|
|
|
#endif
|
2013-06-16 17:43:32 +00:00
|
|
|
|
2011-05-01 13:02:46 +00:00
|
|
|
#endif /* __PINCTRL_IMX233_H__ */
|