mraa.c: Find i2c bus by pci id
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -149,6 +149,16 @@ int mraa_find_i2c_bus(const char* devname, int startfrom);
|
|||||||
*/
|
*/
|
||||||
mraa_result_t mraa_atoi(char* intStr, int* value);
|
mraa_result_t mraa_atoi(char* intStr, int* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* helper function to find an i2c bus based on pci data
|
||||||
|
*
|
||||||
|
* @param pci_device
|
||||||
|
* @param pci_id on pci_device
|
||||||
|
* @param i2c adapter name & number
|
||||||
|
* @return the matching i2c-dev bus id or -1
|
||||||
|
*/
|
||||||
|
int mraa_find_i2c_bus_pci(const char* pci_device, const char *pci_id, const char* adapter_name);
|
||||||
|
|
||||||
#if defined(IMRAA)
|
#if defined(IMRAA)
|
||||||
/**
|
/**
|
||||||
* read Imraa subplatform lock file, caller is responsible to free return
|
* read Imraa subplatform lock file, caller is responsible to free return
|
||||||
|
|||||||
43
src/mraa.c
43
src/mraa.c
@@ -928,6 +928,49 @@ mraa_count_i2c_files(const char* path, const struct stat* sb, int flag, struct F
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mraa_find_i2c_bus_pci(const char* pci_device, const char *pci_id, const char* adapter_name)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* For example we'd get something like:
|
||||||
|
* pci0000:00/0000:00:16.3/i2c_desiignware.3
|
||||||
|
*/
|
||||||
|
char path[1024];
|
||||||
|
snprintf(path, 1024-1, "/sys/devices/pci%s/%s/%s/", pci_device, pci_id, adapter_name);
|
||||||
|
if (mraa_file_exist(path)) {
|
||||||
|
struct dirent **namelist;
|
||||||
|
int n;
|
||||||
|
n = scandir(path, &namelist, NULL, alphasort);
|
||||||
|
if (n < 0) {
|
||||||
|
syslog(LOG_ERR, "Failed to get information on i2c");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
while (n--) {
|
||||||
|
char* dup = strdup(namelist[n]->d_name);
|
||||||
|
const char delim = '-';
|
||||||
|
char* token;
|
||||||
|
token = strsep(&dup, &delim);
|
||||||
|
if (token != NULL) {
|
||||||
|
if (strncmp("i2c", token, 3) == 0) {
|
||||||
|
token = strsep(&dup, &delim);
|
||||||
|
if (token != NULL) {
|
||||||
|
int ret = -1;
|
||||||
|
if (mraa_atoi(token, &ret) == MRAA_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(namelist[n]);
|
||||||
|
}
|
||||||
|
free(namelist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mraa_find_i2c_bus(const char* devname, int startfrom)
|
mraa_find_i2c_bus(const char* devname, int startfrom)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user