2016-03-03 22:33:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Open-RnD Sp. z o.o.
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-03-03 22:33:15 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file header for STM32 pin multiplexing
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _STM32_PINMUX_H_
|
|
|
|
#define _STM32_PINMUX_H_
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-03-03 22:33:15 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <clock_control.h>
|
2017-07-25 17:57:28 +08:00
|
|
|
#ifdef CONFIG_SOC_SERIES_STM32F1X
|
2017-07-27 00:12:02 +08:00
|
|
|
#include <dt-bindings/pinctrl/stm32-pinctrlf1.h>
|
2017-07-25 17:57:28 +08:00
|
|
|
#else
|
2017-07-27 00:12:02 +08:00
|
|
|
#include <dt-bindings/pinctrl/stm32-pinctrl.h>
|
|
|
|
#endif /* CONFIG_SOC_SERIES_STM32F1X */
|
|
|
|
#include "pinmux/pinmux.h"
|
2017-07-27 00:10:25 +08:00
|
|
|
|
2016-10-05 17:51:34 +08:00
|
|
|
|
2016-03-03 22:33:15 +08:00
|
|
|
/* pretend that array will cover pin functions */
|
|
|
|
typedef int stm32_pin_func_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief pinmux config wrapper
|
|
|
|
*
|
|
|
|
* GPIO function is assumed to be always available, as such it's not listed
|
|
|
|
* in @funcs array
|
|
|
|
*/
|
|
|
|
struct stm32_pinmux_conf {
|
2017-04-21 23:03:20 +08:00
|
|
|
u32_t pin; /* pin ID */
|
2016-03-03 22:33:15 +08:00
|
|
|
const stm32_pin_func_t *funcs; /* functions array, indexed with
|
|
|
|
* (stm32_pin_alt_func - 1)
|
|
|
|
*/
|
|
|
|
const size_t nfuncs; /* number of alternate functions, not
|
|
|
|
* counting GPIO
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief helper to extract IO port number from STM32PIN() encoded
|
|
|
|
* value
|
|
|
|
*/
|
|
|
|
#define STM32_PORT(__pin) \
|
2017-08-02 01:57:52 +08:00
|
|
|
((__pin) >> 4)
|
2016-03-03 22:33:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief helper to extract IO pin number from STM32PIN() encoded
|
|
|
|
* value
|
|
|
|
*/
|
|
|
|
#define STM32_PIN(__pin) \
|
2017-08-02 01:57:52 +08:00
|
|
|
((__pin) & 0xf)
|
2016-03-03 22:33:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief helper for mapping IO port to its clock subsystem
|
|
|
|
*
|
|
|
|
* @param port IO port
|
|
|
|
*
|
|
|
|
* Map given IO @port to corresponding clock subsystem. The returned
|
2017-04-20 01:45:34 +08:00
|
|
|
* clock subsystem ID must suitable for passing as parameter to
|
2016-03-03 22:33:15 +08:00
|
|
|
* clock_control_on(). Implement this function at the SoC level.
|
|
|
|
*
|
|
|
|
* @return clock subsystem ID
|
|
|
|
*/
|
|
|
|
clock_control_subsys_t stm32_get_port_clock(int port);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief helper for configuration of IO pin
|
|
|
|
*
|
|
|
|
* @param pin IO pin, STM32PIN() encoded
|
|
|
|
* @param func IO function encoded
|
2016-03-22 04:14:15 +08:00
|
|
|
* @param clk clock control device, for enabling/disabling clock gate
|
|
|
|
* for the port
|
2016-03-03 22:33:15 +08:00
|
|
|
*/
|
2017-04-21 23:03:20 +08:00
|
|
|
int _pinmux_stm32_set(u32_t pin, u32_t func,
|
2016-03-22 04:14:15 +08:00
|
|
|
struct device *clk);
|
2016-03-03 22:33:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief helper for obtaining pin configuration for the board
|
|
|
|
*
|
|
|
|
* @param[out] pins set to the number of pins in the array
|
|
|
|
*
|
|
|
|
* Obtain pin assignment/configuration for current board. This call
|
|
|
|
* needs to be implemented at the board integration level. After
|
|
|
|
* restart all pins are already configured as GPIO and can be skipped
|
2017-04-20 01:45:34 +08:00
|
|
|
* in the configuration array. Pin numbers in @pin_num field are
|
2016-03-03 22:33:15 +08:00
|
|
|
* STM32PIN() encoded.
|
|
|
|
*
|
|
|
|
* @return array of pin assignments
|
|
|
|
*/
|
2016-03-22 04:14:15 +08:00
|
|
|
void stm32_setup_pins(const struct pin_config *pinconf,
|
|
|
|
size_t pins);
|
2016-03-03 22:33:15 +08:00
|
|
|
|
|
|
|
/* common pinmux device name for all STM32 chips */
|
|
|
|
#define STM32_PINMUX_NAME "stm32-pinmux"
|
|
|
|
|
2016-04-03 10:40:26 +08:00
|
|
|
#ifdef CONFIG_SOC_SERIES_STM32F1X
|
2016-03-06 20:53:00 +08:00
|
|
|
#include "pinmux_stm32f1.h"
|
2016-12-21 16:56:20 +08:00
|
|
|
#elif CONFIG_SOC_SERIES_STM32F3X
|
|
|
|
#include "pinmux_stm32f3.h"
|
2016-08-11 05:28:32 +08:00
|
|
|
#elif CONFIG_SOC_SERIES_STM32F4X
|
|
|
|
#include "pinmux_stm32f4.h"
|
2016-12-21 16:56:20 +08:00
|
|
|
#elif CONFIG_SOC_SERIES_STM32L4X
|
2016-10-05 17:53:10 +08:00
|
|
|
#include "pinmux_stm32l4x.h"
|
|
|
|
#endif
|
|
|
|
|
2016-03-03 22:33:15 +08:00
|
|
|
#endif /* _STM32_PINMUX_H_ */
|