| /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 and |
| * only version 2 as published by the Free Software Foundation. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| */ |
| |
| #include <linux/module.h> |
| #include <linux/kernel.h> |
| #include <linux/slab.h> |
| #include <linux/platform_device.h> |
| #include <linux/dma-mapping.h> |
| #include <linux/ioport.h> |
| #include <linux/io.h> |
| #include <linux/module.h> |
| #include <linux/types.h> |
| #include <linux/usb/msm_hsusb.h> |
| #include <linux/delay.h> |
| #include <linux/of.h> |
| |
| #define DBM_MAX_EPS 4 |
| |
| struct dwc3_msm { |
| struct platform_device *dwc3; |
| struct device *dev; |
| void __iomem *base; |
| u32 resource_size; |
| int dbm_num_eps; |
| }; |
| |
| static int __devinit dwc3_msm_probe(struct platform_device *pdev) |
| { |
| struct device_node *node = pdev->dev.of_node; |
| struct platform_device *dwc3; |
| struct dwc3_msm *msm; |
| struct resource *res; |
| int ret = 0; |
| |
| msm = devm_kzalloc(&pdev->dev, sizeof(*msm), GFP_KERNEL); |
| if (!msm) { |
| dev_err(&pdev->dev, "not enough memory\n"); |
| return -ENOMEM; |
| } |
| |
| platform_set_drvdata(pdev, msm); |
| |
| res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| if (!res) { |
| dev_err(&pdev->dev, "missing memory base resource\n"); |
| return -ENODEV; |
| } |
| |
| msm->base = devm_ioremap_nocache(&pdev->dev, res->start, |
| resource_size(res)); |
| if (!msm->base) { |
| dev_err(&pdev->dev, "ioremap failed\n"); |
| return -ENODEV; |
| } |
| |
| dwc3 = platform_device_alloc("dwc3-msm", -1); |
| if (!dwc3) { |
| dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); |
| return -ENOMEM; |
| } |
| |
| dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask); |
| |
| dwc3->dev.parent = &pdev->dev; |
| dwc3->dev.dma_mask = pdev->dev.dma_mask; |
| dwc3->dev.dma_parms = pdev->dev.dma_parms; |
| msm->resource_size = resource_size(res); |
| msm->dev = &pdev->dev; |
| msm->dwc3 = dwc3; |
| |
| if (of_property_read_u32(node, "qcom,dwc-usb3-msm-dbm-eps", |
| &msm->dbm_num_eps)) { |
| dev_err(&pdev->dev, |
| "unable to read platform data num of dbm eps\n"); |
| msm->dbm_num_eps = DBM_MAX_EPS; |
| } |
| |
| if (msm->dbm_num_eps > DBM_MAX_EPS) { |
| dev_err(&pdev->dev, |
| "Driver doesn't support number of DBM EPs. " |
| "max: %d, dbm_num_eps: %d\n", |
| DBM_MAX_EPS, msm->dbm_num_eps); |
| ret = -ENODEV; |
| goto err1; |
| } |
| |
| ret = platform_device_add_resources(dwc3, pdev->resource, |
| pdev->num_resources); |
| if (ret) { |
| dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); |
| goto err1; |
| } |
| |
| ret = platform_device_add(dwc3); |
| if (ret) { |
| dev_err(&pdev->dev, "failed to register dwc3 device\n"); |
| goto err1; |
| } |
| |
| return 0; |
| |
| err1: |
| platform_device_put(dwc3); |
| |
| return ret; |
| } |
| |
| static int __devexit dwc3_msm_remove(struct platform_device *pdev) |
| { |
| struct dwc3_msm *msm = platform_get_drvdata(pdev); |
| |
| platform_device_unregister(msm->dwc3); |
| |
| return 0; |
| } |
| |
| static const struct of_device_id of_dwc3_matach[] = { |
| { |
| .compatible = "qcom,dwc-usb3-msm", |
| }, |
| { }, |
| }; |
| MODULE_DEVICE_TABLE(of, of_dwc3_matach); |
| |
| static struct platform_driver dwc3_msm_driver = { |
| .probe = dwc3_msm_probe, |
| .remove = __devexit_p(dwc3_msm_remove), |
| .driver = { |
| .name = "msm-dwc3", |
| .of_match_table = of_dwc3_matach, |
| }, |
| }; |
| |
| MODULE_LICENSE("GPLV2"); |
| MODULE_DESCRIPTION("DesignWare USB3 MSM Glue Layer"); |
| |
| static int __devinit dwc3_msm_init(void) |
| { |
| return platform_driver_register(&dwc3_msm_driver); |
| } |
| module_init(dwc3_msm_init); |
| |
| static void __exit dwc3_msm_exit(void) |
| { |
| platform_driver_unregister(&dwc3_msm_driver); |
| } |
| module_exit(dwc3_msm_exit); |