struct nvec_chip *nvec;
struct nvec_msg *msg;
struct resource *res;
- struct resource *iomem;
void __iomem *base;
- nvec = kzalloc(sizeof(struct nvec_chip), GFP_KERNEL);
+ nvec = devm_kzalloc(&pdev->dev, sizeof(struct nvec_chip), GFP_KERNEL);
if (nvec == NULL) {
dev_err(&pdev->dev, "failed to reserve memory\n");
return -ENOMEM;
nvec->gpio = of_get_named_gpio(nvec->dev->of_node, "request-gpios", 0);
if (nvec->gpio < 0) {
dev_err(&pdev->dev, "no gpio specified");
- goto failed;
+ return -ENODEV;
}
if (of_property_read_u32(nvec->dev->of_node, "slave-addr", &nvec->i2c_addr)) {
dev_err(&pdev->dev, "no i2c address specified");
- goto failed;
+ return -ENODEV;
}
} else {
dev_err(&pdev->dev, "no platform data\n");
- goto failed;
+ return -ENODEV;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
return -ENODEV;
}
- iomem = request_mem_region(res->start, resource_size(res), pdev->name);
- if (!iomem) {
- dev_err(&pdev->dev, "I2C region already claimed\n");
- return -EBUSY;
- }
-
- base = ioremap(iomem->start, resource_size(iomem));
+ base = devm_request_and_ioremap(&pdev->dev, res);
if (!base) {
dev_err(&pdev->dev, "Can't ioremap I2C region\n");
return -ENOMEM;
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res) {
dev_err(&pdev->dev, "no irq resource?\n");
- ret = -ENODEV;
- goto err_iounmap;
+ return -ENODEV;
}
i2c_clk = clk_get_sys("tegra-i2c.2", NULL);
if (IS_ERR(i2c_clk)) {
dev_err(nvec->dev, "failed to get controller clock\n");
- goto err_iounmap;
+ return -ENODEV;
}
nvec->base = base;
INIT_WORK(&nvec->tx_work, nvec_request_master);
nvec->wq = alloc_workqueue("nvec", WQ_NON_REENTRANT, 2);
- err = gpio_request_one(nvec->gpio, GPIOF_OUT_INIT_HIGH, "nvec gpio");
+ err = devm_gpio_request_one(&pdev->dev, nvec->gpio, GPIOF_OUT_INIT_HIGH,
+ "nvec gpio");
if (err < 0) {
dev_err(nvec->dev, "couldn't request gpio\n");
- goto failed;
+ destroy_workqueue(nvec->wq);
+ return -ENODEV;
}
- err = request_irq(nvec->irq, nvec_interrupt, 0, "nvec", nvec);
+ err = devm_request_irq(&pdev->dev, nvec->irq, nvec_interrupt, 0,
+ "nvec", nvec);
if (err) {
dev_err(nvec->dev, "couldn't request irq\n");
- goto failed;
+ destroy_workqueue(nvec->wq);
+ return -ENODEV;
}
disable_irq(nvec->irq);
nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x80\x00", 7);
return 0;
-
-err_iounmap:
- iounmap(base);
-failed:
- kfree(nvec);
- return -ENOMEM;
}
static int __devexit tegra_nvec_remove(struct platform_device *pdev)
nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3);
mfd_remove_devices(nvec->dev);
- free_irq(nvec->irq, &nvec_interrupt);
- iounmap(nvec->base);
- gpio_free(nvec->gpio);
destroy_workqueue(nvec->wq);
- kfree(nvec);
return 0;
}
static int __devinit nvec_power_probe(struct platform_device *pdev)
{
struct power_supply *psy;
- struct nvec_power *power =
- kzalloc(sizeof(struct nvec_power), GFP_NOWAIT);
+ struct nvec_power *power;
struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
+ power = devm_kzalloc(&pdev->dev, sizeof(struct nvec_power), GFP_NOWAIT);
+ if (power == NULL)
+ return -ENOMEM;
+
dev_set_drvdata(&pdev->dev, power);
power->nvec = nvec;
power->notifier.notifier_call = nvec_power_bat_notifier;
break;
default:
- kfree(power);
return -ENODEV;
}