pwm: Use pinmap functions for setting up pwm.
* Intended function of check_pwm also checks for conflicting gpio, due * to quirk on galileo rev d, functionality commented. Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
This commit is contained in:
@@ -185,6 +185,15 @@ unsigned int maa_check_aio(int pin);
|
|||||||
*/
|
*/
|
||||||
unsigned int maa_check_i2c();
|
unsigned int maa_check_i2c();
|
||||||
|
|
||||||
|
/** Check PWM
|
||||||
|
*
|
||||||
|
* Will check input is valid for pwm and will also setup required multiplexers.
|
||||||
|
* IF the pin also does gpio (strong chance), DO NOTHING, REV D is strange.
|
||||||
|
* @param pin the pin as read from the board surface.
|
||||||
|
* @return the pwm pin_info_t of that IO pin
|
||||||
|
*/
|
||||||
|
maa_pin_t* maa_check_pwm(int pin);
|
||||||
|
|
||||||
/** Get the version string of maa autogenerated from git tag
|
/** Get the version string of maa autogenerated from git tag
|
||||||
*
|
*
|
||||||
* The version returned may not be what is expected however it is a reliable
|
* The version returned may not be what is expected however it is a reliable
|
||||||
|
|||||||
38
src/maa.c
38
src/maa.c
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "maa.h"
|
#include "maa.h"
|
||||||
#include "intel_galileo_rev_d.h"
|
#include "intel_galileo_rev_d.h"
|
||||||
@@ -98,14 +99,13 @@ maa_check_aio(int aio)
|
|||||||
|
|
||||||
int pin = aio + plat->gpio_count;
|
int pin = aio + plat->gpio_count;
|
||||||
|
|
||||||
if(plat->pins[pin].capabilites.aio != 1)
|
if (plat->pins[pin].capabilites.aio != 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (plat->pins[pin].aio.mux_total > 0)
|
if (plat->pins[pin].aio.mux_total > 0)
|
||||||
if (maa_setup_mux_mapped(plat->pins[pin].aio) != MAA_SUCCESS)
|
if (maa_setup_mux_mapped(plat->pins[pin].aio) != MAA_SUCCESS)
|
||||||
return -1;
|
return -1;
|
||||||
return plat->pins[pin].aio.pinmap;
|
return plat->pins[pin].aio.pinmap;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
@@ -132,3 +132,37 @@ maa_check_i2c(int bus_s)
|
|||||||
|
|
||||||
return plat->i2c_bus[bus].bus_id;
|
return plat->i2c_bus[bus].bus_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maa_pin_t*
|
||||||
|
maa_check_pwm(int pin)
|
||||||
|
{
|
||||||
|
if (plat == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (plat->pins[pin].capabilites.pwm != 1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/** quirk in rev d, this messes with pwm on that pin
|
||||||
|
* if (plat->pins[pin].capabilites.gpio == 1) {
|
||||||
|
* maa_gpio_context* mux_i;
|
||||||
|
* mux_i = maa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
|
||||||
|
* if (mux_i == NULL)
|
||||||
|
* return NULL;
|
||||||
|
* if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
|
||||||
|
* return NULL;
|
||||||
|
* if (maa_gpio_write(mux_i, 0) != MAA_SUCCESS)
|
||||||
|
* return NULL;
|
||||||
|
* if (maa_gpio_close(mux_i) != MAA_SUCCESS)
|
||||||
|
* return NULL;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
if (plat->pins[pin].pwm.mux_total > 0)
|
||||||
|
if (maa_setup_mux_mapped(plat->pins[pin].pwm) != MAA_SUCCESS)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
maa_pin_t *ret;
|
||||||
|
ret = (maa_pin_t*) malloc(sizeof(maa_pin_t));
|
||||||
|
ret->pinmap = plat->pins[pin].pwm.pinmap;
|
||||||
|
ret->parent_id = plat->pins[pin].pwm.parent_id;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|||||||
@@ -101,8 +101,13 @@ maa_pwm_get_duty(maa_pwm_context* dev)
|
|||||||
|
|
||||||
maa_pwm_context*
|
maa_pwm_context*
|
||||||
maa_pwm_init(int pin) {
|
maa_pwm_init(int pin) {
|
||||||
//TODO
|
maa_pin_t* pinm = maa_check_pwm(pin);
|
||||||
return maa_pwm_init_raw(0, pin);
|
if (pinm == NULL)
|
||||||
|
return NULL;
|
||||||
|
int chip = pinm->parent_id;
|
||||||
|
int pinn = pinm->pinmap;
|
||||||
|
free(pinm);
|
||||||
|
return maa_pwm_init_raw(chip,pinn);
|
||||||
}
|
}
|
||||||
|
|
||||||
maa_pwm_context*
|
maa_pwm_context*
|
||||||
@@ -121,8 +126,8 @@ maa_pwm_init_raw(int chipin, int pin)
|
|||||||
|
|
||||||
if ((export_f = fopen(buffer, "w")) == NULL) {
|
if ((export_f = fopen(buffer, "w")) == NULL) {
|
||||||
fprintf(stderr, "Failed to open export for writing!\n");
|
fprintf(stderr, "Failed to open export for writing!\n");
|
||||||
free(dev);
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
fprintf(export_f, "%d", dev->pin);
|
fprintf(export_f, "%d", dev->pin);
|
||||||
fclose(export_f);
|
fclose(export_f);
|
||||||
|
|||||||
Reference in New Issue
Block a user