[flashrom] [PATCH 1/7] add lpt_io module - generic LPT functions

Maksim Kuleshov mmcx at mail.ru
Sun Mar 31 17:05:57 CEST 2013


>From 7237cc639dffe325167cca9909f270aa67afbe68 Mon Sep 17 00:00:00 2001
From: Maksim Kuleshov <mmcx at mail.ru>
Date: Sat, 30 Mar 2013 21:23:23 +0400
Subject: [PATCH 1/7] add lpt_io module  - generic LPT functions

Signed-off-by: Maksim Kuleshov <mmcx at mail.ru>
---
 lpt_io.c |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lpt_io.h |   14 +++++++++
 2 files changed, 120 insertions(+)
 create mode 100644 lpt_io.c
 create mode 100644 lpt_io.h

diff --git a/lpt_io.c b/lpt_io.c
new file mode 100644
index 0000000..638f6e9
--- /dev/null
+++ b/lpt_io.c
@@ -0,0 +1,106 @@
+#include <stdint.h>
+#include <string.h>
+#include "lpt_io.h"
+#include "programmer.h"
+
+struct lpt_io_driver {
+	const char *method;
+	int (*init) (lpt_io_context_t * p_context, void *data);
+	void (*out_data) (lpt_io_context_t context, uint8_t data);
+	void (*out_control) (lpt_io_context_t context, uint8_t data);
+	 uint8_t(*in_data) (lpt_io_context_t context);
+	 uint8_t(*in_status) (lpt_io_context_t context);
+	 uint8_t(*in_control) (lpt_io_context_t context);
+	int (*shutdown) (void *data);
+	void *private;
+};
+
+static struct lpt_io_driver *lpt_io_drivers[] = {
+	NULL
+};
+
+int lpt_io_init(lpt_io_context_t * p_context, const char *method,
+		void *method_args)
+{
+	struct lpt_io_driver **p_driver = lpt_io_drivers;
+
+	for (; *p_driver; p_driver++) {
+		if (0 == strcmp((*p_driver)->method, method)) {
+			int err = 0;
+
+			if ((*p_driver)->init) {
+				err =
+				    (*p_driver)->init((void **)p_driver,
+						      method_args);
+			}
+
+			if (err) {
+				return err;
+			}
+
+			*p_context = *p_driver;
+			return 0;
+		}
+	}
+
+	msg_perr("Error: lpt_io_method \"%s\" not supported\n", method);
+	return 1;
+}
+
+#define LPT_PORT_CONTROL_INTERNAL_INVERSION_MASK 0x0B
+#define LPT_PORT_STATUS_INTERNAL_INVERSION_MASK 0x80
+
+void lpt_io_out_data(lpt_io_context_t context, uint8_t data)
+{
+	struct lpt_io_driver *driver = context;
+
+	if (driver && driver->out_data) {
+		driver->out_data(context, data);
+	}
+}
+
+void lpt_io_out_control(lpt_io_context_t context, uint8_t data)
+{
+	data ^= LPT_PORT_CONTROL_INTERNAL_INVERSION_MASK;
+	struct lpt_io_driver *driver = context;
+
+	if (driver && driver->out_control) {
+		driver->out_control(context, data);
+	}
+}
+
+uint8_t lpt_io_in_data(lpt_io_context_t context)
+{
+	uint8_t data = 0;
+	struct lpt_io_driver *driver = context;
+
+	if (driver && driver->in_data) {
+		data = driver->in_data(context);
+	}
+
+	return data;
+}
+
+uint8_t lpt_io_in_status(lpt_io_context_t context)
+{
+	uint8_t data = 0;
+	struct lpt_io_driver *driver = context;
+
+	if (driver && driver->in_status) {
+		data = driver->in_status(context);
+	}
+
+	return data ^ LPT_PORT_STATUS_INTERNAL_INVERSION_MASK;
+}
+
+uint8_t lpt_io_in_control(lpt_io_context_t context)
+{
+	uint8_t data = 0;
+	struct lpt_io_driver *driver = context;
+
+	if (driver && driver->in_control) {
+		data = driver->in_control(context);
+	}
+
+	return data ^ LPT_PORT_CONTROL_INTERNAL_INVERSION_MASK;
+}
diff --git a/lpt_io.h b/lpt_io.h
new file mode 100644
index 0000000..a4912e8
--- /dev/null
+++ b/lpt_io.h
@@ -0,0 +1,14 @@
+#ifndef lpt_io_h_included_
+#define lpt_io_h_included_
+
+typedef void *lpt_io_context_t;
+
+int lpt_io_init(lpt_io_context_t * p_context, const char *method,
+		void *method_args);
+void lpt_io_out_data(lpt_io_context_t context, uint8_t data);
+void lpt_io_out_control(lpt_io_context_t context, uint8_t data);
+uint8_t lpt_io_in_data(lpt_io_context_t context);
+uint8_t lpt_io_in_status(lpt_io_context_t context);
+uint8_t lpt_io_in_control(lpt_io_context_t context);
+
+#endif
-- 
1.7.10.4





More information about the flashrom mailing list