2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-26 22:24:09 +08:00

max8903: adds requesting of gpios.

This change ensures all gpios are available for the driver to use and also
splits off gpio setup into its own function for readability.

Signed-off-by: Chris Lapa <chris@lapa.com.au>

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
This commit is contained in:
Chris Lapa 2016-06-24 12:26:09 +10:00 committed by Sebastian Reichel
parent cbf9077e58
commit 88a469bbb2

View File

@ -179,6 +179,138 @@ static irqreturn_t max8903_fault(int irq, void *_data)
return IRQ_HANDLED;
}
static int max8903_setup_gpios(struct platform_device *pdev)
{
struct max8903_data *data = platform_get_drvdata(pdev);
struct device *dev = &pdev->dev;
struct max8903_pdata *pdata = pdev->dev.platform_data;
int ret = 0;
int gpio;
int ta_in = 0;
int usb_in = 0;
if (pdata->dc_valid) {
if (pdata->dok && gpio_is_valid(pdata->dok)) {
ret = devm_gpio_request(dev, pdata->dok,
data->psy_desc.name);
if (ret) {
dev_err(dev,
"Failed GPIO request for dok: %d err %d\n",
pdata->dok, ret);
return ret;
}
gpio = pdata->dok; /* PULL_UPed Interrupt */
ta_in = gpio_get_value(gpio) ? 0 : 1;
} else {
dev_err(dev, "When DC is wired, DOK should be wired as well.\n");
return -EINVAL;
}
}
if (pdata->dcm) {
if (gpio_is_valid(pdata->dcm)) {
ret = devm_gpio_request(dev, pdata->dcm,
data->psy_desc.name);
if (ret) {
dev_err(dev,
"Failed GPIO request for dcm: %d err %d\n",
pdata->dcm, ret);
return ret;
}
gpio = pdata->dcm; /* Output */
gpio_set_value(gpio, ta_in);
} else {
dev_err(dev, "Invalid pin: dcm.\n");
return -EINVAL;
}
}
if (pdata->usb_valid) {
if (pdata->uok && gpio_is_valid(pdata->uok)) {
ret = devm_gpio_request(dev, pdata->uok,
data->psy_desc.name);
if (ret) {
dev_err(dev,
"Failed GPIO request for uok: %d err %d\n",
pdata->uok, ret);
return ret;
}
gpio = pdata->uok;
usb_in = gpio_get_value(gpio) ? 0 : 1;
} else {
dev_err(dev, "When USB is wired, UOK should be wired."
"as well.\n");
return -EINVAL;
}
}
if (pdata->cen) {
if (gpio_is_valid(pdata->cen)) {
ret = devm_gpio_request(dev, pdata->cen,
data->psy_desc.name);
if (ret) {
dev_err(dev,
"Failed GPIO request for cen: %d err %d\n",
pdata->cen, ret);
return ret;
}
gpio_set_value(pdata->cen, (ta_in || usb_in) ? 0 : 1);
} else {
dev_err(dev, "Invalid pin: cen.\n");
return -EINVAL;
}
}
if (pdata->chg) {
if (gpio_is_valid(pdata->chg)) {
ret = devm_gpio_request(dev, pdata->chg,
data->psy_desc.name);
if (ret) {
dev_err(dev,
"Failed GPIO request for chg: %d err %d\n",
pdata->chg, ret);
return ret;
}
}
}
if (pdata->flt) {
if (gpio_is_valid(pdata->flt)) {
ret = devm_gpio_request(dev, pdata->flt,
data->psy_desc.name);
if (ret) {
dev_err(dev,
"Failed GPIO request for flt: %d err %d\n",
pdata->flt, ret);
return ret;
}
}
}
if (pdata->usus) {
if (gpio_is_valid(pdata->usus)) {
ret = devm_gpio_request(dev, pdata->usus,
data->psy_desc.name);
if (ret) {
dev_err(dev,
"Failed GPIO request for usus: %d err %d\n",
pdata->usus, ret);
return ret;
}
}
}
data->fault = false;
data->ta_in = ta_in;
data->usb_in = usb_in;
return 0;
}
static int max8903_probe(struct platform_device *pdev)
{
struct max8903_data *data;
@ -186,9 +318,6 @@ static int max8903_probe(struct platform_device *pdev)
struct max8903_pdata *pdata = pdev->dev.platform_data;
struct power_supply_config psy_cfg = {};
int ret = 0;
int gpio;
int ta_in = 0;
int usb_in = 0;
if (pdata == NULL) {
dev_err(dev, "No platform data.\n");
@ -210,74 +339,13 @@ static int max8903_probe(struct platform_device *pdev)
return -EINVAL;
}
if (pdata->dc_valid) {
if (pdata->dok && gpio_is_valid(pdata->dok)) {
gpio = pdata->dok; /* PULL_UPed Interrupt */
ta_in = gpio_get_value(gpio) ? 0 : 1;
} else {
dev_err(dev, "When DC is wired, DOK should be wired as well.\n");
return -EINVAL;
}
}
if (pdata->dcm) {
if (gpio_is_valid(pdata->dcm)) {
gpio = pdata->dcm; /* Output */
gpio_set_value(gpio, ta_in);
} else {
dev_err(dev, "Invalid pin: dcm.\n");
return -EINVAL;
}
}
if (pdata->usb_valid) {
if (pdata->uok && gpio_is_valid(pdata->uok)) {
gpio = pdata->uok;
usb_in = gpio_get_value(gpio) ? 0 : 1;
} else {
dev_err(dev, "When USB is wired, UOK should be wired."
"as well.\n");
return -EINVAL;
}
}
if (pdata->cen) {
if (gpio_is_valid(pdata->cen)) {
gpio_set_value(pdata->cen, (ta_in || usb_in) ? 0 : 1);
} else {
dev_err(dev, "Invalid pin: cen.\n");
return -EINVAL;
}
}
if (pdata->chg) {
if (!gpio_is_valid(pdata->chg)) {
dev_err(dev, "Invalid pin: chg.\n");
return -EINVAL;
}
}
if (pdata->flt) {
if (!gpio_is_valid(pdata->flt)) {
dev_err(dev, "Invalid pin: flt.\n");
return -EINVAL;
}
}
if (pdata->usus) {
if (!gpio_is_valid(pdata->usus)) {
dev_err(dev, "Invalid pin: usus.\n");
return -EINVAL;
}
}
data->fault = false;
data->ta_in = ta_in;
data->usb_in = usb_in;
ret = max8903_setup_gpios(pdev);
if (ret)
return ret;
data->psy_desc.name = "max8903_charger";
data->psy_desc.type = (ta_in) ? POWER_SUPPLY_TYPE_MAINS :
((usb_in) ? POWER_SUPPLY_TYPE_USB :
data->psy_desc.type = (data->ta_in) ? POWER_SUPPLY_TYPE_MAINS :
((data->usb_in) ? POWER_SUPPLY_TYPE_USB :
POWER_SUPPLY_TYPE_BATTERY);
data->psy_desc.get_property = max8903_get_property;
data->psy_desc.properties = max8903_charger_props;