Skip to content

Commit

Permalink
Support GPIO Physical Presence Detect Devices
Browse files Browse the repository at this point in the history
This commit makes the necessary changes to support the GPIO devices
used for physical presence detection:
- New attribute GPIO_INFO_PHYS_PRES
- Enable GPIO Device Driver by default
- GPIO Device Driver updated to support new device type
- Added new GPIO PCA9551 layer to sit on top of GPIO Device Driver

Change-Id: I952007503eb5d9fe873adea2eaaeccff21ae18a6
RTC:211220
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/84655
Reviewed-by: Ilya Smirnov <ismirno@us.ibm.com>
Reviewed-by: Christopher J Engel <cjengel@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Nicholas E Bofferding <bofferdn@us.ibm.com>
  • Loading branch information
mabaiocchi authored and Nicholas E Bofferding committed Nov 14, 2019
1 parent 0247cc5 commit eace166
Show file tree
Hide file tree
Showing 8 changed files with 592 additions and 20 deletions.
10 changes: 8 additions & 2 deletions src/include/usr/gpio/gpioddreasoncodes.H
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2014 */
/* Contributors Listed Below - COPYRIGHT 2014,2019 */
/* [+] Google Inc. */
/* [+] International Business Machines Corp. */
/* */
Expand Down Expand Up @@ -40,17 +40,23 @@ namespace GPIO
GPIO_READ = 0x01,
GPIO_WRITE = 0x02,
GPIO_READATTRIBUTES = 0x03,

// Use 0x10-0x1F range for PCA9551 functions
GPIO_PCA9551_SET_LED = 0x10,
};

/**
* @enum grioReasonCode
* @enum gpioReasonCode
*/
enum gpioReasonCode
{
GPIO_INVALID_DEVICE_TYPE = GPIO_COMP_ID | 0x00,
GPIO_ATTR_INFO_NOT_FOUND = GPIO_COMP_ID | 0x01,
GPIO_I2C_TARGET_NOT_FOUND = GPIO_COMP_ID | 0x02,
GPIO_INVALID_OP = GPIO_COMP_ID | 0x03,

// Use 0x10-0x1F range for PCA9551 functions
GPIO_PCA9551_DATA_MISMATCH = GPIO_COMP_ID | 0x10,
};

};
Expand Down
121 changes: 119 additions & 2 deletions src/include/usr/gpio/gpioif.H
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2014 */
/* Contributors Listed Below - COPYRIGHT 2014,2019 */
/* [+] Google Inc. */
/* [+] International Business Machines Corp. */
/* */
Expand All @@ -26,17 +26,134 @@
#ifndef __GPIOIF_H
#define __GPIOIF_H

#include <errl/errlentry.H>

