public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 15/60] gpio: tegra: header file split
Date: Thu, 21 Apr 2016 10:40:34 -0600	[thread overview]
Message-ID: <57190282.5020501@wwwdotorg.org> (raw)
In-Reply-To: <CAPnjgZ0pXUfe_XO6g_xHL0wtVmp53kzKxWWH6vCduOO83VAUqw@mail.gmail.com>

On 04/21/2016 08:11 AM, Simon Glass wrote:
> Hi Stephen,
>
> On 20 April 2016 at 16:01, Stephen Warren <swarren@wwwdotorg.org> wrote:
>> On 04/20/2016 01:26 PM, Simon Glass wrote:
>>>
>>> Hi Stephen,
>>>
>>> On 19 April 2016 at 14:58, Stephen Warren <swarren@wwwdotorg.org> wrote:
>>>>
>>>> From: Stephen Warren <swarren@nvidia.com>
>>>>
>>>> Tegra's gpio.h contains a mix of private definitions for use inside the
>>>> GPIO driver and custom machine-specific APIs. Move the private
>>>> definitions
>>>> out of the global include directory since nothing should need to access
>>>> them. Move the public definitions to the machine-specific include
>>>> directory <mach/>.
>>
>>
>>>> diff --git a/drivers/gpio/tegra_gpio_priv.h
>>>> b/drivers/gpio/tegra_gpio_priv.h
>>
>>
>>>> +/*
>>>> + * GPIO registers are split into two chunks; low and high.
>>>> + * On Tegra20, all low chunks appear first, then all high chunks.
>>>> + * In later SoCs, the low and high chunks are interleaved together.
>>>> + */
>>>> +#define GPIO_CTLR_BANK_HIGH_REGS \
>>>> +       uint gpio_masked_config[TEGRA_GPIO_PORTS]; \
>>>> +       uint gpio_masked_dir_out[TEGRA_GPIO_PORTS]; \
>>>> +       uint gpio_masked_out[TEGRA_GPIO_PORTS]; \
>>>> +       uint reserved0[TEGRA_GPIO_PORTS]; \
>>>> +       uint gpio_masked_int_status[TEGRA_GPIO_PORTS]; \
>>>> +       uint gpio_masked_int_enable[TEGRA_GPIO_PORTS]; \
>>>> +       uint gpio_masked_int_level[TEGRA_GPIO_PORTS]; \
>>>> +       uint reserved1[TEGRA_GPIO_PORTS];
>>>> +
>>>> +/* GPIO Controller registers for a single bank */
>>>> +struct gpio_ctlr_bank {
>>>> +       uint gpio_config[TEGRA_GPIO_PORTS];
>>>> +       uint gpio_dir_out[TEGRA_GPIO_PORTS];
>>>> +       uint gpio_out[TEGRA_GPIO_PORTS];
>>>> +       uint gpio_in[TEGRA_GPIO_PORTS];
>>>> +       uint gpio_int_status[TEGRA_GPIO_PORTS];
>>>> +       uint gpio_int_enable[TEGRA_GPIO_PORTS];
>>>> +       uint gpio_int_level[TEGRA_GPIO_PORTS];
>>>> +       uint gpio_int_clear[TEGRA_GPIO_PORTS];
>>>> +#ifndef CONFIG_TEGRA20
>>>> +       GPIO_CTLR_BANK_HIGH_REGS
>>>> +#endif
>>>> +};
>>>> +
>>>> +#ifdef CONFIG_TEGRA20
>>>> +struct gpio_ctlr_bank_high {
>>>> +       GPIO_CTLR_BANK_HIGH_REGS
>>>
>>>
>>> This seems a bit ugly. Perhaps you could havestruct
>>> gpio_ctlr_high_regs and include that here? It adds a level of
>>> indirection but that doesn't seem very important.
>>
>>
>> In newer Tegras, there's no differentiation between the two register sets
>> that were "low" and "high" in Tegra20. I'd rather not saddle the non-Tegra20
>> struct layouts with some odd naming/nesting just because the Tegra20 layout
>> was odd. I don't see any problem with using a #define for this; it doesn't
>> seem to make the code complex.
>
> OK, well then how about just duplicating the two structs, and dropping
> the #define?
>
> #ifdfef CONFIG_TEGRA20
> struct gpio_ctlr_bank {
>
> };
> #else
> struct gpio_ctlr_bank {
> };
> #endif

Given that the driver doesn't use any registers in the high bank, and 
indeed can't; the driver's reliance on structs rather than register 
defines means that the high bank registers would have to be accessed 
differently between Tegra20 and other SoCs, I propose simply not 
representing those registers. Instead, how about:

struct gpio_ctlr_bank {
	uint gpio_config[TEGRA_GPIO_PORTS];
	uint gpio_dir_out[TEGRA_GPIO_PORTS];
	uint gpio_out[TEGRA_GPIO_PORTS];
	uint gpio_in[TEGRA_GPIO_PORTS];
	uint gpio_int_status[TEGRA_GPIO_PORTS];
	uint gpio_int_enable[TEGRA_GPIO_PORTS];
	uint gpio_int_level[TEGRA_GPIO_PORTS];
	uint gpio_int_clear[TEGRA_GPIO_PORTS];
#ifndef CONFIG_TEGRA20
	uint unused[TEGRA_GPIO_PORTS * 8];
#endif
};

struct gpio_ctlr {
	struct gpio_ctlr_bank gpio_bank[TEGRA_GPIO_BANKS];
};

That removes all the duplication, without any macros etc.

Does that look reasonable? If I fixup the patch like that, I'll add a 
brief comment describing what the unused registers are, similar to the 
one in patch v1.

>> I wonder if we should just convert away from structs for registers entirely.
>> Everything in the HW docs is just numbers, matching those to the structs is
>> always painful, and if we used #defines instead of structs, representing
>> this HW difference would end up being much cleaner and avoid using a macro
>> to "cut/paste" a register list 2 times; see the way the Linux kernel driver
>> handles this.
>
> Structs are definitely easier to read and particularly in this case
> where each struct element is an array.

I'm not really sure there's much objective difference between the 
readability of the two. Arrays can easily be abstracted via a macro or 
inline function so that the call site looks essentially identical; () vs [].

> Why are you worried about code duplication in a header file?

I'm not sure why I would special case my concerns and ignore duplication 
in certain locations yet still care about duplication in general or 
elsewhere?

  reply	other threads:[~2016-04-21 16:40 UTC|newest]

Thread overview: 177+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-19 20:58 [U-Boot] [PATCH 00/60] ARM: tegra: cleanup part 1 Stephen Warren
2016-04-19 20:58 ` [U-Boot] [PATCH 01/60] ARM: tegra: remove unused definitions in headers Stephen Warren
2016-04-20 19:25   ` Simon Glass
2016-04-24 10:20   ` Wolfgang Denk
2016-04-25 19:34     ` Stephen Warren
2016-04-25 21:46       ` Wolfgang Denk
2016-04-25 22:00         ` Stephen Warren
2016-04-25 21:54       ` Simon Glass
2016-04-25 22:02         ` Stephen Warren
2016-04-25 22:15           ` Simon Glass
2016-04-25 22:16           ` Tom Rini
2016-04-19 20:58 ` [U-Boot] [PATCH 02/60] mmc: tegra: move pad init into MMC driver Stephen Warren
2016-04-20 19:25   ` Simon Glass
2016-04-24 10:20   ` Wolfgang Denk
2016-04-25 19:42     ` Stephen Warren
2016-04-25 21:52       ` Wolfgang Denk
2016-04-25 22:37         ` Tom Rini
2016-04-25 22:43           ` Stephen Warren
2016-04-25 23:05             ` Tom Rini
2016-04-25 23:11               ` Stephen Warren
2016-04-25 23:26                 ` Tom Rini
2016-04-25 23:34                   ` Stephen Warren
2016-04-26  0:14                     ` Tom Rini
2016-04-26 16:21                       ` Stephen Warren
2016-04-26 18:15                         ` Tom Rini
2016-04-26 18:09                     ` Wolfgang Denk
2016-04-19 20:58 ` [U-Boot] [PATCH 03/60] mmc: tegra: move header file to driver directory Stephen Warren
2016-04-20 19:25   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 04/60] mmc: tegra: move public header to arch/arm/mach-tegra/include Stephen Warren
2016-04-20 19:25   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 05/60] pwm: tegra: move header file to driver directory Stephen Warren
2016-04-20 19:25   ` Simon Glass
2016-04-24 10:20   ` Wolfgang Denk
2016-04-25 19:47     ` Stephen Warren
2016-04-19 20:58 ` [U-Boot] [PATCH 06/60] i2c: " Stephen Warren
2016-04-20  4:48   ` Heiko Schocher
2016-04-20 19:25   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 07/60] usb: " Stephen Warren
2016-04-20 19:25   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 08/60] video: " Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 09/60] ARM: tegra: correct 64-bit DT unit addresses Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 10/60] ARM: tegra: sort DT /aliases entries Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 11/60] ARM: tegra: add DT alias for GPIO controller Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 12/60] gpio: tegra: remove duplicate define Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 13/60] ARM: tegra: sort some board file include directives Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-24 10:20   ` Wolfgang Denk
2016-04-25 19:54     ` Stephen Warren
2016-04-25 21:59       ` Wolfgang Denk
2016-04-25 23:22         ` Tom Rini
2016-04-26 16:18           ` Stephen Warren
2016-04-26 18:13             ` Wolfgang Denk
2016-04-26 18:20               ` Wolfgang Denk
2016-04-26 18:15             ` Tom Rini
2016-04-26 20:44               ` Stephen Warren
2016-04-26 23:29                 ` Tom Rini
2016-04-26 16:23           ` Stephen Warren
2016-04-26 18:15             ` Tom Rini
2016-04-19 20:58 ` [U-Boot] [PATCH 14/60] ARM: tegra: use DT bindings for GPIO naming Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 15/60] gpio: tegra: header file split Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-20 22:01     ` Stephen Warren
2016-04-21 14:11       ` Simon Glass
2016-04-21 16:40         ` Stephen Warren [this message]
2016-04-21 16:51           ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 16/60] ARM: tegra: migrate TEGRA_GPIO to Kconfig Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 17/60] ARM: tegra: move apb_misc.h Stephen Warren
2016-04-20 19:26   ` Simon Glass
2016-04-20 21:56     ` Stephen Warren
2016-04-21 20:59       ` Simon Glass
2016-04-21 21:14         ` Stephen Warren
2016-04-19 20:58 ` [U-Boot] [PATCH 18/60] ARM: tegra: move fuse.h Stephen Warren
2016-04-22 18:30   ` Simon Glass
2016-04-19 20:58 ` [U-Boot] [PATCH 19/60] ARM: tegra: move gpu.h Stephen Warren
2016-04-22 18:30   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 20/60] ARM: tegra: move pmc.h Stephen Warren
2016-04-22 18:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 21/60] ARM: tegra: move scu.h Stephen Warren
2016-04-22 18:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 22/60] ARM: tegra: move warmboot.h Stephen Warren
2016-04-22 18:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 23/60] ARM: tegra: move xusb-padctl.h to <mach/> Stephen Warren
2016-04-22 18:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 24/60] ARM: tegra: unify+move {board, sys_proto}.h " Stephen Warren
2016-04-22 18:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 25/60] ARM: tegra: use consistently named include guards Stephen Warren
2016-04-22 18:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 26/60] ARM: tegra: delete unused headers Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 27/60] ARM: tegra: move emc.h Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 28/60] ARM: tegra: move sdram_param.h Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 29/60] ARM: tegra: move sysctr.h Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 30/60] ARM: tegra: remove pmu.h Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-22 20:42     ` Stephen Warren
2016-04-19 20:59 ` [U-Boot] [PATCH 31/60] ARM: tegra: move powergate.h to <mach/> Stephen Warren
2016-04-22 18:33   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 32/60] ARM: tegra: add SoC-specific include directory Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 33/60] ARM: tegra: fix bug in Tegra20 flow.h Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 34/60] ARM: tegra: move flow.h Stephen Warren
2016-04-22 18:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 35/60] nyan-big: remove direct MC register access Stephen Warren
2016-04-22 18:33   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 36/60] ARM: tegra: move mc.h Stephen Warren
2016-04-22 18:33   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 37/60] ARM: tegra: move SDIOCFG_DRV* to pinmux.h Stephen Warren
2016-04-23 17:14   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 38/60] ARM: tegra: remove tegra_get_chip() Stephen Warren
2016-04-23 17:14   ` Simon Glass
2016-04-25 19:25     ` Stephen Warren
2016-04-27 14:50       ` Simon Glass
2016-04-27 16:13         ` Stephen Warren
2016-04-29 14:02           ` Simon Glass
2016-04-29 16:27             ` Stephen Warren
2016-04-29 16:53               ` Simon Glass
2016-04-29 17:42                 ` Simon Glass
2016-04-29 19:21                   ` Stephen Warren
2016-05-01 19:16                     ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 39/60] ARM: tegra: remove get_num_cpus() Stephen Warren
2016-04-19 20:59 ` [U-Boot] [PATCH 40/60] ARM: tegra: remove gp_padctrl.h Stephen Warren
2016-05-07 22:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 41/60] ARM: tegra: remove tegra_get_sku_info() Stephen Warren
2016-05-07 22:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 42/60] ARM: tegra: move EMC code to tegra20/ directory Stephen Warren
2016-05-07 22:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 43/60] ARM: tegra: move PLLX configuration into SoC directories Stephen Warren
2016-05-07 22:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 44/60] ARM: tegra: remove tegra_get_chip_sku() Stephen Warren
2016-05-07 22:31   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 45/60] ARM: tegra: move custom pinmux.h to <mach/> Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 46/60] ARM: tegra: add pinmux APIs to replace funcmux Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 47/60] ARM: tegra: provide API for SPL code to init UART Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 48/60] ARM: tegra: lay groundwork for board hook cleanup Stephen Warren
2016-04-19 20:59 ` [U-Boot] [PATCH 49/60] ARM: tegra: convert boards to new hooks Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 50/60] ARM: tegra: remove unused includes Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 51/60] ARM: tegra: move SPL-specific GPIO device to spl.c Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 52/60] ARM: tegra: convert pin_mux_*() to new hooks Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 53/60] tegra: keyboard: move pinmux setup to board files Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 54/60] video: tegra: " Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 55/60] i2c: " Stephen Warren
2016-04-27 15:12   ` Simon Glass
2016-04-27 16:24     ` Stephen Warren
2016-04-27 16:58       ` Simon Glass
2016-04-27 17:16         ` Stephen Warren
2016-04-29 14:02           ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 56/60] ARM: tegra: remove funcmux API Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 57/60] ARM: tegra: don't access Boot Info Table from board code Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 58/60] ARM: tegra: clean up board include statements Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 59/60] ARM: tegra: unify+move tegra.h to mach-tegra/ Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-04-19 20:59 ` [U-Boot] [PATCH 60/60] ARM: tegra: move clock headers Stephen Warren
2016-05-07 22:32   ` Simon Glass
2016-05-07 22:32 ` [U-Boot] [PATCH 00/60] ARM: tegra: cleanup part 1 Simon Glass

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=57190282.5020501@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=u-boot@lists.denx.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