mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-28 23:03:24 +02:00
src: gpio: small cleanups following the port to libgpiod 2.x
This commit is contained in:
64
src/gpio.c
64
src/gpio.c
@@ -42,28 +42,26 @@ static char *gpio_in_names[] = {
|
||||
"status",
|
||||
};
|
||||
|
||||
int gpio_line_get_value(struct EG25Manager *manager, int line) {
|
||||
enum gpiod_line_value gpio_line_get_value(struct EG25Manager *manager, int line) {
|
||||
enum gpiod_line_value value;
|
||||
value = gpiod_line_request_get_value(manager->gpio_in[line], manager->gpio_in_offset[line]);
|
||||
unsigned int offset;
|
||||
|
||||
switch (value) {
|
||||
case GPIOD_LINE_VALUE_ACTIVE:
|
||||
return 1;
|
||||
case GPIOD_LINE_VALUE_INACTIVE:
|
||||
return 0;
|
||||
case GPIOD_LINE_VALUE_ERROR:
|
||||
gpiod_line_request_get_requested_offsets(manager->gpio_in[line], &offset, 1);
|
||||
value = gpiod_line_request_get_value(manager->gpio_in[line], offset);
|
||||
|
||||
if (value == GPIOD_LINE_VALUE_ERROR) {
|
||||
g_warning("gpio: couldn't get value on line %d", line);
|
||||
}
|
||||
|
||||
return -1;
|
||||
return value;
|
||||
}
|
||||
|
||||
int gpio_line_set_value(struct EG25Manager *manager, int line, int value) {
|
||||
enum gpiod_line_value line_value = value ? GPIOD_LINE_VALUE_ACTIVE : GPIOD_LINE_VALUE_INACTIVE;
|
||||
int gpio_line_set_value(struct EG25Manager *manager, int line, enum gpiod_line_value value) {
|
||||
unsigned int offset;
|
||||
int ret;
|
||||
|
||||
ret = gpiod_line_request_set_value(manager->gpio_out[line], manager->gpio_out_offset[line], line_value);
|
||||
|
||||
gpiod_line_request_get_requested_offsets(manager->gpio_out[line], &offset, 1);
|
||||
ret = gpiod_line_request_set_value(manager->gpio_out[line], offset, value);
|
||||
if (ret) {
|
||||
g_warning("gpio: couldn't set value %d on line %d", value, line);
|
||||
return -1;
|
||||
@@ -76,9 +74,9 @@ int gpio_line_set_value(struct EG25Manager *manager, int line, int value) {
|
||||
|
||||
int gpio_sequence_poweron(struct EG25Manager *manager)
|
||||
{
|
||||
gpio_line_set_value(manager, GPIO_OUT_PWRKEY, 1);
|
||||
gpio_line_set_value(manager, GPIO_OUT_PWRKEY, GPIOD_LINE_VALUE_ACTIVE);
|
||||
sleep(1);
|
||||
gpio_line_set_value(manager, GPIO_OUT_PWRKEY, 0);
|
||||
gpio_line_set_value(manager, GPIO_OUT_PWRKEY, GPIOD_LINE_VALUE_INACTIVE);
|
||||
|
||||
g_message("Executed power-on/off sequence");
|
||||
|
||||
@@ -87,7 +85,7 @@ int gpio_sequence_poweron(struct EG25Manager *manager)
|
||||
|
||||
int gpio_sequence_shutdown(struct EG25Manager *manager)
|
||||
{
|
||||
gpio_line_set_value(manager, GPIO_OUT_DISABLE, 1);
|
||||
gpio_line_set_value(manager, GPIO_OUT_DISABLE, GPIOD_LINE_VALUE_ACTIVE);
|
||||
gpio_sequence_poweron(manager);
|
||||
|
||||
g_message("Executed power-off sequence");
|
||||
@@ -97,7 +95,7 @@ int gpio_sequence_shutdown(struct EG25Manager *manager)
|
||||
|
||||
int gpio_sequence_suspend(struct EG25Manager *manager)
|
||||
{
|
||||
gpio_line_set_value(manager, GPIO_OUT_APREADY, 1);
|
||||
gpio_line_set_value(manager, GPIO_OUT_APREADY, GPIOD_LINE_VALUE_ACTIVE);
|
||||
|
||||
g_message("Executed suspend sequence");
|
||||
|
||||
@@ -106,7 +104,7 @@ int gpio_sequence_suspend(struct EG25Manager *manager)
|
||||
|
||||
int gpio_sequence_resume(struct EG25Manager *manager)
|
||||
{
|
||||
gpio_line_set_value(manager, GPIO_OUT_APREADY, 0);
|
||||
gpio_line_set_value(manager, GPIO_OUT_APREADY, GPIOD_LINE_VALUE_INACTIVE);
|
||||
|
||||
g_message("Executed resume sequence");
|
||||
|
||||
@@ -116,7 +114,7 @@ int gpio_sequence_resume(struct EG25Manager *manager)
|
||||
int gpio_sequence_wake(struct EG25Manager *manager)
|
||||
{
|
||||
if (manager->gpio_out_value[GPIO_OUT_DTR]) {
|
||||
gpio_line_set_value(manager, GPIO_OUT_DTR, 0);
|
||||
gpio_line_set_value(manager, GPIO_OUT_DTR, GPIOD_LINE_VALUE_INACTIVE);
|
||||
|
||||
/* Give the modem 200ms to wake from soft sleep */
|
||||
usleep(200000);
|
||||
@@ -129,7 +127,7 @@ int gpio_sequence_wake(struct EG25Manager *manager)
|
||||
|
||||
int gpio_sequence_sleep(struct EG25Manager *manager)
|
||||
{
|
||||
gpio_line_set_value(manager, GPIO_OUT_DTR, 1);
|
||||
gpio_line_set_value(manager, GPIO_OUT_DTR, GPIOD_LINE_VALUE_ACTIVE);
|
||||
g_message("Executed soft sleep sequence");
|
||||
|
||||
return 0;
|
||||
@@ -175,16 +173,6 @@ free_settings:
|
||||
return request;
|
||||
}
|
||||
|
||||
struct gpiod_line_request *gpio_request_output_line(struct EG25Manager *manager, int chip, unsigned int line)
|
||||
{
|
||||
return gpio_request_line(manager, chip, line, GPIOD_LINE_DIRECTION_OUTPUT);
|
||||
}
|
||||
|
||||
struct gpiod_line_request *gpio_request_input_line(struct EG25Manager *manager, int chip, unsigned int line)
|
||||
{
|
||||
return gpio_request_line(manager, chip, line, GPIOD_LINE_DIRECTION_INPUT);
|
||||
}
|
||||
|
||||
static int gpio_chip_dir_filter(const struct dirent *entry)
|
||||
{
|
||||
struct stat sb;
|
||||
@@ -340,10 +328,9 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
|
||||
if (!line.ok || line.u.i < 0 || line.u.i > gpio_chip_num_lines(manager, chip.u.i))
|
||||
g_error("Wrong line ID for output GPIO '%s'", gpio_out_names[i]);
|
||||
|
||||
manager->gpio_out[i] = gpio_request_output_line(manager, chip.u.i, line.u.i);
|
||||
manager->gpio_out[i] = gpio_request_line(manager, chip.u.i, line.u.i, GPIOD_LINE_DIRECTION_OUTPUT);
|
||||
if (!manager->gpio_out[i])
|
||||
g_error("Unable to get output GPIO %d", i);
|
||||
manager->gpio_out_offset[i] = line.u.i;
|
||||
}
|
||||
|
||||
for (i = 0; i < GPIO_IN_COUNT; i++) {
|
||||
@@ -365,10 +352,9 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
|
||||
if (!line.ok || line.u.i < 0 || line.u.i > gpio_chip_num_lines(manager, chip.u.i))
|
||||
g_error("Wrong line ID for input GPIO '%s'", gpio_in_names[i]);
|
||||
|
||||
manager->gpio_in[i] = gpio_request_input_line(manager, chip.u.i, line.u.i);
|
||||
manager->gpio_in[i] = gpio_request_line(manager, chip.u.i, line.u.i, GPIOD_LINE_DIRECTION_INPUT);
|
||||
if (!manager->gpio_in[i])
|
||||
g_error("Unable to get input GPIO %d", i);
|
||||
manager->gpio_in_offset[i] = line.u.i;
|
||||
}
|
||||
} else {
|
||||
guint offset, chipidx, gpio_idx;
|
||||
@@ -394,10 +380,9 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
|
||||
chipidx = 1;
|
||||
}
|
||||
|
||||
manager->gpio_out[i] = gpio_request_input_line(manager, chipidx, offset);
|
||||
manager->gpio_out[i] = gpio_request_line(manager, chipidx, offset, GPIOD_LINE_DIRECTION_OUTPUT);
|
||||
if (!manager->gpio_out[i])
|
||||
g_error("Unable to get output GPIO %d", i);
|
||||
manager->gpio_out_offset[i] = offset;
|
||||
}
|
||||
|
||||
for (i = 0; i < GPIO_IN_COUNT; i++) {
|
||||
@@ -412,10 +397,9 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
|
||||
chipidx = 1;
|
||||
}
|
||||
|
||||
manager->gpio_in[i] = gpio_request_input_line(manager, chipidx, offset);
|
||||
manager->gpio_in[i] = gpio_request_line(manager, chipidx, offset, GPIOD_LINE_DIRECTION_INPUT);
|
||||
if (!manager->gpio_in[i])
|
||||
g_error("Unable to get input GPIO %d", i);
|
||||
manager->gpio_in_offset[i] = offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,11 +409,11 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
|
||||
gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down)
|
||||
{
|
||||
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
||||
gpio_line_get_value(manager, GPIO_IN_STATUS) == 1) {
|
||||
gpio_line_get_value(manager, GPIO_IN_STATUS) == GPIOD_LINE_VALUE_ACTIVE) {
|
||||
|
||||
if (keep_down && manager->gpio_out[GPIO_OUT_RESET]) {
|
||||
// Asserting RESET line to prevent modem from rebooting
|
||||
gpio_line_set_value(manager, GPIO_OUT_RESET, 1);
|
||||
gpio_line_set_value(manager, GPIO_OUT_RESET, GPIOD_LINE_VALUE_ACTIVE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@@ -118,9 +118,7 @@ struct EG25Manager {
|
||||
struct gpiod_chip *gpiochip[2];
|
||||
struct gpiod_line_request *gpio_out[5];
|
||||
guint gpio_out_value[5];
|
||||
guint gpio_out_offset[5];
|
||||
struct gpiod_line_request *gpio_in[2];
|
||||
guint gpio_in_offset[5];
|
||||
};
|
||||
|
||||
void modem_configure(struct EG25Manager *data);
|
||||
|
Reference in New Issue
Block a user