summaryrefslogtreecommitdiff
path: root/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'bus.c')
-rw-r--r--bus.c70
1 files changed, 41 insertions, 29 deletions
diff --git a/bus.c b/bus.c
index 2bebb57..6b2488b 100644
--- a/bus.c
+++ b/bus.c
@@ -89,7 +89,7 @@ static void pinmux_configurepin(char* pin, int option, int mode)
snprintf(path, sizeof(path), "/sys/kernel/debug/omap_mux/%s", pin);
FILE* node = fopen(path, "w");
if (node != NULL) {
- fprintf(node, "0x%02x\n", (((option << 4) | mode) & 0xff));
+ fprintf(node, "0x%02x\n", (((option << 3) | mode) & 0xff));
fclose(node);
} else {
printf("Failed to configure pin %s (%s)\n", pin, path);
@@ -168,14 +168,14 @@ static void gpmc_setup(int chipselect, int accesscycles, int size, bool enablecs
pinmux_configurepin("gpmc_oen_ren", 0x0, 0x0);
pinmux_configurepin("gpmc_wen", 0x0, 0x0);
- pinmux_configurepin("gpmc_ad7", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad6", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad5", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad4", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad3", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad2", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad1", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad0", 0x3, 0x0);
+ pinmux_configurepin("gpmc_ad7", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad6", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad5", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad4", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad3", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad2", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad1", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad0", 0x6, 0x0);
pinmux_configurepin("lcd_data0", 0x0, 0x1);
pinmux_configurepin("lcd_data1", 0x0, 0x1);
@@ -211,11 +211,11 @@ static void gpmc_setup(int chipselect, int accesscycles, int size, bool enablecs
* Export a gpio from the kernel to userland
*/
-static int gpio_export(unsigned base, unsigned io)
+static int gpio_export(unsigned gpio_pin)
{
FILE* exportfile = fopen(GPIO_SYSFSPATH"/"GPIO_EXPORTNODE, "w");
if (exportfile != NULL) {
- fprintf(exportfile, "%d\n", base + io);
+ fprintf(exportfile, "%d\n", gpio_pin);
fclose(exportfile);
return 0;
}
@@ -226,11 +226,11 @@ static int gpio_export(unsigned base, unsigned io)
* Un-export a gpio from userland
*/
-static int gpio_unexport(unsigned base, unsigned io)
+static int gpio_unexport(unsigned gpio_pin)
{
FILE* unexportfile = fopen(GPIO_SYSFSPATH"/"GPIO_UNEXPORTNODE, "w");
if (unexportfile != NULL) {
- fprintf(unexportfile, "%d\n", base + io);
+ fprintf(unexportfile, "%d\n", gpio_pin);
fclose(unexportfile);
return 0;
}
@@ -241,10 +241,10 @@ static int gpio_unexport(unsigned base, unsigned io)
* Change a pins direction
*/
-static int gpio_changedirection(unsigned base, unsigned io, bool out)
+static int gpio_changedirection(unsigned gpio_pin, bool out)
{
char path[PATHLEN];
- snprintf(path, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_DIRECTIONNODE, base + io);
+ snprintf(path, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_DIRECTIONNODE, gpio_pin);
FILE* directionfile = fopen(path, "w");
if (directionfile != NULL) {
if (out) {
@@ -259,19 +259,19 @@ static int gpio_changedirection(unsigned base, unsigned io, bool out)
return -1;
}
-static void gpio_getvaluenodepath(unsigned base, unsigned io, char* buffer)
+static void gpio_getvaluenodepath(unsigned gpio_pin, char* buffer)
{
- snprintf(buffer, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_VALUENODE, base + io);
+ snprintf(buffer, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_VALUENODE, gpio_pin);
}
/*
* Read a pin's value
*/
-static int gpio_readvalue(unsigned base, unsigned io)
+static int gpio_readvalue(unsigned gpio_pin)
{
char path[PATHLEN];
- gpio_getvaluenodepath(base, io, path);
+ gpio_getvaluenodepath(gpio_pin, path);
FILE* valuefile = fopen(path, "r");
if (valuefile != NULL) {
char value[2]; // value will be a single char and \n
@@ -286,10 +286,10 @@ static int gpio_readvalue(unsigned base, unsigned io)
* Write a pin's value
*/
-static int gpio_writevalue(unsigned base, unsigned io, int value)
+static int gpio_writevalue(unsigned gpio_pin, int value)
{
char path[PATHLEN];
- gpio_getvaluenodepath(base, io, path);
+ gpio_getvaluenodepath(gpio_pin, path);
FILE* valuefile = fopen(path, "w");
if (valuefile != NULL) {
fprintf(valuefile, "%d\n", value);
@@ -299,8 +299,20 @@ static int gpio_writevalue(unsigned base, unsigned io, int value)
return -1;
}
-static unsigned bases[] = { GPIOPIN0BASE, GPIOPIN1BASE, GPIOPIN2BASE, GPIOPIN3BASE, GPIOPIN4BASE, GPIOPIN5BASE };
-static unsigned pins[] = { GPIOPIN0PIN, GPIOPIN1PIN, GPIOPIN2PIN, GPIOPIN3PIN, GPIOPIN4PIN, GPIOPIN5PIN };
+// gpio pins are grouped into 4 bunches of 32 pins
+
+#define GPIO0_X (0 * 32)
+#define GPIO1_X (1 * 32)
+#define GPIO2_X (2 * 32)
+#define GPIO3_X (3 * 32)
+
+static unsigned gpio_pins[] = { GPIO0_X + 22, // i.e., GPIO0_22
+ GPIO0_X + 23,
+ GPIO0_X + 26,
+ GPIO1_X + 15, // i.e., GPIO1_15
+ GPIO1_X + 14,
+ GPIO0_X + 27 };
+
static volatile uint8_t* extbus;
static bool isbb = false;
@@ -322,9 +334,9 @@ void bus_init()
//gpmc_printinfo();
int i;
- for (i = 0; i < SIZEOFARRAY(bases); i++) {
- gpio_export(bases[i], pins[i]);
- gpio_changedirection(bases[i], pins[i], true);
+ for (i = 0; i < SIZEOFARRAY(gpio_pins); i++) {
+ gpio_export(gpio_pins[i]);
+ gpio_changedirection(gpio_pins[i], true);
}
}
}
@@ -332,7 +344,7 @@ void bus_init()
void bus_setpin(int pin, int value)
{
if (isbb) {
- gpio_writevalue(bases[pin], pins[pin], value & 0x1);
+ gpio_writevalue(gpio_pins[pin], value & 0x1);
}
}
@@ -357,8 +369,8 @@ void bus_shutdown()
if (isbb) {
util_unmapmemoryblock((void*) extbus, 0x100);
int i;
- for (i = 0; i < SIZEOFARRAY(bases); i++) {
- gpio_unexport(bases[i], pins[i]);
+ for (i = 0; i < SIZEOFARRAY(gpio_pins); i++) {
+ gpio_unexport(gpio_pins[i]);
}
}