void cy_as_hal_sleep(uint32_t ms)
{
	cy_as_hal_sleep_channel channel;

	cy_as_hal_create_sleep_channel(&channel) ;
	cy_as_hal_sleep_on(&channel, ms) ;
	cy_as_hal_destroy_sleep_channel(&channel) ;
}
Ejemplo n.º 2
0
/* west bridge device driver main init */
static int cyasdevice_initialize(void)
{
    cyasdevice *cy_as_dev = 0;
    int		 ret	= 0;
    int		 retval = 0;
    cy_as_device_config config;
    cy_as_hal_sleep_channel channel;
    cy_as_get_firmware_version_data ver_data = {0};
    const char *str = "";
    int spin_lim;
    const struct firmware *fw_entry;

    cy_as_device_init_done = 0;

    cy_as_misc_set_log_level(8);

    cy_as_hal_print_message("<1>_cy_as_device initialize called\n");

    if (cy_as_device_controller != 0) {
        cy_as_hal_print_message("<1>_cy_as_device: the device "
                                "has already been initilaized. ignoring\n");
        return -EBUSY;
    }

    /* cy_as_dev = CyAsHalAlloc (sizeof(cyasdevice), SLAB_KERNEL); */
    cy_as_dev = cy_as_hal_alloc(sizeof(cyasdevice));
    if (cy_as_dev == NULL) {
        cy_as_hal_print_message("<1>_cy_as_device: "
                                "memory allocation failed\n");
        return -ENOMEM;
    }
    memset(cy_as_dev, 0, sizeof(cyasdevice));


    /* Init the HAL & CyAsDeviceHandle */

#ifdef CONFIG_MACH_OMAP3_WESTBRIDGE_AST_PNAND_HAL
    /* start OMAP HAL init instsnce */

    if (!start_o_m_a_p_kernel(dev_handle_name,
                              &(cy_as_dev->hal_tag), cy_false)) {

        cy_as_hal_print_message(
            "<1>_cy_as_device: start OMAP34xx HAL failed\n");
        goto done;
    }
#endif

    /* Now create the device */
    if (cy_as_misc_create_device(&(cy_as_dev->dev_handle),
                                 cy_as_dev->hal_tag) != CY_AS_ERROR_SUCCESS) {

        cy_as_hal_print_message(
            "<1>_cy_as_device: create device failed\n");
        goto done;
    }

    memset(&config, 0, sizeof(config));
    config.dmaintr = cy_true;

    ret = cy_as_misc_configure_device(cy_as_dev->dev_handle, &config);
    if (ret != CY_AS_ERROR_SUCCESS) {

        cy_as_hal_print_message(
            "<1>_cy_as_device: configure device "
            "failed. reason code: %d\n", ret);
        goto done;
    }

    ret = cy_as_misc_register_callback(cy_as_dev->dev_handle,
                                       cy_misc_callback);
    if (ret != CY_AS_ERROR_SUCCESS) {
        cy_as_hal_print_message("<1>_cy_as_device: "
                                "cy_as_misc_register_callback failed. "
                                "reason code: %d\n", ret);
        goto done;
    }

    ret = platform_driver_register(&west_bridge_driver);
    if (unlikely(ret < 0))
        return ret;
    westbridge_pd = platform_device_register_simple(
                        "west_bridge_dev", -1, NULL, 0);

    if (IS_ERR(westbridge_pd)) {
        platform_driver_unregister(&west_bridge_driver);
        return PTR_ERR(westbridge_pd);
    }
    /* Load the firmware */
    ret = request_firmware(&fw_entry,
                           "west bridge fw", &westbridge_pd->dev);
    if (ret) {
        cy_as_hal_print_message("cy_as_device: "
                                "request_firmware failed return val = %d\n", ret);
    } else {
        cy_as_hal_print_message("cy_as_device: "
                                "got the firmware %d size=0x%x\n", ret, fw_entry->size);

        ret = cy_as_misc_download_firmware(
                  cy_as_dev->dev_handle,
                  fw_entry->data,
                  fw_entry->size ,
                  0, 0);
    }

    if (ret != CY_AS_ERROR_SUCCESS) {
        cy_as_hal_print_message("<1>_cy_as_device: cannot download "
                                "firmware. reason code: %d\n", ret);
        goto done;
    }

    /* spin until the device init is completed */
    /* 50 -MAX wait time for the FW load & init
     * to complete is 5sec*/
    spin_lim = 50;

    cy_as_hal_create_sleep_channel(&channel);
    while (!cy_as_device_init_done) {

        cy_as_hal_sleep_on(&channel, 100);

        if (spin_lim-- <= 0) {
            cy_as_hal_print_message(
                "<1>\n_e_r_r_o_r!: "
                "wait for FW init has timed out !!!");
            break;
        }
    }
    cy_as_hal_destroy_sleep_channel(&channel);

    if (spin_lim > 0)
        cy_as_hal_print_message(
            "cy_as_device: astoria firmware is loaded\n");

    ret = cy_as_misc_get_firmware_version(cy_as_dev->dev_handle,
                                          &ver_data, 0, 0);
    if (ret != CY_AS_ERROR_SUCCESS) {
        cy_as_hal_print_message("<1>_cy_as_device: cannot get firmware "
                                "version. reason code: %d\n", ret);
        goto done;
    }

    if ((ver_data.media_type & 0x01) && (ver_data.media_type & 0x06))
        str = "nand and SD/MMC.";
    else if ((ver_data.media_type & 0x01) && (ver_data.media_type & 0x08))
        str = "nand and CEATA.";
    else if (ver_data.media_type & 0x01)
        str = "nand.";
    else if (ver_data.media_type & 0x08)
        str = "CEATA.";
    else
        str = "SD/MMC.";

    cy_as_hal_print_message("<1> cy_as_device:_firmware version: %s "
                            "major=%d minor=%d build=%d,\n_media types supported:%s\n",
                            ((ver_data.is_debug_mode) ? "debug" : "release"),
                            ver_data.major, ver_data.minor, ver_data.build, str);

    spin_lock_init(&cy_as_dev->common_lock);

    /* done now */
    cy_as_device_controller = cy_as_dev;

    return 0;

done:
    if (cy_as_dev)
        cyasdevice_deinit(cy_as_dev);

    return -EINVAL;
}
Ejemplo n.º 3
0
/*
 * CyAsDmaStart()
 *
 * This function intializes the DMA module to insure it is up and running.
 */
