serial: Refactor mcux lpsci shim driver to use clock control interface

Refactors the mcux lpsci shim driver to use the clock control interface
instead of calling CLOCK_GetFreq() directly. This will allow SoCs with
different clock architectures to reuse this driver.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
This commit is contained in:
Maureen Helm 2017-08-27 10:27:58 -05:00 committed by Kumar Gala
commit e0954d3118
2 changed files with 17 additions and 5 deletions

View file

@ -7,7 +7,7 @@
menuconfig UART_MCUX_LPSCI
bool "MCUX LPSCI driver"
depends on HAS_MCUX_LPSCI
depends on HAS_MCUX_LPSCI && CLOCK_CONTROL
default n
select SERIAL_HAS_DRIVER
select SERIAL_SUPPORT_INTERRUPT

View file

@ -7,13 +7,14 @@
#include <errno.h>
#include <device.h>
#include <uart.h>
#include <clock_control.h>
#include <fsl_lpsci.h>
#include <fsl_clock.h>
#include <soc.h>
struct mcux_lpsci_config {
UART0_Type *base;
clock_name_t clock_source;
char *clock_name;
clock_control_subsys_t clock_subsys;
u32_t baud_rate;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
void (*irq_config_func)(struct device *dev);
@ -231,9 +232,18 @@ static int mcux_lpsci_init(struct device *dev)
{
const struct mcux_lpsci_config *config = dev->config->config_info;
lpsci_config_t uart_config;
struct device *clock_dev;
u32_t clock_freq;
clock_freq = CLOCK_GetFreq(config->clock_source);
clock_dev = device_get_binding(config->clock_name);
if (clock_dev == NULL) {
return -EINVAL;
}
if (clock_control_get_rate(clock_dev, config->clock_subsys,
&clock_freq)) {
return -EINVAL;
}
LPSCI_GetDefaultConfig(&uart_config);
uart_config.enableTx = true;
@ -279,7 +289,9 @@ static void mcux_lpsci_config_func_0(struct device *dev);
static const struct mcux_lpsci_config mcux_lpsci_0_config = {
.base = UART0,
.clock_source = UART0_CLK_SRC,
.clock_name = CONFIG_UART_MCUX_LPSCI_0_CLOCK_NAME,
.clock_subsys =
(clock_control_subsys_t)CONFIG_UART_MCUX_LPSCI_0_CLOCK_SUBSYS,
.baud_rate = NXP_KINETIS_LPSCI_4006A000_CURRENT_SPEED,
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.irq_config_func = mcux_lpsci_config_func_0,