示例#1
0
struct platform_device *tegra_usb_hsic_host_register(void)
{
	struct platform_device *pdev;
	int val;

	pdev = platform_device_alloc(tegra_ehci2_device.name,
		tegra_ehci2_device.id);
	if (!pdev)
		return NULL;

	val = platform_device_add_resources(pdev, tegra_ehci2_device.resource,
		tegra_ehci2_device.num_resources);
	if (val)
		goto error;

	pdev->dev.dma_mask =  tegra_ehci2_device.dev.dma_mask;
	pdev->dev.coherent_dma_mask = tegra_ehci2_device.dev.coherent_dma_mask;

	val = platform_device_add_data(pdev, &tegra_ehci_uhsic_pdata,
			sizeof(struct tegra_ehci_platform_data));
	if (val)
		goto error;

	val = platform_device_add(pdev);
	if (val)
		goto error;

	return pdev;

error:
	pr_err("%s: failed to add the host contoller device\n", __func__);
	platform_device_put(pdev);
	return NULL;
}
static int kempld_create_platform_device(const struct dmi_system_id *id)
{
	struct kempld_platform_data *pdata = id->driver_data;
	int ret;

	kempld_pdev = platform_device_alloc("kempld", -1);
	if (!kempld_pdev)
		return -ENOMEM;

	ret = platform_device_add_data(kempld_pdev, pdata, sizeof(*pdata));
	if (ret)
		goto err;

	ret = platform_device_add_resources(kempld_pdev, pdata->ioresource, 1);
	if (ret)
		goto err;

	ret = platform_device_add(kempld_pdev);
	if (ret)
		goto err;

	return 0;
err:
	platform_device_put(kempld_pdev);
	return ret;
}
示例#3
0
文件: mcbsp.c 项目: Elamaran/linux
static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
			struct omap_mcbsp_platform_data *config, int size)
{
	int i;

	omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *),
				     GFP_KERNEL);
	if (!omap_mcbsp_devices) {
		printk(KERN_ERR "Could not register McBSP devices\n");
		return;
	}

	for (i = 0; i < size; i++) {
		struct platform_device *new_mcbsp;
		int ret;

		new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1);
		if (!new_mcbsp)
			continue;
		platform_device_add_resources(new_mcbsp, &res[i * res_count],
					res_count);
		config[i].reg_size = 2;
		config[i].reg_step = 2;
		new_mcbsp->dev.platform_data = &config[i];
		ret = platform_device_add(new_mcbsp);
		if (ret) {
			platform_device_put(new_mcbsp);
			continue;
		}
		omap_mcbsp_devices[i] = new_mcbsp;
	}
}
int mali_platform_device_register(void)
{
	int err;

	MALI_DEBUG_PRINT(4, ("mali_platform_device_register() called\n"));

	/* Connect resources to the device */
	err = platform_device_add_resources(&exynos4_device_g3d, mali_gpu_resources, sizeof(mali_gpu_resources) / sizeof(mali_gpu_resources[0]));
	if (0 == err)
	{
		err = platform_device_add_data(&exynos4_device_g3d, &mali_gpu_data, sizeof(mali_gpu_data));
		if (0 == err)
		{
			mali_platform_init(&(exynos4_device_g3d.dev));

#ifdef CONFIG_PM_RUNTIME
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
			pm_runtime_set_autosuspend_delay(&(exynos4_device_g3d.dev), 1000);
			pm_runtime_use_autosuspend(&(exynos4_device_g3d.dev));
#endif
			pm_runtime_enable(&(exynos4_device_g3d.dev));
#endif
			return 0;
		}

	}
	return err;
}
示例#5
0
文件: main.c 项目: smihir/wcn36xx
static int __init wcn36xx_msm_init(void)
{
	int ret;
	struct resource *wcnss_memory;
	struct resource *tx_irq;
	struct resource *rx_irq;
	struct resource res[3];
	wmsm.core = platform_device_alloc("wcn36xx", -1);

	memset(res, 0x00, sizeof(res));
	wmsm.ctrl_ops.open = wcn36xx_msm_smd_open;
	wmsm.ctrl_ops.close = wcn36xx_msm_smd_close;
	wmsm.ctrl_ops.tx = wcn36xx_msm_smd_send_and_wait;
	wmsm.ctrl_ops.get_hw_mac = wcn36xx_msm_get_hw_mac;
	wmsm.ctrl_ops.smsm_change_state = wcn36xx_msm_smsm_change_state;
	wcnss_memory =
		platform_get_resource_byname(wcnss_get_platform_device(),
					      IORESOURCE_MEM,
					      "wcnss_mmio");
	if (wcnss_memory == NULL) {
		dev_err(&wmsm.core->dev,
			"Failed to get wcnss wlan memory map.\n");
		ret = -ENOMEM;
		return ret;
	}
	memcpy(&res[0], wcnss_memory, sizeof(*wcnss_memory));

	tx_irq = platform_get_resource_byname(wcnss_get_platform_device(),
					      IORESOURCE_IRQ,
					      "wcnss_wlantx_irq");
	if (tx_irq == NULL) {
		dev_err(&wmsm.core->dev, "Failed to get wcnss tx_irq");
		ret = -ENOMEM;
		return ret;
	}
	memcpy(&res[1], tx_irq, sizeof(*tx_irq));

	rx_irq = platform_get_resource_byname(wcnss_get_platform_device(),
					      IORESOURCE_IRQ,
					      "wcnss_wlanrx_irq");
	if (rx_irq == NULL) {
		dev_err(&wmsm.core->dev, "Failed to get wcnss rx_irq");
		ret = -ENOMEM;
		return ret;
	}
	memcpy(&res[2], rx_irq, sizeof(*rx_irq));

	platform_device_add_resources(wmsm.core, res, ARRAY_SIZE(res));

	ret = platform_device_add_data(wmsm.core, &wmsm.ctrl_ops,
				       sizeof(wmsm.ctrl_ops));
	if (ret) {
		dev_err(&wmsm.core->dev, "Can't add platform data\n");
		ret = -ENOMEM;
		return ret;
	}

	platform_device_add(wmsm.core);
	return 0;
}
示例#6
0
static int __devinit msm_sata_probe(struct platform_device *pdev)
{
	struct platform_device *ahci;
	struct msm_sata_hba *hba;
	struct ahci_msm_platform_data *msm_ahci_data;
	int ret = 0;

	hba = devm_kzalloc(&pdev->dev, sizeof(struct msm_sata_hba), GFP_KERNEL);
	if (!hba) {
		dev_err(&pdev->dev, "no memory\n");
		ret = -ENOMEM;
		goto err;
	}

	platform_set_drvdata(pdev, hba);
	msm_ahci_data =
		(struct ahci_msm_platform_data *)pdev->dev.platform_data;
	hba->tx_preemph_gen3 = msm_ahci_data->tx_preemph_gen3;
	hba->rx_eq = msm_ahci_data->rx_eq;
	hba->mpll = msm_ahci_data->mpll;
	hba->term_off = msm_ahci_data->term_off;

	ahci = platform_device_alloc("ahci", pdev->id);
	if (!ahci) {
		dev_err(&pdev->dev, "couldn't allocate ahci device\n");
		ret = -ENOMEM;
		goto err_free;
	}

	dma_set_coherent_mask(&ahci->dev, pdev->dev.coherent_dma_mask);

	ahci->dev.parent = &pdev->dev;
	ahci->dev.dma_mask = pdev->dev.dma_mask;
	ahci->dev.dma_parms = pdev->dev.dma_parms;
	hba->ahci_pdev = ahci;

	ret = platform_device_add_resources(ahci, pdev->resource,
			pdev->num_resources);
	if (ret) {
		dev_err(&pdev->dev, "couldn't add resources to ahci device\n");
		goto err_put_device;
	}

	ahci->dev.platform_data = &msm_ahci_pdata;
	ret = platform_device_add(ahci);
	if (ret) {
		dev_err(&pdev->dev, "failed to register ahci device\n");
		goto err_put_device;
	}

	return 0;

err_put_device:
	platform_device_put(ahci);
err_free:
	devm_kfree(&pdev->dev, hba);
err:
	return ret;
}
示例#7
0
static int dwc3_pci_probe(struct pci_dev *pci,
		const struct pci_device_id *id)
{
	struct resource		res[2];
	struct platform_device	*dwc3;
	int			ret;
	struct device		*dev = &pci->dev;

	ret = pcim_enable_device(pci);
	if (ret) {
		dev_err(dev, "failed to enable pci device\n");
		return -ENODEV;
	}

	pci_set_master(pci);

	dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
	if (!dwc3) {
		dev_err(dev, "couldn't allocate dwc3 device\n");
		return -ENOMEM;
	}

	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));

	res[0].start	= pci_resource_start(pci, 0);
	res[0].end	= pci_resource_end(pci, 0);
	res[0].name	= "dwc_usb3";
	res[0].flags	= IORESOURCE_MEM;

	res[1].start	= pci->irq;
	res[1].name	= "dwc_usb3";
	res[1].flags	= IORESOURCE_IRQ;

	ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
	if (ret) {
		dev_err(dev, "couldn't add resources to dwc3 device\n");
		return ret;
	}

	pci_set_drvdata(pci, dwc3);
	ret = dwc3_pci_quirks(pci);
	if (ret)
		goto err;

	dwc3->dev.parent = dev;
	ACPI_COMPANION_SET(&dwc3->dev, ACPI_COMPANION(dev));

	ret = platform_device_add(dwc3);
	if (ret) {
		dev_err(dev, "failed to register dwc3 device\n");
		goto err;
	}

	return 0;
err:
	platform_device_put(dwc3);
	return ret;
}
示例#8
0
文件: bcmmii.c 项目: Anjali05/linux
static int bcmgenet_mii_register(struct bcmgenet_priv *priv)
{
	struct platform_device *pdev = priv->pdev;
	struct bcmgenet_platform_data *pdata = pdev->dev.platform_data;
	struct device_node *dn = pdev->dev.of_node;
	struct unimac_mdio_pdata ppd;
	struct platform_device *ppdev;
	struct resource *pres, res;
	int id, ret;

	pres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	memset(&res, 0, sizeof(res));
	memset(&ppd, 0, sizeof(ppd));

	ppd.wait_func = bcmgenet_mii_wait;
	ppd.wait_func_data = priv;
	ppd.bus_name = "bcmgenet MII bus";

	/* Unimac MDIO bus controller starts at UniMAC offset + MDIO_CMD
	 * and is 2 * 32-bits word long, 8 bytes total.
	 */
	res.start = pres->start + GENET_UMAC_OFF + UMAC_MDIO_CMD;
	res.end = res.start + 8;
	res.flags = IORESOURCE_MEM;

	if (dn)
		id = of_alias_get_id(dn, "eth");
	else
		id = pdev->id;

	ppdev = platform_device_alloc(UNIMAC_MDIO_DRV_NAME, id);
	if (!ppdev)
		return -ENOMEM;

	/* Retain this platform_device pointer for later cleanup */
	priv->mii_pdev = ppdev;
	ppdev->dev.parent = &pdev->dev;
	ppdev->dev.of_node = bcmgenet_mii_of_find_mdio(priv);
	if (pdata)
		bcmgenet_mii_pdata_init(priv, &ppd);

	ret = platform_device_add_resources(ppdev, &res, 1);
	if (ret)
		goto out;

	ret = platform_device_add_data(ppdev, &ppd, sizeof(ppd));
	if (ret)
		goto out;

	ret = platform_device_add(ppdev);
	if (ret)
		goto out;

	return 0;
out:
	platform_device_put(ppdev);
	return ret;
}
示例#9
0
static int __init abituguru_init(void)
{
	int address, err;
	struct resource res = { .flags = IORESOURCE_IO };

#ifdef CONFIG_DMI
	const char *board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);

	
	if (!force && (!board_vendor ||
			strcmp(board_vendor, "http://www.abit.com.tw/")))
		return -ENODEV;