cy_as_return_status_t
cy_as_dma_start(cy_as_device *dev_p)
{
	cy_as_end_point_number_t i ;
	uint16_t cnt ;

	if (cy_as_device_is_dma_running(dev_p))
		return CY_AS_ERROR_ALREADY_RUNNING ;

	/*
	 * pre-allocate DMA queue structures to be used in the interrupt context
	 */
	for (cnt = 0 ; cnt < 32 ; cnt++) {
		cy_as_dma_queue_entry *entry_p = (cy_as_dma_queue_entry *)
			cy_as_hal_alloc(sizeof(cy_as_dma_queue_entry)) ;
		if (entry_p == 0) {
			cy_as_dma_stop_internal(dev_p) ;
			return CY_AS_ERROR_OUT_OF_MEMORY ;
		}
		cy_as_dma_add_request_to_free_queue(dev_p, entry_p) ;
	}

	/*
	 * pre-allocate the DMA requests for sending EP0
	 * and EP1 data to west bridge
	 */
	dev_p->usb_ep0_dma_req = cy_as_ll_create_request(dev_p,
		CY_RQT_USB_EP_DATA, CY_RQT_USB_RQT_CONTEXT, 64) ;
	dev_p->usb_ep1_dma_req = cy_as_ll_create_request(dev_p,
		CY_RQT_USB_EP_DATA, CY_RQT_USB_RQT_CONTEXT, 64) ;

	if (dev_p->usb_ep0_dma_req == 0 || dev_p->usb_ep1_dma_req == 0) {
		cy_as_dma_stop_internal(dev_p) ;
		return CY_AS_ERROR_OUT_OF_MEMORY ;
	}
	dev_p->usb_ep0_dma_req_save = dev_p->usb_ep0_dma_req ;

	dev_p->usb_ep0_dma_resp = cy_as_ll_create_response(dev_p, 1) ;
	dev_p->usb_ep1_dma_resp = cy_as_ll_create_response(dev_p, 1) ;
	if (dev_p->usb_ep0_dma_resp == 0 || dev_p->usb_ep1_dma_resp == 0) {
		cy_as_dma_stop_internal(dev_p) ;
		return CY_AS_ERROR_OUT_OF_MEMORY ;
	}
	dev_p->usb_ep0_dma_resp_save = dev_p->usb_ep0_dma_resp ;

	/*
	 * set the dev_p->endp to all zeros to insure cleanup is possible if
	 * an error occurs during initialization.
	 */
	cy_as_hal_mem_set(dev_p->endp, 0, sizeof(dev_p->endp)) ;

	/*
	 * now, iterate through each of the endpoints and initialize each
	 * one.
	 */
	for (i = 0 ; i < sizeof(dev_p->endp)/sizeof(dev_p->endp[0]) ; i++) {
		dev_p->endp[i] = (cy_as_dma_end_point *)
			cy_as_hal_alloc(sizeof(cy_as_dma_end_point)) ;
		if (dev_p->endp[i] == 0) {
			cy_as_dma_stop_internal(dev_p) ;
			return CY_AS_ERROR_OUT_OF_MEMORY ;
		}
		cy_as_hal_mem_set(dev_p->endp[i], 0,
			sizeof(cy_as_dma_end_point)) ;

		dev_p->endp[i]->ep = i ;
		dev_p->endp[i]->queue_p = 0 ;
		dev_p->endp[i]->last_p = 0 ;

		cy_as_dma_set_drq(dev_p, i, cy_false) ;

		if (!cy_as_hal_create_sleep_channel(&dev_p->endp[i]->channel))
			return CY_AS_ERROR_CREATE_SLEEP_CHANNEL_FAILED ;
	}

	/*
	 * tell the HAL layer who to call when the
	 * HAL layer completes a DMA request
	 */
	cy_as_hal_dma_register_callback(dev_p->tag,
		cy_as_dma_completed_callback) ;

	/*
	 * mark DMA as up and running on this device
	 */
	cy_as_device_set_dma_running(dev_p) ;

	return CY_AS_ERROR_SUCCESS ;
}