i2c: Work started on using pinmap with i2c
* Update examples and swig interface. Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
@@ -26,16 +26,41 @@
|
||||
#include "smbus.h"
|
||||
|
||||
maa_i2c_context*
|
||||
maa_i2c_init()
|
||||
maa_i2c_init(int bus)
|
||||
{
|
||||
unsigned int checked_pin = maa_check_i2c(bus);
|
||||
if (checked_pin < 0) {
|
||||
switch(checked_pin) {
|
||||
case -1:
|
||||
fprintf(stderr, "No i2c on board\n");
|
||||
return NULL;
|
||||
case -2:
|
||||
fprintf(stderr, "Failed to set-up i2c multiplexer!\n");
|
||||
return NULL;
|
||||
case -3:
|
||||
fprintf(stderr, "Platform Not Initialised");
|
||||
return NULL;
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
return maa_i2c_init_raw(checked_pin);
|
||||
}
|
||||
|
||||
maa_i2c_context*
|
||||
maa_i2c_init_raw(unsigned int bus)
|
||||
{
|
||||
if (bus < 0) {
|
||||
fprintf(stderr, "Bus -%u- bellow zero\n", bus);
|
||||
return NULL;
|
||||
}
|
||||
maa_i2c_context* dev = (maa_i2c_context*) malloc(sizeof(maa_i2c_context));
|
||||
if (dev == NULL)
|
||||
return NULL;
|
||||
|
||||
// Galileo only has one I2C master which should be /dev/i2c-0
|
||||
// reliability is a fickle friend!
|
||||
if ((dev->fh = open("/dev/i2c-0", O_RDWR)) < 1) {
|
||||
fprintf(stderr, "Failed to open requested i2c port");
|
||||
char filepath[32];
|
||||
snprintf(filepath, 32, "/dev/i2c-%u", bus);
|
||||
if ((dev->fh = open(filepath, O_RDWR)) < 1) {
|
||||
fprintf(stderr, "Failed to open requested i2c port %s", filepath);
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
@@ -200,5 +200,27 @@ maa_intel_galileo_rev_d()
|
||||
b->pins[19].mux[1].pin = 20;
|
||||
b->pins[19].mux[1].value = 0;
|
||||
|
||||
strncpy(b->pins[20].name, "I2C", 8);
|
||||
b->pins[20].pin = 0;
|
||||
b->pins[20].parent_id = 0;
|
||||
b->pins[20].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,1,1};
|
||||
b->pins[20].mux_total = 1;
|
||||
b->pins[20].mux[0].pin = 29;
|
||||
b->pins[20].mux[0].value = 0;
|
||||
|
||||
strncpy(b->pins[21].name, "SPI-1.0", 8);
|
||||
b->pins[21].pin = 1;
|
||||
b->pins[21].parent_id = 0;
|
||||
b->pins[21].capabilites = (maa_pincapabilities_t) {1,1,0,0,0,1,1};
|
||||
b->pins[21].mux_total = 4;
|
||||
b->pins[21].mux[0].pin = 42;
|
||||
b->pins[21].mux[0].value = 0;
|
||||
b->pins[21].mux[1].pin = 43;
|
||||
b->pins[21].mux[1].value = 0;
|
||||
b->pins[21].mux[2].pin = 54;
|
||||
b->pins[21].mux[2].value = 0;
|
||||
b->pins[21].mux[3].pin = 55;
|
||||
b->pins[21].mux[3].value = 0;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
19
src/maa.c
19
src/maa.c
@@ -97,3 +97,22 @@ maa_check_aio(int aio)
|
||||
|
||||
return plat->pins[pin].pin;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
maa_check_i2c(int bus)
|
||||
{
|
||||
if (plat == NULL)
|
||||
return -3;
|
||||
|
||||
if (plat->i2c_bus_count >! 0) {
|
||||
fprintf(stderr, "No i2c buses defined in platform");
|
||||
return -1;
|
||||
}
|
||||
int pin = (plat->gpio_count + plat->aio_count) + bus;
|
||||
|
||||
if (plat->pins[pin].mux_total > 0)
|
||||
if (maa_setup_mux_mapped(plat->pins[pin]) != MAA_SUCCESS)
|
||||
return -2;
|
||||
|
||||
return plat->pins[pin].pin;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user