How to set GPIOs to pre-defined value

Brad Chou chou.brad at gmail.com
Thu May 9 17:42:14 AEST 2019


> On May 8, 2019, at 9:53 AM, Andrew Jeffery <andrew at aj.id.au <mailto:andrew at aj.id.au>> wrote:
> 
> 
> 
> On Tue, 7 May 2019, at 18:23, Brad Chou wrote:
>> Hi Samuel,
>> Thanks for your reply, I am using AST2500.
>> I tried add gpio-hog settings into my device tree, and yes, the GPIO 
>> works as it defined.
>> But all GPIOs defined by gpio-hog can not be modified in user space by 
>> gpioset / gpioget utility.
>> I need to set all GPIOs to pre-defined state and can change it at run 
>> time.
>> Set GPIOs in Device tree is trying to lock it by a fixed direction and 
>> value.
>> 
> 
> This problem is probably best taken up with upstream. Currently GPIO
> nodes in the devicetree are ignored if they do not have the `gpio-hog`
> property:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpio/gpiolib-of.c?h=v5.1#n454 <https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpio/gpiolib-of.c?h=v5.1#n454>
> 
> Changing that might be a hard argument - it may impact existing
> devicetrees that expect the current behaviour.
> 
> However, I'm interested in what you see wrong with doing this from
> userspace? What requirements do you have that would need this to
> be done in the kernel?
> 
> Cheers,
> 
> Andrew

I don’t really need it to be set in the kernel.
Just curious about how openBMC initial all GPIOs, especially for AST2500 that has over 200+ GPIOs.
And gpio-hog meaning - to take or use a lot of something in a way that prevents other people from having this gpio.
So no one can operate it after set gpio-hog.
Any userspace operations just got an error similar to this, assume you hog gpio 35 in the kernel :
gpioget gpiochip0 35
gpioget: error reading GPIO values: Device or resource busy


> On May 8, 2019, at 6:32 PM, Samuel Jiang <chyishian.jiang at gmail.com> wrote:
> 
> Hi Brad,
> On May 7, 2019, 4:52 PM +0800, Brad Chou <chou.brad at gmail.com>, wrote:
>> Hi Samuel,
>> Thanks for your reply, I am using AST2500.
>> I tried add gpio-hog settings into my device tree, and yes, the GPIO works as it defined.
>> But all GPIOs defined by gpio-hog can not be modified in user space by gpioset / gpioget utility.
>> I need to set all GPIOs to pre-defined state and can change it at run time.
>> Set GPIOs in Device tree is trying to lock it by a fixed direction and value.
>> 
>> Thanks.
> 
> You could trace the gpioplus library how does it implement control pins, it seems direct modify by gpio chips.

Since openBMC has no individual recipes to do GPIO initial.
Gpioplus is the preferred way to control GPIOs.
Thanks.

> 
>> Now, I am using a shell script with gpioset utility to do the job.
>> But I know using shell to do it is a bad idea.
>> Does anyone have better ideas ? 
> 
> 
> In my situation, I still use shell script export pin which didn't pre-define output high or low and control GPIOs program by c++ at runtime.
> But I think the previous shell script also could rewrite to c++.
> 
> 
> Thanks,
> Samuel Jiang
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20190509/e4f427ae/attachment.htm>


More information about the openbmc mailing list