mirror of
https://github.com/linux-msm/cdba.git
synced 2026-02-25 13:11:56 -08:00
device: separate backend operations
Separate backend operations into control and console operations. Main idea is that each device has single set of console ops (conmux or console) and at most one way to control it. Each backend driver exports a structure with the set of callbacks. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
This commit is contained in:
@@ -33,13 +33,6 @@
|
||||
#include <yaml.h>
|
||||
|
||||
#include "device.h"
|
||||
#include "alpaca.h"
|
||||
#include "ftdi-gpio.h"
|
||||
#include "cdb_assist.h"
|
||||
#include "conmux.h"
|
||||
#include "console.h"
|
||||
#include "qcomlt_dbg.h"
|
||||
#include "ppps.h"
|
||||
|
||||
#define TOKEN_LENGTH 16384
|
||||
|
||||
@@ -82,6 +75,26 @@ static bool expect(struct device_parser *dp, int type, char *scalar)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void set_control_ops(struct device *dev, const struct control_ops *ops)
|
||||
{
|
||||
if (dev->control_ops) {
|
||||
fprintf(stderr, "device parser: control operations are already selected for %s\n", dev->name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dev->control_ops = ops;
|
||||
}
|
||||
|
||||
static void set_console_ops(struct device *dev, const struct console_ops *ops)
|
||||
{
|
||||
if (dev->console_ops) {
|
||||
fprintf(stderr, "device parser: console operations are already selected for %s\n", dev->name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dev->console_ops = ops;
|
||||
}
|
||||
|
||||
static void parse_board(struct device_parser *dp)
|
||||
{
|
||||
struct device *dev;
|
||||
@@ -121,44 +134,25 @@ static void parse_board(struct device_parser *dp)
|
||||
dev->name = strdup(value);
|
||||
} else if (!strcmp(key, "cdba")) {
|
||||
dev->control_dev = strdup(value);
|
||||
|
||||
dev->open = cdb_assist_open;
|
||||
dev->close = cdb_assist_close;
|
||||
dev->power = cdb_assist_power;
|
||||
dev->print_status = cdb_assist_print_status;
|
||||
dev->usb = cdb_assist_usb;
|
||||
dev->key = cdb_assist_key;
|
||||
set_control_ops(dev, &cdb_assist_ops);
|
||||
} else if (!strcmp(key, "conmux")) {
|
||||
/* conmux handles both control and console */
|
||||
dev->control_dev = strdup(value);
|
||||
|
||||
dev->open = conmux_open;
|
||||
dev->power = conmux_power;
|
||||
dev->write = conmux_write;
|
||||
dev->console_dev = strdup(value);
|
||||
set_control_ops(dev, &conmux_ops);
|
||||
set_console_ops(dev, &conmux_console_ops);
|
||||
} else if (!strcmp(key, "alpaca")) {
|
||||
dev->control_dev = strdup(value);
|
||||
|
||||
dev->open = alpaca_open;
|
||||
dev->power = alpaca_power;
|
||||
dev->usb = alpaca_usb;
|
||||
dev->key = alpaca_key;
|
||||
set_control_ops(dev, &alpaca_ops);
|
||||
} else if (!strcmp(key, "ftdi_gpio")) {
|
||||
dev->control_dev = strdup(value);
|
||||
|
||||
dev->open = ftdi_gpio_open;
|
||||
dev->power = ftdi_gpio_power;
|
||||
dev->usb = ftdi_gpio_usb;
|
||||
dev->key = ftdi_gpio_key;
|
||||
set_control_ops(dev, &ftdi_gpio_ops);
|
||||
} else if (!strcmp(key, "qcomlt_debug_board")) {
|
||||
dev->control_dev = strdup(value);
|
||||
|
||||
dev->open = qcomlt_dbg_open;
|
||||
dev->power = qcomlt_dbg_power;
|
||||
dev->usb = qcomlt_dbg_usb;
|
||||
dev->key = qcomlt_dbg_key;
|
||||
set_control_ops(dev, &qcomlt_dbg_ops);
|
||||
} else if (!strcmp(key, "console")) {
|
||||
dev->console_dev = strdup(value);
|
||||
dev->write = console_write;
|
||||
dev->send_break = console_send_break;
|
||||
set_console_ops(dev, &console_ops);
|
||||
} else if (!strcmp(key, "voltage")) {
|
||||
dev->voltage = strtoul(value, NULL, 10);
|
||||
} else if (!strcmp(key, "fastboot")) {
|
||||
@@ -188,7 +182,7 @@ static void parse_board(struct device_parser *dp)
|
||||
}
|
||||
}
|
||||
|
||||
if (!dev->board || !dev->serial || !(dev->open || dev->console_dev)) {
|
||||
if (!dev->board || !dev->serial || !dev->console_dev) {
|
||||
fprintf(stderr, "device parser: insufficiently defined device\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user