Commit d47c1e4b authored by Ladislav Michl's avatar Ladislav Michl Committed by Sebastian Reichel

power: supply: gpio-charger: Remove pdata from gpio_charger

Platform data are now used only during probe time, so remove
them from gpio_charger structure and consolidate probing
function accordingly.
Signed-off-by: default avatarLadislav Michl <ladis@linux-mips.org>
[Replace of_property_read_string with dev_property_read_string]
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.co.uk>
parent f5fec4cc
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <linux/power/gpio-charger.h> #include <linux/power/gpio-charger.h>
struct gpio_charger { struct gpio_charger {
const struct gpio_charger_platform_data *pdata;
unsigned int irq; unsigned int irq;
bool wakeup_enabled; bool wakeup_enabled;
...@@ -67,52 +66,37 @@ static int gpio_charger_get_property(struct power_supply *psy, ...@@ -67,52 +66,37 @@ static int gpio_charger_get_property(struct power_supply *psy,
return 0; return 0;
} }
static enum power_supply_property gpio_charger_properties[] = { static enum power_supply_type gpio_charger_get_type(struct device *dev)
POWER_SUPPLY_PROP_ONLINE,
};
static
struct gpio_charger_platform_data *gpio_charger_parse_dt(struct device *dev)
{ {
struct device_node *np = dev->of_node;
struct gpio_charger_platform_data *pdata;
const char *chargetype; const char *chargetype;
int ret;
if (!device_property_read_string(dev, "charger-type", &chargetype)) {
if (!np) if (!strcmp("unknown", chargetype))
return ERR_PTR(-ENOENT); return POWER_SUPPLY_TYPE_UNKNOWN;
if (!strcmp("battery", chargetype))
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); return POWER_SUPPLY_TYPE_BATTERY;
if (!pdata) if (!strcmp("ups", chargetype))
return ERR_PTR(-ENOMEM); return POWER_SUPPLY_TYPE_UPS;
if (!strcmp("mains", chargetype))
pdata->name = np->name; return POWER_SUPPLY_TYPE_MAINS;
pdata->type = POWER_SUPPLY_TYPE_UNKNOWN; if (!strcmp("usb-sdp", chargetype))
ret = of_property_read_string(np, "charger-type", &chargetype); return POWER_SUPPLY_TYPE_USB;
if (ret >= 0) { if (!strcmp("usb-dcp", chargetype))
if (!strncmp("unknown", chargetype, 7)) return POWER_SUPPLY_TYPE_USB_DCP;
pdata->type = POWER_SUPPLY_TYPE_UNKNOWN; if (!strcmp("usb-cdp", chargetype))
else if (!strncmp("battery", chargetype, 7)) return POWER_SUPPLY_TYPE_USB_CDP;
pdata->type = POWER_SUPPLY_TYPE_BATTERY; if (!strcmp("usb-aca", chargetype))
else if (!strncmp("ups", chargetype, 3)) return POWER_SUPPLY_TYPE_USB_ACA;
pdata->type = POWER_SUPPLY_TYPE_UPS;
else if (!strncmp("mains", chargetype, 5))
pdata->type = POWER_SUPPLY_TYPE_MAINS;
else if (!strncmp("usb-sdp", chargetype, 7))
pdata->type = POWER_SUPPLY_TYPE_USB;
else if (!strncmp("usb-dcp", chargetype, 7))
pdata->type = POWER_SUPPLY_TYPE_USB_DCP;
else if (!strncmp("usb-cdp", chargetype, 7))
pdata->type = POWER_SUPPLY_TYPE_USB_CDP;
else if (!strncmp("usb-aca", chargetype, 7))
pdata->type = POWER_SUPPLY_TYPE_USB_ACA;
else
dev_warn(dev, "unknown charger type %s\n", chargetype);
} }
dev_warn(dev, "unknown charger type %s\n", chargetype);
return pdata; return POWER_SUPPLY_TYPE_UNKNOWN;
} }
static enum power_supply_property gpio_charger_properties[] = {
POWER_SUPPLY_PROP_ONLINE,
};
static int gpio_charger_probe(struct platform_device *pdev) static int gpio_charger_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -123,14 +107,9 @@ static int gpio_charger_probe(struct platform_device *pdev) ...@@ -123,14 +107,9 @@ static int gpio_charger_probe(struct platform_device *pdev)
unsigned long flags; unsigned long flags;
int irq, ret; int irq, ret;
if (!pdata) { if (!pdata && !dev->of_node) {
pdata = gpio_charger_parse_dt(dev); dev_err(dev, "No platform data\n");
if (IS_ERR(pdata)) { return -ENOENT;
ret = PTR_ERR(pdata);
if (ret != -EPROBE_DEFER)
dev_err(dev, "No platform data\n");
return ret;
}
} }
gpio_charger = devm_kzalloc(dev, sizeof(*gpio_charger), GFP_KERNEL); gpio_charger = devm_kzalloc(dev, sizeof(*gpio_charger), GFP_KERNEL);
...@@ -173,18 +152,26 @@ static int gpio_charger_probe(struct platform_device *pdev) ...@@ -173,18 +152,26 @@ static int gpio_charger_probe(struct platform_device *pdev)
} }
charger_desc = &gpio_charger->charger_desc; charger_desc = &gpio_charger->charger_desc;
charger_desc->name = pdata->name ? pdata->name : "gpio-charger";
charger_desc->type = pdata->type;
charger_desc->properties = gpio_charger_properties; charger_desc->properties = gpio_charger_properties;
charger_desc->num_properties = ARRAY_SIZE(gpio_charger_properties); charger_desc->num_properties = ARRAY_SIZE(gpio_charger_properties);
charger_desc->get_property = gpio_charger_get_property; charger_desc->get_property = gpio_charger_get_property;
psy_cfg.supplied_to = pdata->supplied_to;
psy_cfg.num_supplicants = pdata->num_supplicants;
psy_cfg.of_node = dev->of_node; psy_cfg.of_node = dev->of_node;
psy_cfg.drv_data = gpio_charger; psy_cfg.drv_data = gpio_charger;
if (pdata) {
charger_desc->name = pdata->name;
charger_desc->type = pdata->type;
psy_cfg.supplied_to = pdata->supplied_to;
psy_cfg.num_supplicants = pdata->num_supplicants;
} else {
charger_desc->name = dev->of_node->name;
charger_desc->type = gpio_charger_get_type(dev);
}
if (!charger_desc->name)
charger_desc->name = pdev->name;
gpio_charger->charger = devm_power_supply_register(dev, charger_desc, gpio_charger->charger = devm_power_supply_register(dev, charger_desc,
&psy_cfg); &psy_cfg);
if (IS_ERR(gpio_charger->charger)) { if (IS_ERR(gpio_charger->charger)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment