hm60x/hm801: Buttons rework.
[maemo-rb.git] / firmware / target / arm / imx233 / pinctrl-imx233.h
blobec2341044221b75a8d2c0d492ff86b7c1dc345e4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 by Amaury Pouly
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #ifndef __PINCTRL_IMX233_H__
24 #define __PINCTRL_IMX233_H__
26 #include "cpu.h"
28 #define HW_PINCTRL_BASE 0x80018000
30 #define HW_PINCTRL_CTRL (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x0))
31 #define HW_PINCTRL_MUXSEL(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x100 + (i) * 0x10))
32 #define HW_PINCTRL_DRIVE(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x200 + (i) * 0x10))
33 #define HW_PINCTRL_PULL(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x400 + (i) * 0x10))
34 #define HW_PINCTRL_DOUT(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x500 + (i) * 0x10))
35 #define HW_PINCTRL_DIN(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x600 + (i) * 0x10))
36 #define HW_PINCTRL_DOE(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x700 + (i) * 0x10))
37 #define HW_PINCTRL_PIN2IRQ(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x800 + (i) * 0x10))
38 #define HW_PINCTRL_IRQEN(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x900 + (i) * 0x10))
39 #define HW_PINCTRL_IRQEN(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0x900 + (i) * 0x10))
40 #define HW_PINCTRL_IRQLEVEL(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0xa00 + (i) * 0x10))
41 #define HW_PINCTRL_IRQPOL(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0xb00 + (i) * 0x10))
42 #define HW_PINCTRL_IRQSTAT(i) (*(volatile uint32_t *)(HW_PINCTRL_BASE + 0xc00 + (i) * 0x10))
44 #define PINCTRL_FUNCTION_MAIN 0
45 #define PINCTRL_FUNCTION_ALT1 1
46 #define PINCTRL_FUNCTION_ALT2 2
47 #define PINCTRL_FUNCTION_GPIO 3
49 #define PINCTRL_DRIVE_4mA 0
50 #define PINCTRL_DRIVE_8mA 1
51 #define PINCTRL_DRIVE_12mA 2
52 #define PINCTRL_DRIVE_16mA 3 /* not available on all pins */
54 typedef void (*pin_irq_cb_t)(int bank, int pin);
56 static inline void imx233_pinctrl_init(void)
58 __REG_CLR(HW_PINCTRL_CTRL) = __BLOCK_CLKGATE | __BLOCK_SFTRST;
61 static inline void imx233_set_pin_drive_strength(unsigned bank, unsigned pin, unsigned strength)
63 __REG_CLR(HW_PINCTRL_DRIVE(4 * bank + pin / 8)) = 3 << (4 * (pin % 8));
64 __REG_SET(HW_PINCTRL_DRIVE(4 * bank + pin / 8)) = strength << (4 * (pin % 8));
67 static inline void imx233_enable_gpio_output(unsigned bank, unsigned pin, bool enable)
69 if(enable)
70 __REG_SET(HW_PINCTRL_DOE(bank)) = 1 << pin;
71 else
72 __REG_CLR(HW_PINCTRL_DOE(bank)) = 1 << pin;
75 static inline void imx233_enable_gpio_output_mask(unsigned bank, uint32_t pin_mask, bool enable)
77 if(enable)
78 __REG_SET(HW_PINCTRL_DOE(bank)) = pin_mask;
79 else
80 __REG_CLR(HW_PINCTRL_DOE(bank)) = pin_mask;
83 static inline void imx233_set_gpio_output(unsigned bank, unsigned pin, bool value)
85 if(value)
86 __REG_SET(HW_PINCTRL_DOUT(bank)) = 1 << pin;
87 else
88 __REG_CLR(HW_PINCTRL_DOUT(bank)) = 1 << pin;
91 static inline void imx233_set_gpio_output_mask(unsigned bank, uint32_t pin_mask, bool value)
93 if(value)
94 __REG_SET(HW_PINCTRL_DOUT(bank)) = pin_mask;
95 else
96 __REG_CLR(HW_PINCTRL_DOUT(bank)) = pin_mask;
99 static inline uint32_t imx233_get_gpio_input_mask(unsigned bank, uint32_t pin_mask)
101 return HW_PINCTRL_DIN(bank) & pin_mask;
104 static inline void imx233_set_pin_function(unsigned bank, unsigned pin, unsigned function)
106 __REG_CLR(HW_PINCTRL_MUXSEL(2 * bank + pin / 16)) = 3 << (2 * (pin % 16));
107 __REG_SET(HW_PINCTRL_MUXSEL(2 * bank + pin / 16)) = function << (2 * (pin % 16));
110 static inline void imx233_enable_pin_pullup(unsigned bank, unsigned pin, bool enable)
112 if(enable)
113 __REG_SET(HW_PINCTRL_PULL(bank)) = 1 << pin;
114 else
115 __REG_CLR(HW_PINCTRL_PULL(bank)) = 1 << pin;
118 static inline void imx233_enable_pin_pullup_mask(unsigned bank, uint32_t pin_msk, bool enable)
120 if(enable)
121 __REG_SET(HW_PINCTRL_PULL(bank)) = pin_msk;
122 else
123 __REG_CLR(HW_PINCTRL_PULL(bank)) = pin_msk;
126 /** On irq, the pin irq interrupt is disable and then cb is called;
127 * the setup_pin_irq function needs to be called again to enable it again */
128 void imx233_setup_pin_irq(int bank, int pin, bool enable_int,
129 bool level, bool polarity, pin_irq_cb_t cb);
131 #endif /* __PINCTRL_IMX233_H__ */