static int wb_suspend(struct platform_device *devptr, pm_message_t pm) { disable_irq(WB_SDCD_IRQ_INT); down(&cy_as_device_controller->wq_sema); if (cy_as_device_controller->cy_work->f_isrunning) { up(&cy_as_device_controller->wq_sema); enable_irq(WB_SDCD_IRQ_INT); return -1; } up(&cy_as_device_controller->wq_sema); /* cy_as_hal_print_message(KERN_ERR"%s called\n", __func__); */ /* down(&cy_as_device_controller->wq_sema); */ cyasdevice_disable_thread(); cancel_delayed_work(&cy_as_device_controller->cy_work->work); cyasdevice_enter_standby(); /* disable clock */ /* cy_as_hal_sleep(10); */ msleep(10); disable_irq(WB_CYAS_IRQ_INT); gpio_set_value(WB_CLK_EN, 0); cy_as_hal_enable_NANDCLK(0); cy_as_hal_enable_power(cy_as_device_controller->hal_tag, 0); /* up(&cy_as_device_controller->wq_sema); */ return 0; }
static void cy_wq_function(struct work_struct *work) { int status; int is_inserted; int ret; int retry_count; down(&cy_as_device_controller->thread_sleep_sem); down(&cy_as_device_controller->wq_sema); cy_as_device_controller->cy_work->f_isrunning = 1; up(&cy_as_device_controller->wq_sema); status = cy_as_device_controller->cy_work->f_status; g_SD_flag = is_inserted = cy_as_hal_detect_SD(); if (cy_as_device_controller->cy_work->f_reload == 1) { cy_as_device_controller->cy_work->f_reload = 0; cy_as_hal_enable_power(cy_as_device_controller->hal_tag, 1); } #ifdef __USE_CYAS_AUTO_SUSPEND__ cyasdevice_disable_thread(); #endif if (!is_inserted) { /* removed SD card. */ cy_as_hal_print_message(KERN_ERR "[cyasdevice.c] %s: SD card is removed.\n", __func__) ; if (status) { cy_as_hal_print_message(KERN_ERR "[cyasdevice.c] %s: cyasblkdev_blk_exit\n", __func__) ; down(&cy_as_device_controller->wq_sema); cyasdevice_leave_standby(); cy_as_device_controller->cy_work->f_status = 0x0; up(&cy_as_device_controller->wq_sema); cyasblkdev_blk_exit(); retry_count = 0; while (!cy_as_device_init_done) { if (++retry_count == 5) { cyasdevice_reload_firmware(0); break; } msleep(10); } } down(&cy_as_device_controller->wq_sema); cyasdevice_enter_standby(); up(&cy_as_device_controller->wq_sema); msleep(10); } else { /* insterted SD card. */ cy_as_hal_print_message(KERN_ERR"[cyasdevice.c] %s:\ leave standby\n", __func__) ; down(&cy_as_device_controller->wq_sema); cyasdevice_leave_standby(); up(&cy_as_device_controller->wq_sema); retry_count = 0; while (!cy_as_device_init_done) { if (++retry_count == 5) { cyasdevice_reload_firmware(0); break; } msleep(10); } cy_as_hal_print_message(KERN_ERR "++++++++++++ [cyasdevice.c] %s: SD card is inserted.\n", __func__) ; if (cy_as_device_controller->cy_work->f_reload == 2) { cy_as_device_controller->cy_work->f_reload = 0; ret = cyasblkdev_check_sdcard(); if (ret == 1) { cy_as_hal_print_message( "[cyasdevice.c] %s: cyasblkdev_blk_exit\n", __func__) ; cyasblkdev_blk_exit(); status = cy_as_device_controller->cy_work->f_status = 0x0; } else if (ret < 0) { cyasblkdev_blk_exit(); cy_as_hal_print_message( "[cyasdevice.c] %s: reload firmware\n", __func__) ; status = cy_as_device_controller->cy_work->f_status = 0x0; } else { #ifdef __USE_CYAS_AUTO_SUSPEND__ cyasdevice_enable_thread(); #endif } } if (status == 0) { cy_as_hal_print_message(KERN_ERR "[cyasdevice.c] %s: cyasblkdev_blk_init\n", __func__) ; cy_as_device_controller->cy_work->f_status = 0x1; retry_count = 2; while (retry_count--) { ret = cyasblkdev_blk_init(0, 0); if (ret) { cyasblkdev_blk_exit(); msleep(10); cyasdevice_reload_firmware(-1); msleep(10); } else break; } if (ret) { down(&cy_as_device_controller->wq_sema); cyasdevice_enter_standby(); up(&cy_as_device_controller->wq_sema); msleep(10); cy_as_device_controller->cy_work->f_isrunning = 0; up(&cy_as_device_controller->thread_sleep_sem); return; } } #ifdef __USE_CYAS_AUTO_SUSPEND__ /* cyasdevice_enable_thread(); */ #endif } cy_as_device_controller->cy_work->f_isrunning = 0; up(&cy_as_device_controller->thread_sleep_sem); return; }
int cy_as_diagnostics(cy_as_diag_cmd_type mode, char *result) { uint32_t retVal = 0; #ifdef __CYAS_SYSFS_FOR_DIAGNOSTICS__ cy_as_device_handle cyas_hd = cyasdevice_getdevhandle(); switch( mode ) { case CY_AS_DIAG_GET_VERSION: { cy_as_get_firmware_version_data ver_data = {0}; const char *str = "" ; cyasdevice_leave_standby(); retVal = cy_as_misc_get_firmware_version(cyas_hd, &ver_data, 0, 0) ; if (retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message("cy_as_diagnostics: cannot get firmware version. reason code: %d\n", retVal) ; sprintf( result, "fail - %d", retVal ); return retVal; } 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." ; cyasdevice_enter_standby(); 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) ; sprintf( result, "%d.%d.%d", ver_data.major, ver_data.minor, ver_data.build ); } break; case CY_AS_DIAG_DISABLE_MSM_SDIO: break; case CY_AS_DIAG_ENABLE_MSM_SDIO: break; case CY_AS_DIAG_ENTER_STANDBY: cyasdevice_enter_standby(); break; case CY_AS_DIAG_LEAVE_STANDBY: cyasdevice_leave_standby(); break; case CY_AS_DIAG_CREATE_BLKDEV: retVal = cyasblkdev_blk_init(0, 0); break; case CY_AS_DIAG_DESTROY_BLKDEV: cyasblkdev_blk_exit(); break; case CY_AS_DIAG_SD_MOUNT: { int i; uint32_t count = 0 ; int bus = 1 ; cy_as_storage_query_device_data dev_data ; cy_as_storage_query_unit_data unit_data = {0} ; cyasdevice_leave_standby(); actdata = (uint8_t *)cy_as_hal_alloc(CYASSTORAGE_MAX_XFER_SIZE); expdata = (uint8_t *)cy_as_hal_alloc(CYASSTORAGE_MAX_XFER_SIZE); cy_as_hal_mem_set(actdata, 0, CYASSTORAGE_MAX_XFER_SIZE); cy_as_hal_mem_set(expdata, 0, CYASSTORAGE_MAX_XFER_SIZE); retVal = cy_as_storage_device_control(cyas_hd, bus, 0, cy_true, cy_false, cy_as_storage_detect_SDAT_3, 0, 0) ; if (retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message(KERN_ERR"ERROR: Cannot set Device control - Reason code %d\n", retVal) ; return retVal; } // Start the storage API and get a handle to the device we are interested in. retVal = cy_as_storage_start(cyas_hd,0,0) ; if (retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message(KERN_ERR"ERROR: Cannot start storage stack - Reason code %d\n", retVal) ; return retVal; } retVal = cy_as_storage_query_media(cyas_hd, cy_as_media_sd_flash, &count, 0, 0) ; if (retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message(KERN_ERR"ERROR: Cannot query SD device count - Reason code %d\n", retVal) ; return retVal; } if (!count) { cy_as_hal_print_message(KERN_ERR"ERROR: SD storage media was not found\n") ; return retVal; } else { cy_as_hal_print_message(KERN_ERR"SUCCESS: %d SD device(s) found. SD_CLK, SD_CMD, and SD_D0 connected\n", count) ; dev_data.bus = 1 ; dev_data.device = 0 ; retVal = cy_as_storage_query_device(cyas_hd, &dev_data, 0, 0 ); if(retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message(KERN_ERR"ERROR: Cannot query SD device count - Reason code %d\n", retVal) ; return retVal; } else { #if 1 //skkm retVal = cy_as_storage_change_sd_frequency(cyas_hd, bus, 0x11, 24, 0, 0); if(retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message("%s: Cannot control cy_as_storage_change_sd_frequency - reason [%d]\n", __func__, retVal) ; } #endif cy_as_hal_print_message(KERN_ERR"Checking for SD_WP Connectivity:\n"); if(dev_data.desc_p.writeable) { cy_as_hal_print_message(KERN_ERR" SD media is not write protected \n") ; } else { cy_as_hal_print_message(KERN_ERR" SD media is write protected %d\n", retVal) ; } unit_data.device = 0 ; unit_data.unit = 0 ; unit_data.bus = bus; retVal = cy_as_storage_query_unit(cyas_hd,&unit_data, 0, 0) ; if (retVal != CY_AS_ERROR_SUCCESS) { #ifndef WESTBRIDGE_NDEBUG cy_as_hal_print_message(KERN_INFO"%s: cannot query %d device unit - reason code %d\n", __func__, unit_data.bus, retVal) ; #endif return retVal; } } } cy_as_hal_set_ep_dma_mode(4, false); cy_as_hal_set_ep_dma_mode(8, false); start_unit = unit_data.desc_p.unit_size - MAX_DRQ_LOOPS_IN_ISR*2; for ( i = 0 ; i < CYASSTORAGE_MAX_XFER_SIZE ; i++ ) { expdata[i] = i; } } break; case CY_AS_DIAG_SD_READ: { int i; int bus = 1 ; struct timespec mStartTime, mEndTime; long second,nano; long mDelta; mStartTime = CURRENT_TIME; retVal = cy_as_storage_read(cyas_hd, bus, 0, 0, start_unit, actdata, MAX_DRQ_LOOPS_IN_ISR) ; if (retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message(KERN_ERR "ERROR: cannot read from block device - code %d\n", retVal) ; break; } mEndTime = CURRENT_TIME; second = mEndTime.tv_sec - mStartTime.tv_sec; nano = mEndTime.tv_nsec - mStartTime.tv_nsec; mDelta = (second*1000000) + nano/1000; cy_as_hal_print_message("<1>%s: reading speed = %d KByte/s\n", __func__, (int)((CYASSTORAGE_MAX_XFER_SIZE*1000)/mDelta) ) ; if ( memcmp(expdata, actdata, 2048) != 0 ) { int errCnt = 0 ; cy_as_hal_print_message(KERN_ERR "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n") ; for ( i = 0 ; i < 2048 ; i++ ) { if ( expdata[i] != actdata[i] ) { cy_as_hal_print_message(KERN_ERR "EXP[%d]: 0x%02x\n",i, expdata[i]); cy_as_hal_print_message(KERN_ERR "ACT[%d]: 0x%02x\n",i, actdata[i]); errCnt++ ; if ( errCnt > 10 ) { break; } } } cy_as_hal_print_message(KERN_ERR "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n") ; retVal = CY_AS_ERROR_INVALID_RESPONSE; break; } else { cy_as_hal_print_message(KERN_ERR "success : storage test\n") ; } } break; case CY_AS_DIAG_SD_WRITE: { int i; int bus = 1 ; struct timespec mStartTime, mEndTime; long second,nano; long mDelta; for ( i = 0 ; i < CYASSTORAGE_MAX_XFER_SIZE ; i++ ) { expdata[i] = i; } mStartTime = CURRENT_TIME; retVal = cy_as_storage_write(cyas_hd, bus, 0, 0, start_unit, expdata, MAX_DRQ_LOOPS_IN_ISR) ; if (retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message(KERN_ERR "ERROR: cannot write to block device - code %d\n", retVal) ; break; } mEndTime = CURRENT_TIME; second = mEndTime.tv_sec - mStartTime.tv_sec; nano = mEndTime.tv_nsec - mStartTime.tv_nsec; mDelta = (second*1000000) + nano/1000; cy_as_hal_print_message("<1>%s: writing speed = %d KByte/s\n", __func__, (int)((CYASSTORAGE_MAX_XFER_SIZE*1000)/mDelta) ) ; } break; case CY_AS_DIAG_SD_UNMOUNT: cy_as_hal_set_ep_dma_mode(4, true); cy_as_hal_set_ep_dma_mode(8, true); // Start the storage API and get a handle to the device we are interested in. retVal = cy_as_storage_stop(cyas_hd,0,0) ; if (retVal != CY_AS_ERROR_SUCCESS) { cy_as_hal_print_message(KERN_ERR"ERROR: Cannot stop storage stack - Reason code %d\n", retVal) ; return retVal; } cy_as_hal_free(actdata); cy_as_hal_free(expdata); cyasdevice_enter_standby(); break; #if 0 case CY_AS_DIAG_CONNECT_UMS: cyasdevice_leave_standby(); //cyasblkdev_blk_exit(); cyasdevice_reload_firmware(0); //CyAsHalSelUSBSwitch(1); retVal = CyAsAPIUsbInit(); if (retVal) { cy_as_hal_print_message("%s: USB test failed.\n", __func__) ; return 0; } else { msleep(1000); cy_as_hal_print_message("%s: USB connected.\n", __func__) ; } cy_as_hal_print_message("%s: UMS MODE init done\n", __func__) ; break; case CY_AS_DIAG_DISCONNECT_UMS: CyAsAPIUsbExit(); //CyAsHalSelUSBSwitch(0); cy_as_hal_print_message("%s: UMS mode - close done\n", __func__) ; cyasdevice_reload_firmware(1); //cyasblkdev_blk_init(0, 0); cyasdevice_enter_standby(); cy_as_hal_print_message("%s: reload F/W - close done\n", __func__) ; break; case CY_AS_DIAG_CONNECT_MTP: cyasdevice_leave_standby(); //CyAsHalSelUSBSwitch(1); cyasblkdev_blk_init(0, 0); retVal = cy_as_gadget_init(1); if (retVal) { cy_as_hal_print_message("%s: cy_as_gadget_init failed.\n", __func__) ; } else { cy_as_hal_print_message("%s: cy_as_gadget_init success\n", __func__) ; } cy_as_hal_print_message("%s: Start cy_as_gadget driver - init done\n", __func__) ; break; case CY_AS_DIAG_DISCONNECT_MTP: cyasblkdev_blk_exit(); cy_as_gadget_cleanup(); //CyAsHalSelUSBSwitch(0); cyasdevice_enter_standby(); cy_as_hal_print_message("%s: cy_as_gadget driver - close done\n", __func__) ; break; #endif case CY_AS_DIAG_TEST_RESET_LOW: //cy_as_hal_set_reset_pin(0); cy_as_hal_print_message("%s: cy_as_hal_set_reset_pin - set LOW\n", __func__) ; break; case CY_AS_DIAG_TEST_RESET_HIGH: //cy_as_hal_set_reset_pin(1); cy_as_hal_print_message("%s: cy_as_hal_set_reset_pin - set HIGH\n", __func__) ; break; default: cy_as_hal_print_message("%s: unkown mode \n", __func__) ; break; } #endif return retVal; }