Changes between Version 27 and Version 28 of gpio

12/15/2021 08:44:43 PM (9 months ago)
Tim Harvey

updated U-Boot GPIO examples


  • gpio

    v27 v28  
    657657= U-Boot GPIO
    658 The U-Boot bootloader has basic support for processor GPIO's.
     658The U-Boot bootloader has basic support for GPIO's associated with a driver (such as processor GPIO's):
    661  * output logic high:
    662 {{{#!bash
    663 > gpio set 123
    664 }}}
    665  * output logic low:
    666 {{{#!bash
    667 > gpio clr 123
    668 }}}
    669  * show gpio's claimed by drivers:
    670 {{{#!bash
    671 > gpio status
    672 }}}
    673  * show gpio input:
    674 {{{#!bash
    675 > gpio input 123
     661 * Show GPIO's
     663u-boot=> gpio status
     664Bank GPIO1_:
     665GPIO1_0: output: 0 [x] rs485_term.gpio-hog
     666GPIO1_1: input: 0 [x] mipi_gpio4.gpio-hog
     667GPIO1_6: output: 0 [x] pci_usb_sel.gpio-hog
     668GPIO1_7: input: 1 [x] dio0.gpio-hog
     669GPIO1_9: input: 1 [x] dio1.gpio-hog
     671Bank GPIO2_:
     672GPIO2_12: input: 1 [x]
     674Bank GPIO3_:
     675GPIO3_0: output: 0 [x] ethernet@30be0000.phy-reset-gpios
     677Bank GPIO4_:
     678GPIO4_0: output: 0 [x] rs485_en.gpio-hog
     679GPIO4_1: input: 0 [x] mipi_gpio3.gpio-hog
     680GPIO4_2: output: 0 [x] rs485_hd.gpio-hog
     681GPIO4_3: input: 0 [x] mipi_gpio2.gpio-hog
     682GPIO4_4: input: 0 [x] mipi_gpio1.gpio-hog
     683GPIO4_7: output: 1 [x] pci_wdis#.gpio-hog
     685Bank GPIO5_:
     686GPIO5_4: output: 0 [x] led-1.gpios
     687GPIO5_5: output: 0 [x] led-0.gpios
     689 * show status of a particular GPIO (using the gpio id reported above)
     691u-boot=> gpio status GPIO4_7
     692Bank GPIO4_:
     693GPIO4_7: output: 1 [x] pci_wdis#.gpio-hog
     694u-boot=> gpio status GPIO1_7
     695Bank GPIO1_:
     696GPIO1_7: input: 1 [x] dio0.gpio-hog
     699  - above you can see that GPIO4_7 (the 'pci_wdis#' gpio on this board) is an output and currently driven high
     700  - above you can see that GPIO1_7 (the 'dio0' gpio on this board) is an input and its current value is high
     701  - note that a 0 always represents a voltage low and 1 always represents a voltage high regardless of if the gpio is considered 'active high' or 'active low' (which is typically indicated by the GPIO name as active low gpios typically end with a '#')
     702 * set a gpio to output low (clr)
     704u-boot=> gpio clr GPIO4_7   
     705gpio: pin GPIO4_7 (gpio 103) value is 0
     707 * set a gpio to output high (set)
     709u-boot=> gpio set GPIO4_7
     710gpio: pin GPIO4_7 (gpio 103) value is 1
    677712 * toggle gpio:
    679 > gpio toggle 123
    680 }}}
     714u-boot=> gpio toggle GPIO4_7
     715gpio: pin GPIO4_7 (gpio 103) value is 0
     716u-boot=> gpio toggle GPIO4_7
     717gpio: pin GPIO4_7 (gpio 103) value is 1
     720The value specified to the vaious gpio commands can be one of:
     721 - bank name (ie GPIO4_ above) to represent all GPIO's in that bank
     722 - pin name (ie GPIO4_7 above) to represent a specific gpio
     723 - pin number (ie 103) to represent a specific gpio. The pin number notation is not recommended as it depends on GPIO controllers being registered in the same order which may not always be the case. It is always better to refer to the bank and pin name/notation.
     726Note that on some platforms GPIO's can not be read back unless configured a specific way. This is the case on IMX boards where GPIO cells need to have the 'Software Input On' (SION) bit enabled in order to read it back. If you have such as GPIO you can still drive it high but you will get a wraning such as 'Warning: value of pin is still 0'. Additinally the 'toggle' won't function for these GPIO's as the software can't determine what state they are.