mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: Wadim Egorov <w.egorov@phytec.de>
Cc: "barebox@lists.infradead.org" <barebox@lists.infradead.org>
Subject: Re: [PATCH 3/8] ARM: rockchip: Add early debug support for RK3288
Date: Thu, 28 Jul 2016 11:55:54 -0700	[thread overview]
Message-ID: <CAHQ1cqGeD9NG9oWDbUqNNGv9=i-H9Z5ehHU7+a-My7wqzAT+oA@mail.gmail.com> (raw)
In-Reply-To: <5799F20D.6050904@phytec.de>

On Thu, Jul 28, 2016 at 4:52 AM, Wadim Egorov <w.egorov@phytec.de> wrote:
> Hi Andrey,
>
> On 20.07.2016 17:03, Andrey Smirnov wrote:
>> On Wed, Jul 20, 2016 at 7:17 AM, Wadim Egorov <w.egorov@phytec.de> wrote:
>>> Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
>>> ---
>>>  arch/arm/mach-rockchip/include/mach/debug_ll.h | 72 +++++++++++++++-----------
>>>  common/Kconfig                                 |  6 +--
>>>  2 files changed, 45 insertions(+), 33 deletions(-)
>>>
>>> diff --git a/arch/arm/mach-rockchip/include/mach/debug_ll.h b/arch/arm/mach-rockchip/include/mach/debug_ll.h
>>> index c666b99..144cada 100644
>>> --- a/arch/arm/mach-rockchip/include/mach/debug_ll.h
>>> +++ b/arch/arm/mach-rockchip/include/mach/debug_ll.h
>>> @@ -1,25 +1,31 @@
>>>  #ifndef __MACH_DEBUG_LL_H__
>>>  #define __MACH_DEBUG_LL_H__
>>>
>>> +#include <common.h>
>>>  #include <io.h>
>>> +#include <mach/rk3188-regs.h>
>>> +#include <mach/rk3288-regs.h>
>>> +
>>> +#ifdef CONFIG_ARCH_RK3188
>>> +
>>> +#define UART_CLOCK             100000000
>>> +#define RK_DEBUG_SOC           RK3188
>>> +#define serial_out(a, v)       writeb(v, a)
>>> +#define serial_in(a)           readb(a)
>>> +
>>> +#elif defined CONFIG_ARCH_RK3288
>>> +
>>> +#define UART_CLOCK             24000000
>>> +#define RK_DEBUG_SOC           RK3288
>>> +#define serial_out(a, v)       writel(v, a)
>>> +#define serial_in(a)           readl(a)
>> These "serial_in/out" macros seem a bit redundant to me. What's the
>> story behind them, why were they added?

Oh! I didn't notice the difference between the two definitions. Makes
sense. Maybe implement it as a inline function and use if
(IS_ENABLED(CONFIG_ARCH_RK3188)) to dispatch appropriate writes, so as
to avoid macros and have the code be more self documenting?

