/*1* Copyright 2008 Sascha Hauer, [email protected]2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation; either version 26* of the License, or (at your option) any later version.7* This program is distributed in the hope that it will be useful,8* but WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10* GNU General Public License for more details.11*12* You should have received a copy of the GNU General Public License13* along with this program; if not, write to the Free Software14* Foundation, Inc., 51 Franklin Street, Fifth Floor,15* Boston, MA 02110-1301, USA.16*/1718#include <linux/kernel.h>19#include <linux/slab.h>20#include <linux/init.h>21#include <linux/platform_device.h>22#include <linux/amba/bus.h>2324struct platform_device *__init mxs_add_platform_device_dmamask(25const char *name, int id,26const struct resource *res, unsigned int num_resources,27const void *data, size_t size_data, u64 dmamask)28{29int ret = -ENOMEM;30struct platform_device *pdev;3132pdev = platform_device_alloc(name, id);33if (!pdev)34goto err;3536if (dmamask) {37/*38* This memory isn't freed when the device is put,39* I don't have a nice idea for that though. Conceptually40* dma_mask in struct device should not be a pointer.41* See http://thread.gmane.org/gmane.linux.kernel.pci/908142*/43pdev->dev.dma_mask =44kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);45if (!pdev->dev.dma_mask)46/* ret is still -ENOMEM; */47goto err;4849*pdev->dev.dma_mask = dmamask;50pdev->dev.coherent_dma_mask = dmamask;51}5253if (res) {54ret = platform_device_add_resources(pdev, res, num_resources);55if (ret)56goto err;57}5859if (data) {60ret = platform_device_add_data(pdev, data, size_data);61if (ret)62goto err;63}6465ret = platform_device_add(pdev);66if (ret) {67err:68if (dmamask)69kfree(pdev->dev.dma_mask);70platform_device_put(pdev);71return ERR_PTR(ret);72}7374return pdev;75}7677int __init mxs_add_amba_device(const struct amba_device *dev)78{79struct amba_device *adev = kmalloc(sizeof(*adev), GFP_KERNEL);8081if (!adev) {82pr_err("%s: failed to allocate memory", __func__);83return -ENOMEM;84}8586*adev = *dev;8788return amba_device_register(adev, &iomem_resource);89}909192