#endif

	address = abituguru_detect();
	if (address < 0)
		return address;

	err = platform_driver_register(&abituguru_driver);
	if (err)
		goto exit;

	abituguru_pdev = platform_device_alloc(ABIT_UGURU_NAME, address);
	if (!abituguru_pdev) {
		printk(KERN_ERR ABIT_UGURU_NAME
			": Device allocation failed\n");
		err = -ENOMEM;
		goto exit_driver_unregister;
	}

	res.start = address;
	res.end = address + ABIT_UGURU_REGION_LENGTH - 1;
	res.name = ABIT_UGURU_NAME;

	err = platform_device_add_resources(abituguru_pdev, &res, 1);
	if (err) {
		printk(KERN_ERR ABIT_UGURU_NAME
			": Device resource addition failed (%d)\n", err);
		goto exit_device_put;
	}

	err = platform_device_add(abituguru_pdev);
	if (err) {
		printk(KERN_ERR ABIT_UGURU_NAME
			": Device addition failed (%d)\n", err);
		goto exit_device_put;
	}

	return 0;

exit_device_put:
	platform_device_put(abituguru_pdev);
exit_driver_unregister:
	platform_driver_unregister(&abituguru_driver);
exit:
	return err;
}
void __init *msic_gpio_platform_data(void *info)
{
	struct platform_device *pdev = NULL;
	struct sfi_device_table_entry *entry = info;
	static struct intel_msic_gpio_pdata msic_gpio_pdata;
	int ret;
	int gpio;
	struct resource res;

	pdev = platform_device_alloc(MSIC_GPIO_DEVICE_NAME, -1);

	if (!pdev) {
		pr_err("out of memory for SFI platform dev %s\n",
					MSIC_GPIO_DEVICE_NAME);
		return NULL;
	}

	gpio = get_gpio_by_name("msic_gpio_base");

	if (gpio < 0)
		return NULL;

	/* Basincove PMIC GPIO has total 8 GPIO pins,
	 * GPIO[5:2,0] support 1.8V, GPIO[7:6,1] support 1.8V and 3.3V,
	 * We group GPIO[5:2] to low voltage and GPIO[7:6] to
	 * high voltage. Because the CTL registers are contiguous,
	 * this grouping method doesn't affect the driver usage but
	 * easy for the driver sharing among multiple platforms.
	 */
	msic_gpio_pdata.ngpio_lv = 6;
	msic_gpio_pdata.ngpio_hv = 2;
	msic_gpio_pdata.gpio0_lv_ctlo = 0x7E;
	msic_gpio_pdata.gpio0_lv_ctli = 0x8E;
	msic_gpio_pdata.gpio0_hv_ctlo = 0x84;
	msic_gpio_pdata.gpio0_hv_ctli = 0x94;

	msic_gpio_pdata.can_sleep = 1;
	msic_gpio_pdata.gpio_base = gpio;

	pdev->dev.platform_data = &msic_gpio_pdata;

	ret = platform_device_add(pdev);
	if (ret) {
		pr_err("failed to add msic gpio platform device\n");
		platform_device_put(pdev);
		return NULL;
	}

	res.name = "IRQ",
	res.flags = IORESOURCE_IRQ,
	res.start = entry->irq;
	platform_device_add_resources(pdev, &res, 1);

	register_rpmsg_service("rpmsg_msic_gpio", RPROC_SCU, RP_MSIC_GPIO);

	return &msic_gpio_pdata;
}
int pxa_register_device(struct pxa_device_desc *desc,
				void *data, size_t size)
{
	struct platform_device *pdev;
	struct resource res[2 + MAX_RESOURCE_DMA];
	int i, ret = 0, nres = 0;

	if (desc == NULL)
		return -EINVAL;

	pdev = platform_device_alloc(desc->drv_name, desc->id);
	if (pdev == NULL)
		return -ENOMEM;

	pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);

	memset(res, 0, sizeof(res));

	if (desc->start != -1ul && desc->size > 0) {
		res[nres].start	= desc->start;
		res[nres].end	= desc->start + desc->size - 1;
		res[nres].flags	= IORESOURCE_MEM;
		nres++;
	}

	if (desc->irq != NO_IRQ) {
		res[nres].start	= desc->irq;
		res[nres].end	= desc->irq;
		res[nres].flags	= IORESOURCE_IRQ;
		nres++;
	}

	for (i = 0; i < MAX_RESOURCE_DMA; i++, nres++) {
		if (desc->dma[i] == 0)
			break;

		res[nres].start	= desc->dma[i];
		res[nres].end	= desc->dma[i];
		res[nres].flags	= IORESOURCE_DMA;
	}

	ret = platform_device_add_resources(pdev, res, nres);
	if (ret) {
		platform_device_put(pdev);
		return ret;
	}

	if (data && size) {
		ret = platform_device_add_data(pdev, data, size);
		if (ret) {
			platform_device_put(pdev);
			return ret;
		}
	}

	return platform_device_add(pdev);
}
static int __init gpu_init(void)
{
    int ret = 0;

#ifndef CONFIG_DOVE_GPU
    gpu_resources[0].start = gpu_resources[0].end = irqLine;

    gpu_resources[1].start = registerMemBase;
    gpu_resources[1].end   = registerMemBase + registerMemSize - 1;

    gpu_resources[2].start = contiguousBase;
    gpu_resources[2].end   = contiguousBase + contiguousSize - 1;

/*####modified for marvell-bg2*/
    /* Allocate device */
    gpu_device = platform_device_alloc(DRV_NAME, -1);
/*####end for marvell-bg2*/

    if (!gpu_device)
    {
        printk(KERN_ERR "galcore: platform_device_alloc failed.\n");
        ret = -ENOMEM;
        goto out;
    }

    /* Insert resource */
    ret = platform_device_add_resources(gpu_device, gpu_resources, 3);
    if (ret)
    {
        printk(KERN_ERR "galcore: platform_device_add_resources failed.\n");
        goto put_dev;
    }

    /* Add device */
    ret = platform_device_add(gpu_device);
    if (ret)
    {
        printk(KERN_ERR "galcore: platform_device_add failed.\n");
        goto put_dev;
    }
#endif

    ret = platform_driver_register(&gpu_driver);
    if (!ret)
    {
        goto out;
    }

#ifndef CONFIG_DOVE_GPU
    platform_device_del(gpu_device);
put_dev:
    platform_device_put(gpu_device);
#endif

out:
    return ret;
}
示例#13
0
int mali_platform_device_register(void)
{
    int err;

    MALI_DEBUG_PRINT(4, ("mali_platform_device_register() called\n"));

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
    exynos_pm_add_dev_to_genpd(&mali_gpu_device, &exynos4_pd_g3d);
#endif

    /* Connect resources to the device */
    err = platform_device_add_resources(&mali_gpu_device, mali_gpu_resources, sizeof(mali_gpu_resources) / sizeof(mali_gpu_resources[0]));
    if (0 == err)
    {
        err = platform_device_add_data(&mali_gpu_device, &mali_gpu_data, sizeof(mali_gpu_data));
        if (0 == err)
        {
#ifdef CONFIG_PM_RUNTIME
#if defined(USE_PM_NOTIFIER)
            err = register_pm_notifier(&mali_pwr_notif_block);
            if (err)
            {
                goto plat_init_err;
            }
#endif
#endif /* CONFIG_PM_RUNTIME */

            /* Register the platform device */
            err = platform_device_register(&mali_gpu_device);
            if (0 == err)
            {
                mali_platform_init(&(mali_gpu_device.dev));

#ifdef CONFIG_PM_RUNTIME
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
                pm_runtime_set_autosuspend_delay(&(mali_gpu_device.dev), 1000);
                pm_runtime_use_autosuspend(&(mali_gpu_device.dev));
#endif
                pm_runtime_enable(&(mali_gpu_device.dev));
#endif

                return 0;
            }
        }

#ifdef CONFIG_PM_RUNTIME
#if defined(USE_PM_NOTIFIER)
plat_init_err:
        unregister_pm_notifier(&mali_pwr_notif_block);
#endif
#endif /* CONFIG_PM_RUNTIME */
        platform_device_unregister(&mali_gpu_device);
    }

    return err;
}
static int __init gpu_init(void)
{
    int ret = 0;

#ifndef CONFIG_DOVE_GPU
#if !MRVL_USE_GPU_RESERVE_MEM
    gpu_resources[0].start = gpu_resources[0].end = irqLine;

    gpu_resources[1].start = registerMemBase;
    gpu_resources[1].end   = registerMemBase + registerMemSize - 1;

    /* Allocate device */
    gpu_device = platform_device_alloc(DEVICE_NAME, -1);
    if (!gpu_device)
    {
        printk(KERN_ERR "galcore: platform_device_alloc failed.\n");
        ret = -ENOMEM;
        goto out;
    }

    /* Insert resource */
    ret = platform_device_add_resources(gpu_device, gpu_resources, 2);
    if (ret)
    {
        printk(KERN_ERR "galcore: platform_device_add_resources failed.\n");
        goto put_dev;
    }

    /* Add device */
    ret = platform_device_add(gpu_device);
    if (ret)
    {
        printk(KERN_ERR "galcore: platform_device_add failed.\n");
        goto put_dev;
    }
#endif
#endif

    ret = platform_driver_register(&gpu_driver);
    if (!ret)
    {
        goto out;
    }

#ifndef CONFIG_DOVE_GPU
#if !MRVL_USE_GPU_RESERVE_MEM
    platform_device_del(gpu_device);
put_dev:
    platform_device_put(gpu_device);
#endif
#endif

out:
    return ret;
}
示例#15
0
static int __init acpi_csrt_parse_shared_info(struct platform_device *pdev,
        const struct acpi_csrt_group *grp)
{
    const struct acpi_csrt_shared_info *si;
    struct resource res[3];
    size_t nres;
    int ret;

    memset(res, 0, sizeof(res));
    nres = 0;

    si = (const struct acpi_csrt_shared_info *)&grp[1];
    /*
     * The peripherals that are listed on CSRT typically support only
     * 32-bit addresses so we only use the low part of MMIO base for
     * now.
     */
    if (!si->mmio_base_high && si->mmio_base_low) {
        /*
         * There is no size of the memory resource in shared_info
         * so we assume that it is 4k here.
         */
        res[nres].start = si->mmio_base_low;
        res[nres].end = res[0].start + SZ_4K - 1;
        res[nres++].flags = IORESOURCE_MEM;
    }

    if (si->gsi_interrupt) {
        int irq = acpi_register_gsi(NULL, si->gsi_interrupt,
                                    si->interrupt_mode,
                                    si->interrupt_polarity);
        res[nres].start = irq;
        res[nres].end = irq;
        res[nres++].flags = IORESOURCE_IRQ;
    }

    if (si->base_request_line || si->num_handshake_signals) {
        /*
         * We pass the driver a DMA resource describing the range
         * of request lines the device supports.
         */
        res[nres].start = si->base_request_line;
        res[nres].end = res[nres].start + si->num_handshake_signals - 1;
        res[nres++].flags = IORESOURCE_DMA;
    }

    ret = platform_device_add_resources(pdev, res, nres);
    if (ret) {
        if (si->gsi_interrupt)
            acpi_unregister_gsi(si->gsi_interrupt);
        return ret;
    }

    return 0;
}
示例#16
0
static noinline void __init tegra_setup_bluesleep(void)
{
	struct platform_device *pdev = NULL;
	struct resource *res;

	pdev = platform_device_alloc("bluesleep", 0);
	if (!pdev) {
		pr_err("unable to allocate platform device for bluesleep");
		return;
	}

	res = kzalloc(sizeof(struct resource) * 3, GFP_KERNEL);
	if (!res) {
		pr_err("unable to allocate resource for bluesleep\n");
		goto err_free_dev;
	}

	res[0].name   = "gpio_host_wake";
	res[0].start  = TEGRA_GPIO_PU6;
	res[0].end    = TEGRA_GPIO_PU6;
	res[0].flags  = IORESOURCE_IO;

	res[1].name   = "gpio_ext_wake";
	res[1].start  = TEGRA_GPIO_PU1;
	res[1].end    = TEGRA_GPIO_PU1;
	res[1].flags  = IORESOURCE_IO;

	res[2].name   = "host_wake";
	res[2].start  = gpio_to_irq(TEGRA_GPIO_PU6);
	res[2].end    = gpio_to_irq(TEGRA_GPIO_PU6);
	res[2].flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE;

	if (platform_device_add_resources(pdev, res, 3)) {
		pr_err("unable to add resources to bluesleep device\n");
		goto err_free_res;
	}

	if (platform_device_add(pdev)) {
		pr_err("unable to add bluesleep device\n");
		goto err_free_res;
	}

	tegra_gpio_enable(TEGRA_GPIO_PU6);
	tegra_gpio_enable(TEGRA_GPIO_PU1);

	kfree(res);

	return;

err_free_res:
	kfree(res);
err_free_dev:
	platform_device_put(pdev);
	return;
}
示例#17
0
struct platform_device *__init at32_add_device_psif(unsigned int id)
{
	struct platform_device *pdev;
	u32 pin_mask;