>
> writeb() does not work with RK3288. So I added serial_in/out macros to
> split the different types of memory access to the uart registers.
>
>>
>>> -#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 0
>>> -#define UART_BASE      0x10124000
>>> -#endif
>>> -#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 1
>>> -#define UART_BASE      0x10126000
>>> -#endif
>>> -#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 2
>>> -#define UART_BASE      0x20064000
>>> -#endif
>>> -#if CONFIG_DEBUG_ROCKCHIP_UART_PORT == 3
>>> -#define UART_BASE      0x20068000
>>>  #endif
>>>
>>> -#define LSR_THRE       0x20    /* Xmit holding register empty */
>>> -#define LSR            (5 << 2)
>>> -#define THR            (0 << 2)
>>> +#define __RK_UART_BASE(soc, num) soc##_UART##num##_BASE
>>> +#define RK_UART_BASE(soc, num) __RK_UART_BASE(soc, num)
>>>
>>> +#define LSR_THRE       0x20    /* Xmit holding register empty */
>>>  #define LCR_BKSE       0x80    /* Bank select enable */
>>>  #define LSR            (5 << 2)
>>>  #define THR            (0 << 2)
>>> @@ -33,28 +39,34 @@
>>>
>>>  static inline void INIT_LL(void)
>>>  {
>>> -       unsigned int clk = 100000000;
>>> -       unsigned int divisor = clk / 16 / 115200;
>>> -
>>> -       writeb(0x00, UART_BASE + LCR);
>>> -       writeb(0x00, UART_BASE + IER);
>>> -       writeb(0x07, UART_BASE + MDR);
>>> -       writeb(LCR_BKSE, UART_BASE + LCR);
>>> -       writeb(divisor & 0xff, UART_BASE + DLL);
>>> -       writeb(divisor >> 8, UART_BASE + DLM);
>>> -       writeb(0x03, UART_BASE + LCR);
>>> -       writeb(0x03, UART_BASE + MCR);
>>> -       writeb(0x07, UART_BASE + FCR);
>>> -       writeb(0x00, UART_BASE + MDR);
>>> +       void __iomem *base = (void *)RK_UART_BASE(RK_DEBUG_SOC,
>>> +               CONFIG_DEBUG_ROCKCHIP_UART_PORT);
>> There's a IOMEM macro that you could use to avoid explicit casting.
>
> ok
>
>>
>>> +       unsigned int divisor = DIV_ROUND_CLOSEST(UART_CLOCK, 16 * 115200);
>> I'd suggest CONFIG_BAUDRATE instead of hard-coded value.
>
> ok
>
>>
>>> +
>>> +       serial_out(base + LCR, 0x00);
>>> +       serial_out(base + IER, 0x00);
>>> +       serial_out(base + MDR, 0x07);
>>> +       serial_out(base + LCR, LCR_BKSE);
>>> +       serial_out(base + DLL, divisor & 0xff);
>>> +       serial_out(base + DLM, divisor >> 8);
>>> +       serial_out(base + LCR, 0x03);
>>> +       serial_out(base + MCR, 0x03);
>>> +       serial_out(base + FCR, 0x07);
>>> +       serial_out(base + MDR, 0x00);
>>>  }
>>>
>>>  static inline void PUTC_LL(char c)
>>>  {
>>> +       void __iomem *base = (void *)RK_UART_BASE(RK_DEBUG_SOC,
>>> +               CONFIG_DEBUG_ROCKCHIP_UART_PORT);
>> IOMEM here as well.
>
> ok
>
>>
>>> +
>>>         /* Wait until there is space in the FIFO */
>>> -       while ((readb(UART_BASE + LSR) & LSR_THRE) == 0);
>>> +       while ((serial_in(base + LSR) & LSR_THRE) == 0)
>>> +               ;
>> You could probably separate this busy loop into a small inline
>> function and re-use it below and in the code of the full-fledged
>> driver.
>
> I don't really see the point here.
>

This code snippet was used at least twice in your code and I assumed
you'd use same idiom in the full UART driver for that part, so the
same point as with any other code coalescing -- avoiding repetition
and separating behavior from implementation details. Anyway, just a
suggestion.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2016-07-28 18:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20 14:17 [PATCH 1/8] ARM: rockchip: Add basic RK3288 support Wadim Egorov
2016-07-20 14:17 ` [PATCH 2/8] ARM: rockchip: Add timer driver Wadim Egorov
2016-07-20 17:35   ` Andrey Smirnov
2016-07-28 11:55     ` Wadim Egorov
2016-07-28 19:12       ` Andrey Smirnov
2016-08-03  5:47       ` Sascha Hauer
2016-08-03  6:59         ` Wadim Egorov
2016-07-20 14:17 ` [PATCH 3/8] ARM: rockchip: Add early debug support for RK3288 Wadim Egorov
2016-07-20 15:03   ` Andrey Smirnov
2016-07-28 11:52     ` Wadim Egorov
2016-07-28 18:55       ` Andrey Smirnov [this message]
2016-07-20 14:17 ` [PATCH 4/8] clk: Add RK3288 clock driver Wadim Egorov
2016-07-20 14:17 ` [PATCH 5/8] mci: dw_mmc: Add RK3288 compatible string Wadim Egorov
2016-07-20 14:17 ` [PATCH 6/8] ARM: Add phyCORE-RK3288 SOM support Wadim Egorov
2016-07-20 17:57   ` Andrey Smirnov
2016-07-20 14:17 ` [PATCH 7/8] configs: Add RK3288 defconfig Wadim Egorov
2016-07-20 14:17 ` [PATCH 8/8] doc: Add RK3288 Documentation Wadim Egorov
2016-07-21  7:00   ` Sascha Hauer
2016-07-21  7:09     ` Wadim Egorov
2016-07-20 17:52 ` [PATCH 1/8] ARM: rockchip: Add basic RK3288 support Andrey Smirnov
2016-07-21  6:54   ` Sascha Hauer
2016-07-28 11:59     ` Wadim Egorov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHQ1cqGeD9NG9oWDbUqNNGv9=i-H9Z5ehHU7+a-My7wqzAT+oA@mail.gmail.com' \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=w.egorov@phytec.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox