Skip to content
Permalink
Browse files

drivers: uart_qmsi: Get clock frequency from DTS

The uart_qmsi driver used system clock frequency
as a base for baudrate calculation. This commit corrects
that by obtaining the needed value from DTS.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
  • Loading branch information...
pizi-nordic authored and carlescufi committed Apr 11, 2019
1 parent 69bbcec commit dc44cb00d1d0ea402c16694bcda1430fb3dee97e
Showing with 28 additions and 14 deletions.
  1. +20 −10 drivers/serial/uart_qmsi.c
  2. +4 −2 soc/arc/quark_se_c1000_ss/dts_fixup.h
  3. +4 −2 soc/x86/intel_quark/quark_se/dts_fixup.h
@@ -20,10 +20,10 @@

#define IIR_IID_NO_INTERRUPT_PENDING 0x01

#define DIVISOR_LOW(baudrate) \
((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / (16 * baudrate)) & 0xFF)
#define DIVISOR_HIGH(baudrate) \
(((CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / (16 * baudrate)) & 0xFF00) >> 8)
#define DIVISOR_LOW(clock, baudrate) \
((clock / (16 * baudrate)) & 0xFF)
#define DIVISOR_HIGH(clock, baudrate) \
(((clock / (16 * baudrate)) & 0xFF00) >> 8)

/* Convenient macro to get the controller instance. */
#define GET_CONTROLLER_INSTANCE(dev) \
@@ -33,6 +33,7 @@
struct uart_qmsi_config_info {
qm_uart_t instance;
clk_periph_t clock_gate;
u32_t clock_frequency;
u32_t baud_divisor;
bool hw_fc;

@@ -140,9 +141,12 @@ static void irq_config_func_0(struct device *dev);
static const struct uart_qmsi_config_info config_info_0 = {
.instance = QM_UART_0,
.clock_gate = CLK_PERIPH_UARTA_REGISTER | CLK_PERIPH_CLK,
.clock_frequency = DT_UART_QMSI_0_CLOCK_FREQUENCY,
.baud_divisor = QM_UART_CFG_BAUD_DL_PACK(
DIVISOR_HIGH(DT_UART_QMSI_0_BAUDRATE),
DIVISOR_LOW(DT_UART_QMSI_0_BAUDRATE),
DIVISOR_HIGH(DT_UART_QMSI_0_CLOCK_FREQUENCY,
DT_UART_QMSI_0_BAUDRATE),
DIVISOR_LOW(DT_UART_QMSI_0_CLOCK_FREQUENCY,
DT_UART_QMSI_0_BAUDRATE),
0),
#ifdef CONFIG_UART_QMSI_0_HW_FC
.hw_fc = true,
@@ -168,9 +172,12 @@ static void irq_config_func_1(struct device *dev);
static const struct uart_qmsi_config_info config_info_1 = {
.instance = QM_UART_1,
.clock_gate = CLK_PERIPH_UARTB_REGISTER | CLK_PERIPH_CLK,
.clock_frequency = DT_UART_QMSI_1_CLOCK_FREQUENCY,
.baud_divisor = QM_UART_CFG_BAUD_DL_PACK(
DIVISOR_HIGH(DT_UART_QMSI_1_BAUDRATE),
DIVISOR_LOW(DT_UART_QMSI_1_BAUDRATE),
DIVISOR_HIGH(DT_UART_QMSI_1_CLOCK_FREQUENCY,
DT_UART_QMSI_1_BAUDRATE),
DIVISOR_LOW(DT_UART_QMSI_1_CLOCK_FREQUENCY,
DT_UART_QMSI_1_BAUDRATE),
0),
#ifdef CONFIG_UART_QMSI_1_HW_FC
.hw_fc = true,
@@ -405,13 +412,16 @@ static void irq_config_func_1(struct device *dev)
static int uart_qmsi_line_ctrl_set(struct device *dev, u32_t ctrl, u32_t val)
{
qm_uart_t instance = GET_CONTROLLER_INSTANCE(dev);
const struct uart_qmsi_config_info *config = dev->config->config_info;
qm_uart_config_t cfg;

switch (ctrl) {
case LINE_CTRL_BAUD_RATE:
cfg.line_control = QM_UART[instance]->lcr;
cfg.baud_divisor = QM_UART_CFG_BAUD_DL_PACK(DIVISOR_HIGH(val),
DIVISOR_LOW(val), 0);
cfg.baud_divisor = QM_UART_CFG_BAUD_DL_PACK(
DIVISOR_HIGH(config->clock_frequency, val),
DIVISOR_LOW(config->clock_frequency, val),
0);
if (cfg.baud_divisor == 0) {
return -EINVAL;
}
@@ -2,12 +2,14 @@

/* SoC level DTS fixup file */

#define DT_UART_QMSI_0_BAUDRATE DT_INTEL_QMSI_UART_B0002000_CURRENT_SPEED
#define DT_UART_QMSI_0_CLOCK_FREQUENCY DT_INTEL_QMSI_UART_B0002000_CLOCKS_CLOCK_FREQUENCY
#define DT_UART_QMSI_0_BAUDRATE DT_INTEL_QMSI_UART_B0002000_CURRENT_SPEED
#define DT_UART_QMSI_0_NAME DT_INTEL_QMSI_UART_B0002000_LABEL
#define DT_UART_QMSI_0_IRQ DT_INTEL_QMSI_UART_B0002000_IRQ_0
#define DT_UART_QMSI_0_IRQ_PRI DT_INTEL_QMSI_UART_B0002000_IRQ_0_PRIORITY

#define DT_UART_QMSI_1_BAUDRATE DT_INTEL_QMSI_UART_B0002400_CURRENT_SPEED
#define DT_UART_QMSI_1_CLOCK_FREQUENCY DT_INTEL_QMSI_UART_B0002400_CLOCKS_CLOCK_FREQUENCY
#define DT_UART_QMSI_1_BAUDRATE DT_INTEL_QMSI_UART_B0002400_CURRENT_SPEED
#define DT_UART_QMSI_1_NAME DT_INTEL_QMSI_UART_B0002400_LABEL
#define DT_UART_QMSI_1_IRQ DT_INTEL_QMSI_UART_B0002400_IRQ_0
#define DT_UART_QMSI_1_IRQ_PRI DT_INTEL_QMSI_UART_B0002400_IRQ_0_PRIORITY
@@ -2,13 +2,15 @@

/* SoC level DTS fixup file */

#define DT_UART_QMSI_0_BAUDRATE DT_INTEL_QMSI_UART_B0002000_CURRENT_SPEED
#define DT_UART_QMSI_0_CLOCK_FREQUENCY DT_INTEL_QMSI_UART_B0002000_CLOCKS_CLOCK_FREQUENCY
#define DT_UART_QMSI_0_BAUDRATE DT_INTEL_QMSI_UART_B0002000_CURRENT_SPEED
#define DT_UART_QMSI_0_NAME DT_INTEL_QMSI_UART_B0002000_LABEL
#define DT_UART_QMSI_0_IRQ DT_INTEL_QMSI_UART_B0002000_IRQ_0
#define DT_UART_QMSI_0_IRQ_PRI DT_INTEL_QMSI_UART_B0002000_IRQ_0_PRIORITY
#define DT_UART_QMSI_0_IRQ_FLAGS DT_INTEL_QMSI_UART_B0002000_IRQ_0_SENSE

#define DT_UART_QMSI_1_BAUDRATE DT_INTEL_QMSI_UART_B0002400_CURRENT_SPEED
#define DT_UART_QMSI_1_CLOCK_FREQUENCY DT_INTEL_QMSI_UART_B0002400_CLOCKS_CLOCK_FREQUENCY
#define DT_UART_QMSI_1_BAUDRATE DT_INTEL_QMSI_UART_B0002400_CURRENT_SPEED
#define DT_UART_QMSI_1_NAME DT_INTEL_QMSI_UART_B0002400_LABEL
#define DT_UART_QMSI_1_IRQ DT_INTEL_QMSI_UART_B0002400_IRQ_0
#define DT_UART_QMSI_1_IRQ_PRI DT_INTEL_QMSI_UART_B0002400_IRQ_0_PRIORITY

0 comments on commit dc44cb0

Please sign in to comment.
You can’t perform that action at this time.