skeleton: Use ioctl gpio handling
Now that chassiskill is a standalone app and is
using ioctl gpio handling (through the gpioplus library),
the gpio libraries here need to use ioctl as well for
chassiskill to be compatible.
Tested: Verified chassiskill works as intended and checked
that nothing else broke.
Change-Id: I67c431027d31e87c332c3e1771fc2d3423f56652
Signed-off-by: Anthony Wilson <wilsonan@us.ibm.com>
diff --git a/op-pwrctl/power_control_obj.c b/op-pwrctl/power_control_obj.c
index dedcbe2..ada9b3b 100644
--- a/op-pwrctl/power_control_obj.c
+++ b/op-pwrctl/power_control_obj.c
@@ -52,8 +52,9 @@
}
uint8_t pgood_state;
- int rc = gpio_open(&g_gpio_configs.power_gpio.power_good_in);
+ int rc = gpio_open(&g_gpio_configs.power_gpio.power_good_in, 0);
if(rc != GPIO_OK) {
+ gpio_close(&g_gpio_configs.power_gpio.power_good_in);
g_print("ERROR PowerControl: GPIO open error (gpio=%s,rc=%d)\n",
g_gpio_configs.power_gpio.power_good_in.name, rc);
return FALSE;
@@ -81,15 +82,16 @@
for(i = 0; i < g_gpio_configs.power_gpio.num_reset_outs; i++)
{
GPIO *reset_out = &g_gpio_configs.power_gpio.reset_outs[i];
- rc = gpio_open(reset_out);
+ reset_state = pgood_state ^ g_gpio_configs.power_gpio.reset_pols[i];
+ rc = gpio_open(reset_out, reset_state);
if(rc != GPIO_OK)
{
+ gpio_close(reset_out);
g_print("ERROR PowerControl: GPIO open error (gpio=%s,rc=%d)\n",
reset_out->name, rc);
continue;
}
- reset_state = pgood_state ^ g_gpio_configs.power_gpio.reset_pols[i];
g_print("PowerControl: pgood: %d, setting reset %s to %d\n",
(int)pgood_state, reset_out->name, (int)reset_state);
gpio_write(reset_out, reset_state);
@@ -111,15 +113,16 @@
continue;
}
}
- rc = gpio_open(pci_reset_out);
+ reset_state = pgood_state ^ g_gpio_configs.power_gpio.pci_reset_pols[i];
+ rc = gpio_open(pci_reset_out, reset_state);
if(rc != GPIO_OK)
{
+ gpio_close(pci_reset_out);
g_print("ERROR PowerControl: GPIO open error (gpio=%s,rc=%d)\n",
pci_reset_out->name, rc);
continue;
}
- reset_state = pgood_state ^ g_gpio_configs.power_gpio.pci_reset_pols[i];
g_print("PowerControl: pgood: %d, setting pci reset %s to %d\n",
(int)pgood_state, pci_reset_out->name, (int)reset_state);
gpio_write(pci_reset_out, reset_state);
@@ -202,9 +205,10 @@
if (ignore)
return;
- rc = gpio_open(&g_gpio_configs.power_gpio.power_good_in);
+ rc = gpio_open(&g_gpio_configs.power_gpio.power_good_in, 0);
if(rc != GPIO_OK)
{
+ gpio_close(&g_gpio_configs.power_gpio.power_good_in);
g_print("ERROR PowerControl: on_boot_progress(): GPIO open error (gpio=%s,rc=%d)\n",
g_gpio_configs.power_gpio.power_good_in.name, rc);
return;
@@ -220,15 +224,16 @@
if(!g_gpio_configs.power_gpio.pci_reset_holds[i])
continue;
- rc = gpio_open(pci_reset_out);
+ reset_state = pgood_state ^ g_gpio_configs.power_gpio.pci_reset_pols[i];
+ rc = gpio_open(pci_reset_out, reset_state);
if(rc != GPIO_OK)
{
+ gpio_close(pci_reset_out);
g_print("ERROR PowerControl: GPIO open error (gpio=%s,rc=%d)\n",
pci_reset_out->name, rc);
continue;
}
- reset_state = pgood_state ^ g_gpio_configs.power_gpio.pci_reset_pols[i];
g_print("PowerControl: pgood: %d, setting pci reset %s to %d\n",
(int)pgood_state, pci_reset_out->name, (int)reset_state);
gpio_write(pci_reset_out, reset_state);
@@ -267,17 +272,19 @@
uint8_t power_up_out;
for (i = 0; i < power_gpio->num_power_up_outs; i++) {
GPIO *power_pin = &power_gpio->power_up_outs[i];
- error = gpio_open(power_pin);
+ power_up_out = state ^ !power_gpio->power_up_pols[i];
+ error = gpio_open(power_pin, power_up_out);
if(error != GPIO_OK) {
+ gpio_close(power_pin);
g_print("ERROR PowerControl: GPIO open error (gpio=%s,rc=%d)\n",
power_gpio->power_up_outs[i].name, error);
continue;
}
- power_up_out = state ^ !power_gpio->power_up_pols[i];
g_print("PowerControl: setting power up %s to %d\n",
power_gpio->power_up_outs[i].name, (int)power_up_out);
error = gpio_write(power_pin, power_up_out);
if(error != GPIO_OK) {
+ gpio_close(power_pin);
continue;
}
gpio_close(power_pin);
@@ -294,16 +301,17 @@
* power pins' states. This commits the changes to the latch states. */
if (power_gpio->latch_out.name != NULL) {
int rc;
- uint8_t latch_value = 0;
- rc = gpio_open(&power_gpio->latch_out);
+ uint8_t latch_value = 1;
+ rc = gpio_open(&power_gpio->latch_out, latch_value);
if (rc != GPIO_OK) {
/* Failures are non-fatal. */
+ gpio_close(&power_gpio->latch_out);
g_print("PowerControl ERROR failed to open latch %s rc=%d\n",
power_gpio->latch_out.name, rc);
return TRUE;
}
/* Make the latch transparent for as brief of a time as possible. */
- rc = gpio_write(&power_gpio->latch_out, 1);
+ rc = gpio_write(&power_gpio->latch_out, latch_value--);
if (rc != GPIO_OK) {
g_print("PowerControl ERROR failed to assert latch %s rc=%d\n",
power_gpio->latch_out.name, rc);
@@ -311,7 +319,7 @@
g_print("PowerControl asserted latch %s\n",
power_gpio->latch_out.name);
}
- rc = gpio_write(&power_gpio->latch_out, 0);
+ rc = gpio_write(&power_gpio->latch_out, latch_value);
if (rc != GPIO_OK) {
g_print("PowerControl ERROR failed to clear latch %s rc=%d\n",
power_gpio->latch_out.name, rc);
@@ -355,29 +363,29 @@
// get gpio device paths
if(power_gpio->latch_out.name != NULL) { /* latch is optional */
- rc = gpio_init(&power_gpio->latch_out);
+ rc = gpio_get_params(&power_gpio->latch_out);
if(rc != GPIO_OK) {
error = rc;
}
}
- rc = gpio_init(&power_gpio->power_good_in);
+ rc = gpio_get_params(&power_gpio->power_good_in);
if(rc != GPIO_OK) {
error = rc;
}
for(int i = 0; i < power_gpio->num_power_up_outs; i++) {
- rc = gpio_init(&power_gpio->power_up_outs[i]);
+ rc = gpio_get_params(&power_gpio->power_up_outs[i]);
if(rc != GPIO_OK) {
error = rc;
}
}
for(int i = 0; i < power_gpio->num_reset_outs; i++) {
- rc = gpio_init(&power_gpio->reset_outs[i]);
+ rc = gpio_get_params(&power_gpio->reset_outs[i]);
if(rc != GPIO_OK) {
error = rc;
}
}
for(int i = 0; i < power_gpio->num_pci_reset_outs; i++) {
- rc = gpio_init(&power_gpio->pci_reset_outs[i]);
+ rc = gpio_get_params(&power_gpio->pci_reset_outs[i]);
if(rc != GPIO_OK) {
error = rc;
}
@@ -385,12 +393,14 @@
gpio_inits_done();
- rc = gpio_open(&power_gpio->power_good_in);
+ rc = gpio_open(&power_gpio->power_good_in, 0);
if(rc != GPIO_OK) {
+ gpio_close(&power_gpio->power_good_in);
return rc;
}
rc = gpio_read(&power_gpio->power_good_in, &pgood_state);
if(rc != GPIO_OK) {
+ gpio_close(&power_gpio->power_good_in);
return rc;
}
gpio_close(&power_gpio->power_good_in);