	if (!(id == 0 || id == 1))
		return NULL;

	pdev = platform_device_alloc("atmel_psif", id);
	if (!pdev)
		return NULL;

	switch (id) {
	case 0:
		pin_mask  = (1 << 8) | (1 << 9); /* CLOCK & DATA */

		if (platform_device_add_resources(pdev, atmel_psif0_resource,
					ARRAY_SIZE(atmel_psif0_resource)))
			goto err_add_resources;
		atmel_psif0_pclk.dev = &pdev->dev;
		select_peripheral(PIOA, pin_mask, PERIPH_A, 0);
		break;
	case 1:
		pin_mask  = (1 << 11) | (1 << 12); /* CLOCK & DATA */

		if (platform_device_add_resources(pdev, atmel_psif1_resource,
					ARRAY_SIZE(atmel_psif1_resource)))
			goto err_add_resources;
		atmel_psif1_pclk.dev = &pdev->dev;
		select_peripheral(PIOB, pin_mask, PERIPH_A, 0);
		break;
	default:
		return NULL;
	}

	platform_device_add(pdev);
	return pdev;

err_add_resources:
	platform_device_put(pdev);
	return NULL;
}
int kbase_platform_fake_register(void)
{
	kbase_platform_config *config;
	int attribute_count;
#ifndef CONFIG_OF
	struct resource resources[PLATFORM_CONFIG_RESOURCE_COUNT];
#endif
	int err;

	config = kbase_get_platform_config(); /* declared in midgard/mali_kbase_config.h but defined in platform folder */
	if (config == NULL)
	{
		pr_err("%s: couldn't get platform config\n", __func__);
		return -ENODEV;
	}

	attribute_count = kbasep_get_config_attribute_count(config->attributes);
#ifdef CONFIG_MACH_MANTA
	err = platform_device_add_data(&exynos5_device_g3d, config->attributes, attribute_count * sizeof(config->attributes[0]));
	if (err)
		return err;
#else

	mali_device = platform_device_alloc("mali", 0);
	if (mali_device == NULL)
		return -ENOMEM;

#ifndef CONFIG_OF
	kbasep_config_parse_io_resources(config->io_resources, resources);
	err = platform_device_add_resources(mali_device, resources, PLATFORM_CONFIG_RESOURCE_COUNT);
	if (err) {
		platform_device_put(mali_device);
		mali_device = NULL;
		return err;
	}
#endif /* CONFIG_OF */

	err = platform_device_add_data(mali_device, config->attributes, attribute_count * sizeof(config->attributes[0]));
	if (err) {
		platform_device_unregister(mali_device);
		mali_device = NULL;
		return err;
	}

	err = platform_device_add(mali_device);
	if (err) {
		platform_device_unregister(mali_device);
		mali_device = NULL;
		return err;
	}
#endif /* CONFIG_CONFIG_MACH_MANTA */

	return 0;
}
static int __init platform_init(void)
{

    s3c_buttons = platform_device_alloc("mini2440-buttons",-1);

    platform_device_add_resources(s3c_buttons,&s3c_buttons_resource,7);

    /*平台设备的注册*/
    platform_device_add(s3c_buttons);


}
示例#20
0
/*
 * Create MPSC platform devices
 */
static int __init mv64x60_mpsc_register_shared_pdev(struct device_node *np)
{
	struct platform_device *pdev;
	struct resource r[2];
	struct mpsc_shared_pdata pdata;
	const phandle *ph;
	struct device_node *mpscrouting, *mpscintr;
	int err;

	ph = of_get_property(np, "mpscrouting", NULL);
	mpscrouting = of_find_node_by_phandle(*ph);
	if (!mpscrouting)
		return -ENODEV;

	err = of_address_to_resource(mpscrouting, 0, &r[0]);
	of_node_put(mpscrouting);
	if (err)
		return err;

	ph = of_get_property(np, "mpscintr", NULL);
	mpscintr = of_find_node_by_phandle(*ph);
	if (!mpscintr)
		return -ENODEV;

	err = of_address_to_resource(mpscintr, 0, &r[1]);
	of_node_put(mpscintr);
	if (err)
		return err;

	memset(&pdata, 0, sizeof(pdata));

	pdev = platform_device_alloc(MPSC_SHARED_NAME, 0);
	if (!pdev)
		return -ENOMEM;

	err = platform_device_add_resources(pdev, r, 2);
	if (err)
		goto error;

	err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
	if (err)
		goto error;

	err = platform_device_add(pdev);
	if (err)
		goto error;

	return 0;

error:
	platform_device_put(pdev);
	return err;
}
示例#21
0
文件: serial.c 项目: 0-T-0/ps4-linux
static __init int lasat_uart_add(void)
{
	struct platform_device *pdev;
	int retval;

	pdev = platform_device_alloc("serial8250", -1);
	if (!pdev)
		return -ENOMEM;

	if (!IS_LASAT_200()) {
		lasat_serial_res[0].start = KSEG1ADDR(LASAT_UART_REGS_BASE_100);
		lasat_serial_res[0].end = lasat_serial_res[0].start + LASAT_UART_REGS_SHIFT_100 * 8 - 1;
		lasat_serial_res[0].flags = IORESOURCE_MEM;
		lasat_serial_res[1].start = LASATINT_UART_100;
		lasat_serial_res[1].end = LASATINT_UART_100;
		lasat_serial_res[1].flags = IORESOURCE_IRQ;

		lasat_serial8250_port[0].mapbase = LASAT_UART_REGS_BASE_100;
		lasat_serial8250_port[0].uartclk = LASAT_BASE_BAUD_100 * 16;
		lasat_serial8250_port[0].regshift = LASAT_UART_REGS_SHIFT_100;
		lasat_serial8250_port[0].irq = LASATINT_UART_100;
	} else {
		lasat_serial_res[0].start = KSEG1ADDR(LASAT_UART_REGS_BASE_200);
		lasat_serial_res[0].end = lasat_serial_res[0].start + LASAT_UART_REGS_SHIFT_200 * 8 - 1;
		lasat_serial_res[0].flags = IORESOURCE_MEM;
		lasat_serial_res[1].start = LASATINT_UART_200;
		lasat_serial_res[1].end = LASATINT_UART_200;
		lasat_serial_res[1].flags = IORESOURCE_IRQ;

		lasat_serial8250_port[0].mapbase = LASAT_UART_REGS_BASE_200;
		lasat_serial8250_port[0].uartclk = LASAT_BASE_BAUD_200 * 16;
		lasat_serial8250_port[0].regshift = LASAT_UART_REGS_SHIFT_200;
		lasat_serial8250_port[0].irq = LASATINT_UART_200;
	}

	pdev->id = PLAT8250_DEV_PLATFORM;
	pdev->dev.platform_data = lasat_serial8250_port;

	retval = platform_device_add_resources(pdev, lasat_serial_res, ARRAY_SIZE(lasat_serial_res));
	if (retval)
		goto err_free_device;

	retval = platform_device_add(pdev);
	if (retval)
		goto err_free_device;

	return 0;

err_free_device:
	platform_device_put(pdev);

	return retval;
}
示例#22
0
struct platform_device *__init imx_add_platform_device_dmamask(
		const char *name, int id,
		const struct resource *res, unsigned int num_resources,
		const void *data, size_t size_data, u64 dmamask)
{
	int ret = -ENOMEM;
	struct platform_device *pdev;

	pdev = platform_device_alloc(name, id);
	if (!pdev)
		goto err;

	if (dmamask) {
		/*
		 * This memory isn't freed when the device is put,
		 * I don't have a nice idea for that though.  Conceptually
		 * dma_mask in struct device should not be a pointer.
		 * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
		 */
		pdev->dev.dma_mask =
			kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
		if (!pdev->dev.dma_mask)
			/* ret is still -ENOMEM; */
			goto err;

		*pdev->dev.dma_mask = dmamask;
		pdev->dev.coherent_dma_mask = dmamask;
	}

	if (res) {
		ret = platform_device_add_resources(pdev, res, num_resources);
		if (ret)
			goto err;
	}

	if (data) {
		ret = platform_device_add_data(pdev, data, size_data);
		if (ret)
			goto err;
	}

	ret = platform_device_add(pdev);
	if (ret) {
err:
		if (dmamask)
			kfree(pdev->dev.dma_mask);
		platform_device_put(pdev);
		return ERR_PTR(ret);
	}

	return pdev;
}
static struct platform_device * tegra_usb_otg_host_register(void)
{
	int val;
	struct platform_device *pdev = NULL;
	void *platform_data;

	pr_info("%s: enabling USB host mode\n", __func__);	
	
	/* Enable VBUS - This means we can power USB devices, but
	   we cant use VBUS detection at all */
	gpio_direction_input(SHUTTLE_USB0_VBUS);

	/* Leave some time for stabilization purposes */
	msleep(10);
	
	/* And register the USB host device */
	pdev = platform_device_alloc(tegra_ehci1_device.name,
			tegra_ehci1_device.id);
	if (!pdev)
		goto err_2;

	val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
		tegra_ehci1_device.num_resources);
	if (val)
		goto error;

	pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
	pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
	
	platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data), GFP_KERNEL);
	if (!platform_data)
		goto error;

	memcpy(platform_data, tegra_ehci1_device.dev.platform_data,
				sizeof(struct tegra_ehci_platform_data));
	pdev->dev.platform_data = platform_data;
 	
	val = platform_device_add(pdev);
	if (val)
		goto error_add;

	usb_host_pdev = pdev;
	return pdev;

error_add:
	kfree(platform_data);
error:
	platform_device_put(pdev);
err_2:
	pr_err("%s: failed to add the host controller device\n", __func__);	
	return NULL;
}
示例#24
0
/*
 * Register MMC devices.
 */
static int __init omap_mmc_add(const char *name, int id, unsigned long base,
                               unsigned long size, unsigned int irq,
                               unsigned rx_req, unsigned tx_req,
                               struct omap_mmc_platform_data *data)
{
    struct platform_device *pdev;
    struct resource res[OMAP_MMC_NR_RES];
    int ret;

    pdev = platform_device_alloc(name, id);
    if (!pdev)
        return -ENOMEM;

    memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
    res[0].start = base;
    res[0].end = base + size - 1;
    res[0].flags = IORESOURCE_MEM;
    res[1].start = res[1].end = irq;
    res[1].flags = IORESOURCE_IRQ;
    res[2].start = rx_req;
    res[2].name = "rx";
    res[2].flags = IORESOURCE_DMA;
    res[3].start = tx_req;
    res[3].name = "tx";
    res[3].flags = IORESOURCE_DMA;

    if (cpu_is_omap7xx())
        data->slots[0].features = MMC_OMAP7XX;
    if (cpu_is_omap15xx())
        data->slots[0].features = MMC_OMAP15XX;
    if (cpu_is_omap16xx())
        data->slots[0].features = MMC_OMAP16XX;

    ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
    if (ret == 0)
        ret = platform_device_add_data(pdev, data, sizeof(*data));
    if (ret)
        goto fail;

    ret = platform_device_add(pdev);
    if (ret)
        goto fail;

    /* return device handle to board setup code */
    data->dev = &pdev->dev;
    return 0;

fail:
    platform_device_put(pdev);
    return ret;
}
示例#25
0
文件: giu.c 项目: CSCLOG/beaglebone
static int __init vr41xx_giu_add(void)
{
	struct platform_device *pdev;
	struct resource *res;
	unsigned int num;
	int retval;

	pdev = platform_device_alloc("GIU", -1);
	if (!pdev)
		return -ENOMEM;

	switch (current_cpu_type()) {
	case CPU_VR4111:
	case CPU_VR4121:
		pdev->id = GPIO_50PINS_PULLUPDOWN;
		res = giu_50pins_pullupdown_resource;
		num = ARRAY_SIZE(giu_50pins_pullupdown_resource);
		break;
	case CPU_VR4122:
	case CPU_VR4131:
		pdev->id = GPIO_36PINS;
		res = giu_36pins_resource;
		num = ARRAY_SIZE(giu_36pins_resource);
		break;
	case CPU_VR4133:
		pdev->id = GPIO_48PINS_EDGE_SELECT;
		res = giu_48pins_resource;
		num = ARRAY_SIZE(giu_48pins_resource);
		break;
	default:
		retval = -ENODEV;
		goto err_free_device;
	}

	retval = platform_device_add_resources(pdev, res, num);
	if (retval)
		goto err_free_device;

	retval = platform_device_add(pdev);
	if (retval)
		goto err_free_device;

	return 0;

err_free_device:
	platform_device_put(pdev);

	return retval;
}
示例#26
0
static int __init p1025twr_ssd1289_init(void)
{
	struct device_node *np;
	struct platform_device *pdev;
	struct resource res[2];
	int ret;

	np = of_find_compatible_node(NULL, NULL, "ssd1289");
	if (!np) {
		printk(KERN_ERR "Get display ssd1289 device node fails\n");
		return -ENODEV;
	}

	memset(res, 0, sizeof(res));
	ret = of_address_to_resource(np, 0, &res[0]);
	if (ret) {
		printk(KERN_ERR "Failed to get resource 0\n");
		return -ENODEV;
	}
	ret = of_address_to_resource(np, 1, &res[1]);
	if (ret) {
		printk(KERN_ERR "Failed to get resource 1\n");
		return -ENODEV;
	}
	pdev = platform_device_alloc("ssd1289", 0);
	if (!pdev) {
		printk(KERN_ERR "Failed to alloc platform_device\n");
		return -ENODEV;
	}
	ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
	if (ret)
		goto unreg;

	ret = platform_device_add_data(pdev, &fsl_ssd1289_data,
					sizeof(fsl_ssd1289_data));
	if (ret)
		goto unreg;

	ret = platform_device_add(pdev);
	if (ret)
		goto unreg;

	return 0;

unreg:
	platform_device_del(pdev);
	return -ENODEV;

}
void __init smba_setup_bluesleep(void)
{
	struct platform_device *pdev = NULL;
	struct resource *res;

	pdev = platform_device_alloc("bluesleep", 0);
	if (!pdev) {
		pr_err("unable to allocate platform device for bluesleep");
		return;
	}

	res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
	if (!res) {
		pr_err("unable to allocate resource for bluesleep\n");
		goto err_free_dev;
	}

	res[0].name   = "gpio_host_wake";
	res[0].start  = SMBA1002_BT_IRQ;
	res[0].end    = SMBA1002_BT_IRQ;
	res[0].flags  = IORESOURCE_IO;

	res[1].name   = "host_wake";
	res[1].start  = gpio_to_irq(SMBA1002_BT_IRQ);
	res[1].end    = gpio_to_irq(SMBA1002_BT_IRQ);
	res[1].flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE;

	if (platform_device_add_resources(pdev, res, 2)) {
		pr_err("unable to add resources to bluesleep device\n");
		goto err_free_res;
	}

	if (platform_device_add(pdev)) {
		pr_err("unable to add bluesleep device\n");
		goto err_free_res;
	}

	tegra_gpio_enable(SMBA1002_BT_IRQ);

	kfree(res);

	return;

err_free_res:
	kfree(res);
err_free_dev:
	platform_device_put(pdev);
	return;
}
示例#28
0
static noinline void __init tegra_setup_bluesleep(void)
{
       struct platform_device *pDev = NULL;
       struct resource *res;

       pDev = platform_device_alloc("bluesleep", 0);
       if (!pDev) {
               pr_err("unable to allocate platform device for bluesleep");
               goto fail;
       }

       res = kzalloc(sizeof(struct resource)*3, GFP_KERNEL);
       if (!res) {
               pr_err("unable to allocate resource for bluesleep\n");
               goto fail;
       }

       res[0].name   = "gpio_host_wake";
       res[0].start  = TEGRA_GPIO_PU6;
       res[0].end    = TEGRA_GPIO_PU6;
       res[0].flags  = IORESOURCE_IO;

       res[1].name   = "gpio_ext_wake";
       res[1].start  = TEGRA_GPIO_PU1;
       res[1].end    = TEGRA_GPIO_PU1;
       res[1].flags  = IORESOURCE_IO;

       res[2].name   = "host_wake";
       res[2].start  = gpio_to_irq(TEGRA_GPIO_PU6);
       res[2].end    = gpio_to_irq(TEGRA_GPIO_PU6);
       res[2].flags  = IORESOURCE_IRQ;

       if (platform_device_add_resources(pDev, res, 3)) {
               pr_err("unable to add resources to bluesleep device\n");
               goto fail;
       }

       if (platform_device_add(pDev)) {
               pr_err("unable to add bluesleep device\n");
               goto fail;
       }

       bluesleep_setup_uart_port(&tegra_uart[2]);

fail:
       if (pDev)
               return;
}
示例#29
0
static struct device *add_child(struct i2c_client *client, const char *name,
                                void *pdata, unsigned pdata_len,
                                bool can_wakeup, int irq)
{
    struct platform_device	*pdev;
    int			status;

    pdev = platform_device_alloc(name, -1);
    if (!pdev) {
        dev_dbg(&client->dev, "can't alloc dev\n");
        status = -ENOMEM;
        goto err;
    }

    device_init_wakeup(&pdev->dev, can_wakeup);
    pdev->dev.parent = &client->dev;

    if (pdata) {
        status = platform_device_add_data(pdev, pdata, pdata_len);
        if (status < 0) {
            dev_dbg(&pdev->dev, "can't add platform_data\n");
            goto err;
        }
    }

    if (irq) {
        struct resource r = {
            .start = irq,
            .flags = IORESOURCE_IRQ,
        };

        status = platform_device_add_resources(pdev, &r, 1);
        if (status < 0) {
            dev_dbg(&pdev->dev, "can't add irq\n");
            goto err;
        }
    }

    status = platform_device_add(pdev);

err:
    if (status < 0) {
        platform_device_put(pdev);
        dev_err(&client->dev, "can't add %s dev\n", name);
        return ERR_PTR(status);
    }
    return &pdev->dev;
}
static struct platform_device * tegra_usb_otg_host_register(void)
{
	int val;
	struct platform_device *pdev = NULL;
	void *platform_data;

