2014-04-02 05:56:19

by Michal Simek

[permalink] [raw]
Subject: Re: [PATCH 1/2] GPIO: Add driver for Zynq GPIO controller

Hi Linus,

On 03/31/2014 10:22 AM, Linus Walleij wrote:
> On Sat, Mar 29, 2014 at 5:44 AM, Harini Katakam
> <[email protected]> wrote:
>> On Sat, Mar 29, 2014 at 3:20 AM, Linus Walleij <[email protected]> wrote:
>>> On Thu, Mar 27, 2014 at 4:25 PM, Harini Katakam <[email protected]> wrote:
>
>>>> +/* Read/Write access to the GPIO PS registers */
>>>> +static inline u32 zynq_gpio_readreg(void __iomem *offset)
>>>> +{
>>>> + return readl_relaxed(offset);
>>>> +}
>>>> +
>>>> +static inline void zynq_gpio_writereg(void __iomem *offset, u32 val)
>>>> +{
>>>> + writel_relaxed(val, offset);
>>>> +}
>>>
>>> I think this is unnecessary and confusing indirection.
>>> Just use the readl_relaxed/writel_relaxed functions directly in
>>> the code.
>>>
>>
>> This is just to be flexible.
>
> Define exactly what you mean with "flexible" in this context. I
> only see unnecessary overhead and hard-to-read code.

We have just passed this discussion for watchdog driver
here: https://lkml.org/lkml/2014/4/1/843

Are you ok with doing it in this way?

static inline u32 zynq_gpio_readreg(struct zynq_gpio *gpio, u32 offset)
{
return readl_relaxed(gpio->base_addr + offset);
}

static inline void zynq_gpio_writereg(struct zynq_gpio *gpio, u32 offset, u32 val)
{
writel_relaxed(val, gpio->base_addr + offset);
}

Or even like this to be able to handle error cases.

static inline int zynq_gpio_readreg(struct zynq_gpio *gpio, u32 offset, u32 *val)
{
*val = readl_relaxed(gpio->base_addr + offset);
return 0;
}

static inline int zynq_gpio_writereg(struct zynq_gpio *gpio, u32 offset, u32 val)
{
writel_relaxed(val, gpio->base_addr + offset);
return 0;
}

Thanks,
Michal

--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: http://www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform



Attachments:
signature.asc (263.00 B)
OpenPGP digital signature

2014-04-10 17:52:26

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 1/2] GPIO: Add driver for Zynq GPIO controller

On Wed, Apr 2, 2014 at 7:56 AM, Michal Simek <[email protected]> wrote:
> On 03/31/2014 10:22 AM, Linus Walleij wrote:
>> On Sat, Mar 29, 2014 at 5:44 AM, Harini Katakam
>> <[email protected]> wrote:
>>> On Sat, Mar 29, 2014 at 3:20 AM, Linus Walleij <[email protected]> wrote:
>>>> On Thu, Mar 27, 2014 at 4:25 PM, Harini Katakam <[email protected]> wrote:
>>
>>>>> +/* Read/Write access to the GPIO PS registers */
>>>>> +static inline u32 zynq_gpio_readreg(void __iomem *offset)
>>>>> +{
>>>>> + return readl_relaxed(offset);
>>>>> +}
>>>>> +
>>>>> +static inline void zynq_gpio_writereg(void __iomem *offset, u32 val)
>>>>> +{
>>>>> + writel_relaxed(val, offset);
>>>>> +}
>>>>
>>>> I think this is unnecessary and confusing indirection.
>>>> Just use the readl_relaxed/writel_relaxed functions directly in
>>>> the code.
>>>>
>>>
>>> This is just to be flexible.
>>
>> Define exactly what you mean with "flexible" in this context. I
>> only see unnecessary overhead and hard-to-read code.
>
> We have just passed this discussion for watchdog driver
> here: https://lkml.org/lkml/2014/4/1/843
>
> Are you ok with doing it in this way?

No :-)

Subsystem maintainers do not necessarily agree on such issues.

Yours,
Linus Walleij

2014-04-11 06:57:33

by Michal Simek

[permalink] [raw]
Subject: Re: [PATCH 1/2] GPIO: Add driver for Zynq GPIO controller

On 04/10/2014 07:52 PM, Linus Walleij wrote:
> On Wed, Apr 2, 2014 at 7:56 AM, Michal Simek <[email protected]> wrote:
>> On 03/31/2014 10:22 AM, Linus Walleij wrote:
>>> On Sat, Mar 29, 2014 at 5:44 AM, Harini Katakam
>>> <[email protected]> wrote:
>>>> On Sat, Mar 29, 2014 at 3:20 AM, Linus Walleij <[email protected]> wrote:
>>>>> On Thu, Mar 27, 2014 at 4:25 PM, Harini Katakam <[email protected]> wrote:
>>>
>>>>>> +/* Read/Write access to the GPIO PS registers */
>>>>>> +static inline u32 zynq_gpio_readreg(void __iomem *offset)
>>>>>> +{
>>>>>> + return readl_relaxed(offset);
>>>>>> +}
>>>>>> +
>>>>>> +static inline void zynq_gpio_writereg(void __iomem *offset, u32 val)
>>>>>> +{
>>>>>> + writel_relaxed(val, offset);
>>>>>> +}
>>>>>
>>>>> I think this is unnecessary and confusing indirection.
>>>>> Just use the readl_relaxed/writel_relaxed functions directly in
>>>>> the code.
>>>>>
>>>>
>>>> This is just to be flexible.
>>>
>>> Define exactly what you mean with "flexible" in this context. I
>>> only see unnecessary overhead and hard-to-read code.
>>
>> We have just passed this discussion for watchdog driver
>> here: https://lkml.org/lkml/2014/4/1/843
>>
>> Are you ok with doing it in this way?
>
> No :-)
>
> Subsystem maintainers do not necessarily agree on such issues.

I think your sentence is right. :-)
But what to do to convince you to agree with it?
We can use readl/writel directly (or relaxed versions) but it will
just end up that we will have a patch in our xilinx git tree
which won't be in the mainline.

Having central point for IO access functions it not an unused technique.
I was able to find out some cases in drivers/gpio/
gpio-bt8xx.c, gpio-msm-v1.c, gpio-tegra.c, gpio-xilinx.c (almost similar reason
here :-))
and just one in pinctrl-spear.h.
But I have to admit most of gpio/pinmux drivers are using them directly
but on the other hand they are not FPGA based. :-)

BTW: Shouldn't be __raw_ versions replaced by _relaxed?

Thanks,
Michal

--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: http://www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform



Attachments:
signature.asc (263.00 B)
OpenPGP digital signature