Beispiel #1
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;
}
/* 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

#ifdef CONFIG_MACH_C110_WESTBRIDGE_AST_PNAND_HAL
 /* start C110 HAL init instsnce */
	if (!cy_as_hal_c110_pnand_start(dev_handle_name,
		&(cy_as_dev->hal_tag), cy_false)) {
		cy_as_hal_print_message("<1>_cy_as_device: start C110 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)) {
		cy_as_hal_print_message("[%s] error in register the platform\
			driver for west bridge\n", __FUNCTION__);
		platform_driver_unregister(&west_bridge_driver);
		return PTR_ERR(westbridge_pd);
	} else {