Exemplo n.º 1
0
static int __init hsi_controller_init(struct hsi_dev *hsi_ctrl,
                                      struct platform_device *pd)
{
    struct hsi_platform_data *pdata = pd->dev.platform_data;
    struct resource *mem, *ioarea;
    int err;

    mem = platform_get_resource(pd, IORESOURCE_MEM, 0);
    if (!mem) {
        dev_err(&pd->dev, "HSI device does not have "
                "HSI IO memory region information\n");
        return -ENXIO;
    }
    dev_dbg(&pd->dev, "hsi_controller_init : IORESOURCE_MEM %s [%x, %x]\n",
            mem->name, mem->start, mem->end);

    ioarea = devm_request_mem_region(&pd->dev, mem->start,
                                     (mem->end - mem->start) + 1,
                                     dev_name(&pd->dev));
    if (!ioarea) {
        dev_err(&pd->dev, "Unable to request HSI IO mem region\n");
        return -EBUSY;
    }
    dev_dbg(&pd->dev, "hsi_controller_init : ioarea %s [%x, %x]\n",
            ioarea->name, ioarea->start, ioarea->end);

    hsi_ctrl->phy_base = mem->start;
    hsi_ctrl->base = devm_ioremap(&pd->dev, mem->start,
                                  (mem->end - mem->start) + 1);
    if (!hsi_ctrl->base) {
        dev_err(&pd->dev, "Unable to ioremap HSI base IO address\n");
        return -ENXIO;
    }
    dev_dbg(&pd->dev, "hsi_controller_init : hsi_ctrl->base=%x\n",
            (unsigned int)hsi_ctrl->base);

    hsi_ctrl->id = pd->id;
    if (pdata->num_ports > HSI_MAX_PORTS) {
        dev_err(&pd->dev, "The HSI driver does not support enough "
                "ports!\n");
        return -ENXIO;
    }
    hsi_ctrl->max_p = pdata->num_ports;
    hsi_ctrl->clock_enabled = false;
    hsi_ctrl->clock_rate = 0;
    hsi_ctrl->in_dma_tasklet = false;
    hsi_ctrl->fifo_mapping_strategy = pdata->fifo_mapping_strategy;
    hsi_ctrl->dev = &pd->dev;
    spin_lock_init(&hsi_ctrl->lock);
    err = hsi_init_gdd_chan_count(hsi_ctrl);
    if (err < 0)
        goto rback1;

    err = hsi_ports_init(hsi_ctrl);
    if (err < 0)
        goto rback1;

    err = hsi_request_gdd_irq(hsi_ctrl);
    if (err < 0)
        goto rback2;

    /* Everything is fine */
    return 0;
rback2:
    hsi_ports_exit(hsi_ctrl, hsi_ctrl->max_p);
rback1:
    dev_err(&pd->dev, "Error on hsi_controller initialization\n");
    return err;
}
Exemplo n.º 2
0
static int __init hsi_controller_init(struct hsi_dev *hsi_ctrl,
				      struct platform_device *pd)
{
	struct hsi_platform_data *pdata = pd->dev.platform_data;
	struct resource *mem, *ioarea;
	int err;

	mem = platform_get_resource(pd, IORESOURCE_MEM, 0);
	if (!mem) {
		dev_err(&pd->dev, "HSI device does not have "
			"HSI IO memory region information\n");
		return -ENXIO;
	}

	ioarea = devm_request_mem_region(&pd->dev, mem->start,
					 (mem->end - mem->start) + 1,
					 dev_name(&pd->dev));
	if (!ioarea) {
		dev_err(&pd->dev, "Unable to request HSI IO mem region\n");
		return -EBUSY;
	}

	hsi_ctrl->phy_base = mem->start;
	hsi_ctrl->base = devm_ioremap(&pd->dev, mem->start,
				      (mem->end - mem->start) + 1);
	if (!hsi_ctrl->base) {
		dev_err(&pd->dev, "Unable to ioremap HSI base IO address\n");
		return -ENXIO;
	}

	hsi_ctrl->id = pd->id;
	if (pdata->num_ports > HSI_MAX_PORTS) {
		dev_err(&pd->dev, "The HSI driver does not support enough "
		"ports!\n");
		return -ENXIO;
	}
	hsi_ctrl->max_p = pdata->num_ports;
	hsi_ctrl->dev = &pd->dev;
	spin_lock_init(&hsi_ctrl->lock);
	hsi_ctrl->hsi_clk = clk_get(&pd->dev, "hsi_ck");
	hsi_init_gdd_chan_count(hsi_ctrl);

	if (IS_ERR(hsi_ctrl->hsi_clk)) {
		dev_err(hsi_ctrl->dev, "Unable to get HSI clocks\n");
		return PTR_ERR(hsi_ctrl->hsi_clk);
	}

	if (pdata->clk_notifier_register) {
		hsi_ctrl->hsi_nb.notifier_call = hsi_clk_event;
		hsi_ctrl->hsi_nb.priority = INT_MAX; /* Let's try to be first */
		err = pdata->clk_notifier_register(hsi_ctrl->hsi_clk,
						   &hsi_ctrl->hsi_nb);
		if (err < 0)
			goto rback1;
	}

	err = hsi_ports_init(hsi_ctrl);
	if (err < 0)
		goto rback2;

	err = hsi_request_gdd_irq(hsi_ctrl);
	if (err < 0)
		goto rback3;

	return 0;
rback3:
	hsi_ports_exit(hsi_ctrl, hsi_ctrl->max_p);
rback2:
	if (pdata->clk_notifier_unregister)
		pdata->clk_notifier_unregister(hsi_ctrl->hsi_clk,
					       &hsi_ctrl->hsi_nb);
rback1:
	clk_put(hsi_ctrl->hsi_clk);
	dev_err(&pd->dev, "Error on hsi_controller initialization\n");
	return err;
}