ASoC: twl4030: Convert to use devm_kzalloc
[linux-2.6/btrfs-unstable.git] / drivers / usb / dwc3 / dwc3-exynos.c
blobb8f00389fa34c2acb169afde75d142d84dab9ea2
1 /**
2 * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
7 * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/platform_device.h>
19 #include <linux/platform_data/dwc3-exynos.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/clk.h>
23 #include "core.h"
25 struct dwc3_exynos {
26 struct platform_device *dwc3;
27 struct device *dev;
29 struct clk *clk;
32 static int __devinit dwc3_exynos_probe(struct platform_device *pdev)
34 struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
35 struct platform_device *dwc3;
36 struct dwc3_exynos *exynos;
37 struct clk *clk;
39 int devid;
40 int ret = -ENOMEM;
42 exynos = kzalloc(sizeof(*exynos), GFP_KERNEL);
43 if (!exynos) {
44 dev_err(&pdev->dev, "not enough memory\n");
45 goto err0;
48 platform_set_drvdata(pdev, exynos);
50 devid = dwc3_get_device_id();
51 if (devid < 0)
52 goto err1;
54 dwc3 = platform_device_alloc("dwc3", devid);
55 if (!dwc3) {
56 dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
57 goto err2;
60 clk = clk_get(&pdev->dev, "usbdrd30");
61 if (IS_ERR(clk)) {
62 dev_err(&pdev->dev, "couldn't get clock\n");
63 ret = -EINVAL;
64 goto err3;
67 dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask);
69 dwc3->dev.parent = &pdev->dev;
70 dwc3->dev.dma_mask = pdev->dev.dma_mask;
71 dwc3->dev.dma_parms = pdev->dev.dma_parms;
72 exynos->dwc3 = dwc3;
73 exynos->dev = &pdev->dev;
74 exynos->clk = clk;
76 clk_enable(exynos->clk);
78 /* PHY initialization */
79 if (!pdata) {
80 dev_dbg(&pdev->dev, "missing platform data\n");
81 } else {
82 if (pdata->phy_init)
83 pdata->phy_init(pdev, pdata->phy_type);
86 ret = platform_device_add_resources(dwc3, pdev->resource,
87 pdev->num_resources);
88 if (ret) {
89 dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
90 goto err4;
93 ret = platform_device_add(dwc3);
94 if (ret) {
95 dev_err(&pdev->dev, "failed to register dwc3 device\n");
96 goto err4;
99 return 0;
101 err4:
102 if (pdata && pdata->phy_exit)
103 pdata->phy_exit(pdev, pdata->phy_type);
105 clk_disable(clk);
106 clk_put(clk);
107 err3:
108 platform_device_put(dwc3);
109 err2:
110 dwc3_put_device_id(devid);
111 err1:
112 kfree(exynos);
113 err0:
114 return ret;
117 static int __devexit dwc3_exynos_remove(struct platform_device *pdev)
119 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
120 struct dwc3_exynos_data *pdata = pdev->dev.platform_data;
122 platform_device_unregister(exynos->dwc3);
124 dwc3_put_device_id(exynos->dwc3->id);
126 if (pdata && pdata->phy_exit)
127 pdata->phy_exit(pdev, pdata->phy_type);
129 clk_disable(exynos->clk);
130 clk_put(exynos->clk);
132 kfree(exynos);
134 return 0;
137 static struct platform_driver dwc3_exynos_driver = {
138 .probe = dwc3_exynos_probe,
139 .remove = __devexit_p(dwc3_exynos_remove),
140 .driver = {
141 .name = "exynos-dwc3",
145 module_platform_driver(dwc3_exynos_driver);
147 MODULE_ALIAS("platform:exynos-dwc3");
148 MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
149 MODULE_LICENSE("GPL");
150 MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");