namespace GPIO
{
/**
* @brief Devices to be accessed
*/
enum gpioDevice_t
{
PCA95X_GPIO = 0,
// Corresponds to attribute ...
PCA95X_GPIO = 0, // GPIO_INFO
PCA9551_GPIO_PHYS_PRES = 1, // GPIO_INFO_PHYS_PRES
INVALID_GPIO,
};


/* The following enums and interfaces are specific to PCA9551 GPIO Devices.
* Documentation here: https://www.nxp.com/docs/en/data-sheet/PCA9551.pdf
*/

/**
* @brief Specific to PCA9551: LED Bit Mask to match how their status is read
* back from LED "INPUT" register on PCA9551 Devices
*/
enum PCA9551_LEDS_t : uint8_t
{
PCA9551_LED0 = 0x01,
PCA9551_LED1 = 0x02,
PCA9551_LED2 = 0x04,
PCA9551_LED3 = 0x08,
PCA9551_LED4 = 0x10,
PCA9551_LED5 = 0x20,
PCA9551_LED6 = 0x40,
PCA9551_LED7 = 0x80,
};

/**
* @brief Specific to PCA9551: Values used by the LED select registers
* to determine the source of the LED data.
*/
enum PCA9551_LED_Output_Settings_t : uint8_t
{
PCA9551_OUTPUT_LOW = 0x00, // LED on
PCA9551_OUTPUT_HIGH_IMPEDANCE = 0x01, // LED off; default
PCA9551_OUTPUT_PWM0 = 0x02, // Output blinks at PWM0 rate
PCA9551_OUTPUT_PWM1 = 0x03, // Output blinks at PWM1 rate
};

/**
* @brief Specific to PCA9551: Control register definition:
sepcificies which register the operation will target
*/
enum PCA9551_Registers_t : uint8_t
{
PCA9551_REGISTER_INPUT = 0x00, // INPUT (read only) input register
PCA9551_REGISTER_PCS0 = 0x01, // PSC0 (r/w) frequency prescaler 0
PCA9551_REGISTER_PWM0 = 0x02, // PWM0 (r/w) PWM register 0
PCA9551_REGISTER_PCS1 = 0x03, // PSC1 (r/w) frequency prescaler 1
PCA9551_REGISTER_PWM1 = 0x04, // PWM1 (r/w) PWM register 1
PCA9551_REGISTER_LS0 = 0x05, // LS0 (r/w) LED0 to LED3 selector
PCA9551_REGISTER_LS1 = 0x06, // LS1 (r/w) LED4 to LED7 selector
};

/**
* @brief Specific to PCA9551: Helper constants to work with the bits in the
* PCA9551 registers
*/
enum PCA9551_Constants_t : uint8_t
{
// Mask shifted to apply 2-bit settings to a specific LED in the output
// settings register
PCA9551_LED_SETTINGS_MASK = 0x03,

// Amount to shift the LED value per LED when walking through the LEDs
// in the INPUT register (related to PCA9551_LEDS_t above)
PCA9551_LED_SHIFT_AMOUNT = 0x01,

// Amount to shift the LED Settings MASK per LED when walking through the
// LEDs in the output settings register (ie, 2 bits at a time)
PCA9551_LED_SETTINGS_MASK_SHIFT_AMOUNT = 0x02,

// LED Divider: While the INPUT register can contain all 8 LED values
// (since each value is represented by one bit), the SETTINGS registers
// (PCA9551_REGISTER_LS0 and PCA9551_REGISTER_LS1) can only cover 4 LEDs
// each since each setting requires 2 bits.
// This divisor takes LEDs 4 to 7 and makes them look like LEDs 0 to 3
PCA9551_LED_SETTINGS_DIVISOR = 0x80,
};

/**
* @brief Returns the PCA9551 Device's INPUT register which reflects the state
* of the device's LEDs (aka pins)
*
* @param[in] i_target - Target that contains ATTR_GPIO_INFO_PHYS_PRES attribute
* to run the commands against
*
* @param[out] o_led_data - The INPUT register data from the device
*
* @return errlHndl_t nullptr on success; non-nullptr on error.
*/
errlHndl_t gpioPca9551GetLeds(TARGETING::Target * i_target,
uint8_t & o_led_data);

/**
* @brief Sets the given LED (aka pin) of a PCA9551 Device to a certain setting
* and returns the INPUT register which reflects the state of device's
* LEDs (aka pins) after the setting has been run
*
* @param[in] i_target - Target that contains ATTR_GPIO_INFO_PHYS_PRES attribute
* to run the commands against
*
* @param[in] i_led - The specific LED Target that contains ATTR_GPIO_INFO_PHYS_PRES attribute
* to run the commands against
*
* @param[in] i_setting - the output setting to set the LED to
*
* @param[out] o_led_data - The INPUT register data from the device after the
* 'set' procedure has been run allowing the caller to
* evaluate if the set actually went through
*
* @return errlHndl_t nullptr on success; non-nullptr on error.
*/

errlHndl_t gpioPca9551SetLed(TARGETING::Target * i_target,
const PCA9551_LEDS_t i_led,
const PCA9551_LED_Output_Settings_t i_setting,
uint8_t & o_led_data);


}; // GPIO NAMESPACE
#endif
2 changes: 1 addition & 1 deletion src/usr/gpio/HBconfig
@@ -1,4 +1,4 @@
config GPIODD
default n
default y
help
Enable GPIO device driver support

0 comments on commit eace166

Please sign in to comment.