	pr_info("%s: enabling USB host mode\n", __func__);	
	
	gpio_direction_input(SMBA1002_USB0_VBUS);

	msleep(10);
	
	pdev = platform_device_alloc(tegra_ehci1_device.name,
			tegra_ehci1_device.id);
	if (!pdev)
		goto err_2;

	val = platform_device_add_resources(pdev, tegra_ehci1_device.resource,
		tegra_ehci1_device.num_resources);
	if (val)
		goto error;

	pdev->dev.dma_mask =  tegra_ehci1_device.dev.dma_mask;
	pdev->dev.coherent_dma_mask = tegra_ehci1_device.dev.coherent_dma_mask;
	
	platform_data = kmalloc(sizeof(struct tegra_ehci_platform_data), GFP_KERNEL);
	if (!platform_data)
		goto error;

	memcpy(platform_data, tegra_ehci1_device.dev.platform_data,
				sizeof(struct tegra_ehci_platform_data));
	pdev->dev.platform_data = platform_data;
 	
	val = platform_device_add(pdev);
	if (val)
		goto error_add;

	usb_host_pdev = pdev;
	return pdev;

error_add:
	kfree(platform_data);
error:
	platform_device_put(pdev);
err_2:
	pr_err("%s: failed to add the host controller device\n", __func__);	
	return NULL;
}