void reset_mcu(struct ssp_data *data) {
	func_dbg();
	ssp_enable(data, false);
	clean_pending_list(data);
	toggle_mcu_reset(data);
	ssp_enable(data, true);
}
void reset_mcu(struct ssp_data *data) {
	func_dbg();
	ssp_enable(data, false);
	clean_pending_list(data);
#ifdef CONFIG_SENSORS_SSP_BBD
        bbd_mcu_reset();
#else
	toggle_mcu_reset(data);
	ssp_enable(data, true);
#endif
}
int forced_to_download_binary(struct ssp_data *data, int iBinType)
{
	int iRet = 0;
	int retry = 3;

	ssp_dbg("[SSP] %s, mcu binany update!\n", __func__);
	ssp_enable(data, false);
#if SSP_STATUS_MONITOR
	cancel_delayed_work_sync(&data->polling_work);
#endif

	data->fw_dl_state = FW_DL_STATE_DOWNLOADING;

	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);

	data->spi->max_speed_hz = BOOT_SPI_HZ;
	if (spi_setup(data->spi))
		pr_err("failed to setup spi for ssp_boot\n");

	do {
		pr_info("[SSP] %d try\n", 3 - retry);
		iRet = update_mcu_bin(data, iBinType);
	} while (retry -- > 0 && iRet < 0);

	data->spi->max_speed_hz = NORM_SPI_HZ;
	if (spi_setup(data->spi))
		pr_err("failed to setup spi for ssp_norm\n");

	if (iRet < 0) {
		ssp_dbg("[SSP] %s, update_mcu_bin failed!\n", __func__);
		goto out;
	}

	data->fw_dl_state = FW_DL_STATE_SYNC;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);
	ssp_enable(data, true);

	get_proximity_threshold(data);
	proximity_open_calibration(data);
	accel_open_calibration(data);
	gyro_open_calibration(data);
	pressure_open_calibration(data);

	data->fw_dl_state = FW_DL_STATE_DONE;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);

#if SSP_STATUS_MONITOR
	schedule_delayed_work(&data->polling_work, msecs_to_jiffies(7000));
#endif
	iRet = SUCCESS;
out:
	return iRet;
}
Пример #4
0
int forced_to_download_binary(struct ssp_data *data, int iBinType)
{
    int iRet = 0;
    int retry = 3;

    ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__);

    ssp_enable(data, false);

    data->fw_dl_state = FW_DL_STATE_DOWNLOADING;
    pr_info("[SSP] %s, DL state = %d\n", __func__,
            data->fw_dl_state);
    data->spi->max_speed_hz = BOOT_SPI_HZ;
    if (spi_setup(data->spi))
        pr_err("failed to setup spi for ssp_boot\n");

    do {
        pr_info("[SSP] %d try\n", 3 - retry);
        iRet = update_mcu_bin(data, iBinType);
    } while (retry -- > 0 && iRet < 0);
    data->spi->max_speed_hz = NORM_SPI_HZ;
    if (spi_setup(data->spi))
        pr_err("failed to setup spi for ssp_norm\n");

    if (iRet < 0) {
        ssp_dbg("[SSP]: %s - update_mcu_bin failed!\n", __func__);
        goto out;
    }

    data->fw_dl_state = FW_DL_STATE_SYNC;
    pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);
    ssp_enable(data, true);

    iRet = initialize_mcu(data);
    if (iRet < 0) {
        iRet = ERROR;
        ssp_dbg("[SSP]: %s - initialize_mcu failed!\n", __func__);
        goto out;
    }

    sync_sensor_state(data);

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
    ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_RESET);
#endif

    data->fw_dl_state = FW_DL_STATE_DONE;
    pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);

    iRet = SUCCESS;
out:
    return iRet;
}
int forced_to_download_binary(struct ssp_data *data, int iBinType)
{
	int iRet = 0;
	int retry = 3;

	ssp_dbg("[SSP] %s, mcu binany update!\n", __func__);
	ssp_enable(data, false);

	data->fw_dl_state = FW_DL_STATE_DOWNLOADING;
	data->spi->mode = SPI_MODE_0;

	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);

	data->spi->max_speed_hz = BOOT_SPI_HZ;
	if (spi_setup(data->spi))
		pr_err("failed to setup spi for ssp_boot\n");

	do {
		pr_info("[SSP] %d try\n", 3 - retry);
		iRet = update_mcu_bin(data, iBinType);
		pr_info("======[SSP] SCHEDULE!!!!!\n");
		schedule(); /*Defence for cpu schedule blocking watchdog*/
		msleep(3);
	} while (retry -- > 0 && iRet < 0);

	data->spi->max_speed_hz = NORM_SPI_HZ;
	data->spi->mode = SPI_MODE_1;
	if (spi_setup(data->spi))
		pr_err("failed to setup spi for ssp_norm\n");

	if (iRet < 0) {
		ssp_dbg("[SSP] %s, update_mcu_bin failed!\n", __func__);
		goto out;
	}

	data->fw_dl_state = FW_DL_STATE_SYNC;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);
	ssp_enable(data, true);

	proximity_open_lcd_ldi(data);
	proximity_open_calibration(data);
	accel_open_calibration(data);
	gyro_open_calibration(data);
	pressure_open_calibration(data);

	data->fw_dl_state = FW_DL_STATE_DONE;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);

	iRet = SUCCESS;
out:
	return iRet;
}
Пример #6
0
static void debug_work_func(struct work_struct *work)
{
	unsigned int uSensorCnt;
	struct ssp_data *data = container_of(work, struct ssp_data, work_debug);

	ssp_dbg("[SSP]: %s(%u) - Sensor state: 0x%x, RC: %u, CC: %u, TC: %u\n", 
		__func__, data->uIrqCnt, data->uSensorState, data->uResetCnt,
		data->uComFailCnt, data->uTimeOutCnt);

	for (uSensorCnt = 0; uSensorCnt < SENSOR_MAX; uSensorCnt++)
		if ((atomic_read(&data->aSensorEnable) & (1 << uSensorCnt))
			|| data->batchLatencyBuf[uSensorCnt])
			print_sensordata(data, uSensorCnt);

	if (((atomic_read(&data->aSensorEnable) & (1 << ACCELEROMETER_SENSOR))
		&& (data->batchLatencyBuf[ACCELEROMETER_SENSOR] == 0)
		&& (data->uIrqCnt == 0) && (data->uTimeOutCnt > 0))
		|| (data->uTimeOutCnt > LIMIT_TIMEOUT_CNT)) {

		if (data->uResetCnt < LIMIT_RESET_CNT) {
			pr_info("[SSP] : %s - uTimeOutCnt(%u), pending(%u)\n",
				__func__, data->uTimeOutCnt,
				!list_empty(&data->pending_list));
			reset_mcu(data);
		} else
			ssp_enable(data, false);

		data->uTimeOutCnt = 0;
		data->uComFailCnt = 0;
	}

	data->uIrqCnt = 0;
}
Пример #7
0
void spi_format(spi_t *obj, int bits, int mode, int slave) {
    MBED_ASSERT(((bits >= 4) && (bits <= 16)) && ((mode >= 0) && (mode <= 3)));
    ssp_disable(obj);
    
    int polarity = (mode & 0x2) ? 1 : 0;
    int phase = (mode & 0x1) ? 1 : 0;
    
    // set it up
    int DSS = bits - 1;            // DSS (data select size)
    int SPO = (polarity) ? 1 : 0;  // SPO - clock out polarity
    int SPH = (phase) ? 1 : 0;     // SPH - clock out phase
    
    int FRF = 0;                   // FRF (frame format) = SPI
    uint32_t tmp = obj->spi->CR0;
    tmp &= ~(0xFFFF);
    tmp |= DSS << 0
        | FRF << 4
        | SPO << 6
        | SPH << 7;
    obj->spi->CR0 = tmp;
    
    tmp = obj->spi->CR1;
    tmp &= ~(0xD);
    tmp |= 0 << 0                   // LBM - loop back mode - off
        | ((slave) ? 1 : 0) << 2   // MS - master slave mode, 1 = slave
        | 0 << 3;                  // SOD - slave output disable - na
    obj->spi->CR1 = tmp;
    
    ssp_enable(obj);
}
Пример #8
0
void spi_frequency(spi_t *obj, int hz) {
    ssp_disable(obj);

    // SPI1 runs from PCLK2, which runs at SystemCoreClock / 2.  SPI2 and SPI3
    // run from PCLK1, which runs at SystemCoreClock / 4.
    uint32_t PCLK = SystemCoreClock;
    switch ((int)obj->spi) {
        case SPI_1: PCLK = PCLK >> 1; break;
        case SPI_2: PCLK = PCLK >> 2; break;
        case SPI_3: PCLK = PCLK >> 2; break;
    }

    // Choose the baud rate divisor (between 2 and 256)
    uint32_t divisor = PCLK / hz;

    // Find the nearest power-of-2
    divisor = divisor > 0 ? divisor-1 : 0;
    divisor |= divisor >> 1;
    divisor |= divisor >> 2;
    divisor |= divisor >> 4;
    divisor |= divisor >> 8;
    divisor |= divisor >> 16;
    divisor++;

    uint32_t baud_rate = __builtin_ffs(divisor) - 1;
    baud_rate = baud_rate > 0x7 ? 0x7 : baud_rate;

    obj->spi->CR1 &= ~(0x7 << 3);
    obj->spi->CR1 |= baud_rate << 3;

    ssp_enable(obj);
}
Пример #9
0
void spi_frequency(spi_t *obj, int hz) {
    ssp_disable(obj);
   
    uint32_t PCLK = SystemCoreClock;
    
        int prescaler;
    
    for (prescaler = 2; prescaler <= 254; prescaler += 2) {
        int prescale_hz = PCLK / prescaler;
        
        // calculate the divider
        int divider = floor(((float)prescale_hz / (float)hz) + 0.5f);
        
        // check we can support the divider
        if (divider < 256) {
            // prescaler
            obj->spi->CPSR = prescaler;
            
            // divider
            obj->spi->CR0 &= ~(0xFFFF << 8);
            obj->spi->CR0 |= (divider - 1) << 8;
            ssp_enable(obj);
            return;
        }
    }
    error("Couldn't setup requested SPI frequency");
}
Пример #10
0
void spi_format(spi_t *obj, int bits, int mode, int slave) {
    MBED_ASSERT(((bits >= 1) && (bits <= 16)) && ((mode >= 0) && (mode <= 3)));
    ssp_disable(obj);
    
    int polarity = (mode & 0x2) ? 1 : 0;
    int phase = (mode & 0x1) ? 1 : 0;
    
    // set it up
    int DSS = bits - 1;            // DSS (data select size)
    int SPO = (polarity) ? 1 : 0;  // SPO - clock out polarity
    int SPH = (phase) ? 1 : 0;     // SPH - clock out phase
    
    uint32_t tmp = obj->spi->CFG;
    tmp &= ~((1 << 2) | (1 << 4) | (1 << 5));
    tmp |= (SPH << 4) | (SPO << 5) | ((slave ? 0 : 1) << 2);
    obj->spi->CFG = tmp;
    
    // select frame length
    tmp = obj->spi->TXDATCTL;
    tmp &= ~(0xf << 24);
    tmp |= (DSS << 24);
    obj->spi->TXDATCTL = tmp;
    
    ssp_enable(obj);
}
Пример #11
0
static void ssp_shutdown(struct spi_device *spi)
{
	struct ssp_data *data = spi_get_drvdata(spi);

	pr_err("[SSP] %s, data->fw_dl_state[%d]*******************!\n",
			__func__,data->fw_dl_state);
	pr_err("[SSP]  lpm %d recovery \n",lpcharge /*, recovery_mode*/);
	func_dbg();
	if (data->bProbeIsDone == false)
		goto exit;

	disable_debug_timer(data);

	if (data->fw_dl_state >= FW_DL_STATE_SCHEDULED &&
		data->fw_dl_state < FW_DL_STATE_DONE) {
		pr_err("[SSP] %s, cancel_delayed_work_sync state = %d\n",
			__func__, data->fw_dl_state);
		cancel_delayed_work_sync(&data->work_firmware);
	}

	if (SUCCESS != ssp_send_cmd(data, MSG2SSP_AP_STATUS_SHUTDOWN, 0))
		pr_err("[SSP]: %s MSG2SSP_AP_STATUS_SHUTDOWN failed\n",
			__func__);

	ssp_enable(data, false);
	clean_pending_list(data);

#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&data->early_suspend);
#endif

	free_irq(data->iIrq, data);
	gpio_free(data->mcu_int1);

	remove_event_symlink(data);
	remove_sysfs(data);
	remove_input_dev(data);

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	ssp_sensorhub_remove(data);
#endif

	del_timer_sync(&data->debug_timer);
	cancel_work_sync(&data->work_debug);
	cancel_delayed_work_sync(&data->work_refresh);
	destroy_workqueue(data->debug_wq);
	wake_lock_destroy(&data->ssp_wake_lock);
#ifdef CONFIG_SENSORS_SSP_SHTC1
	mutex_destroy(&data->bulk_temp_read_lock);
	mutex_destroy(&data->cp_temp_adc_lock);
#endif
#ifdef CONFIG_SENSORS_SSP_ATMEL
	mutex_destroy(&data->comm_mutex);
	mutex_destroy(&data->pending_mutex);
#endif
	toggle_mcu_reset(data);
	pr_info("[SSP] %s done\n", __func__);
exit:
	kfree(data);
}
int forced_to_download_binary(struct ssp_data *data, int iBinType)
{
	int iRet = 0;
	int retry = 3;

	ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__);

	ssp_enable(data, false);

	data->fw_dl_state = FW_DL_STATE_DOWNLOADING;
	pr_info("[SSP] %s, DL state = %d\n", __func__,
	data->fw_dl_state);
	data->spi->max_speed_hz = BOOT_SPI_HZ;
	if (spi_setup(data->spi))
		pr_err("failed to setup spi for ssp_boot\n");

	do {
		pr_info("[SSP] %d try\n", 3 - retry);
		iRet = update_mcu_bin(data, iBinType);
	} while (retry -- > 0 && iRet < 0);
	data->spi->max_speed_hz = NORM_SPI_HZ;
	if (spi_setup(data->spi))
		pr_err("failed to setup spi for ssp_norm\n");

	if (iRet < 0) {
		ssp_dbg("[SSP]: %s - update_mcu_bin failed!\n", __func__);
		goto out;
	}

	data->fw_dl_state = FW_DL_STATE_SYNC;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);
	ssp_enable(data, true);

	proximity_open_lcd_ldi(data);
	proximity_open_calibration(data);
	accel_open_calibration(data);
	gyro_open_calibration(data);
#ifdef CONFIG_SENSORS_SSP_BMP182
	pressure_open_calibration(data);
#endif
	data->fw_dl_state = FW_DL_STATE_DONE;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);

	iRet = SUCCESS;
out:
	return iRet;
}
Пример #13
0
void RunValidator(SSP_PORT port, const unsigned char ssp_address)
{
    SSP_COMMAND_SETUP ssp_setup;
    SSP_POLL_DATA poll;
    //setup the required information
	ssp_setup.port = port;
	ssp_setup.Timeout = 1000;
	ssp_setup.RetryLevel = 3;
	ssp_setup.SSPAddress = ssp_addressc-coholic/eSSP;
	ssp_setup.EncryptionStatus = NO_ENCRYPTION;

    //check validator is present
	if (ssp_sync(ssp_setup) != SSP_RESPONSE_OK)
	{
	    printf("NO VALIDATOR FOUND\n");
	    return;
	}
	printf ("Validator Found\n");

    //try to setup encryption using the default key
/*
	if (ssp_setup_encryption(&ssp_setup,(unsigned long long)0x123456701234567LL) != SSP_RESPONSE_OK)
        printf("Encryption Failed\n");
    else
        printf("Encryption Setup\n");
*/
    //enable the unit
	if (ssp_enable(ssp_setup) != SSP_RESPONSE_OK)
	{
	    printf("Enable Failed\n");
        return;
	}

    if (ssp_enable_higher_protocol_events(ssp_setup) != SSP_RESPONSE_OK)
    {
        printf("Higher Protocol Failed\n");
        return;
    }

    //set the inhibits (enable all note acceptance)
	if (ssp_set_inhibits(ssp_setup,0xFF,0xFF) != SSP_RESPONSE_OK)
	{
	    printf("Inhibits Failed\n");
        return;
	}

	while (1)
	{
	    //poll the unit
	    if (ssp_poll(ssp_setup,&poll) != SSP_RESPONSE_OK)
        {
            printf("SSP_POLL_ERROR\n");
            return;
        }
	    ParsePoll(&poll, ssp_setup);
        usleep(500000); //500 ms delay between polls
	}

}
Пример #14
0
void reset_mcu(struct ssp_data *data)
{
	ssp_enable(data, false);

	toggle_mcu_reset(data);
	msleep(SSP_SW_RESET_TIME);

	if (initialize_mcu(data) < 0)
		return;

	ssp_enable(data, true);
	sync_sensor_state(data);

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_RESET);
#endif
}
Пример #15
0
int forced_to_download_binary(struct ssp_data *data, int iBinType)
{
	int iRet = 0;
	int retry = 3;

	ssp_infof("mcu binany update!");

	ssp_enable(data, false);

	data->fw_dl_state = FW_DL_STATE_DOWNLOADING;
	ssp_infof("DL state = %d", data->fw_dl_state);
	data->spi->max_speed_hz = BOOT_SPI_HZ;
	if (spi_setup(data->spi))
		ssp_err("failed to setup spi for ssp_boot");
	do {
		ssp_info("%d try", 3 - retry);
		iRet = update_mcu_bin(data, iBinType);
	} while (retry-- > 0 && iRet < 0);

	data->spi->max_speed_hz = NORM_SPI_HZ;

	if (spi_setup(data->spi))
		ssp_err("failed to setup spi for ssp_norm");
	if (iRet < 0) {
		ssp_infof("update_mcu_bin failed!");
		goto out;
	}

	data->fw_dl_state = FW_DL_STATE_SYNC;
	ssp_infof("DL state = %d", data->fw_dl_state);
	ssp_enable(data, true);

	get_proximity_threshold(data);
	proximity_open_calibration(data);
	accel_open_calibration(data);
	gyro_open_calibration(data);
	pressure_open_calibration(data);

	data->fw_dl_state = FW_DL_STATE_DONE;
	ssp_infof("DL state = %d", data->fw_dl_state);

	iRet = SUCCESS;
out:
	return iRet;
}
int forced_to_download_binary(struct ssp_data *data, int iBinType)
{
	int iRet = 0;

	ssp_dbg("[SSP]: %s - mcu binany update!\n", __func__);

	ssp_enable(data, false);

	data->fw_dl_state = FW_DL_STATE_DOWNLOADING;
	pr_info("[SSP] %s, DL state = %d\n", __func__,
	data->fw_dl_state);

	iRet = update_mcu_bin(data, iBinType);
	if (iRet < 0) {
		ssp_dbg("[SSP]: %s - update_mcu_bin failed!\n", __func__);
		goto out;
	}

	data->fw_dl_state = FW_DL_STATE_SYNC;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);
	iRet = initialize_mcu(data);
    if (iRet == ERROR) {
        data->uResetCnt++;
        toggle_mcu_reset(data);
        msleep(SSP_SW_RESET_TIME);
        initialize_mcu(data);
    } else if (iRet < ERROR) {
        pr_err("[SSP]: %s - initialize_mcu failed\n", __func__);
		goto out;
    }

	ssp_enable(data, true);
	sync_sensor_state(data);

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_RESET);
#endif

	data->fw_dl_state = FW_DL_STATE_DONE;
	pr_info("[SSP] %s, DL state = %d\n", __func__, data->fw_dl_state);

	iRet = SUCCESS;
out:
	return iRet;
}
Пример #17
0
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
    int spi_n = get_available_spi();
    if (spi_n == -1) {
        error("No available SPI");
    }
    obj->spi_n = spi_n;
    spi_used |= (1 << spi_n);
    
    obj->spi = (spi_n) ? (LPC_SPI_TypeDef *)(LPC_SPI1_BASE) : (LPC_SPI_TypeDef *)(LPC_SPI0_BASE);
    
    const SWM_Map *swm;
    uint32_t regVal;
    
    swm = &SWM_SPI_SCLK[obj->spi_n];
    regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset);
    LPC_SWM->PINASSIGN[swm->n] = regVal |  (sclk   << swm->offset);
    
    swm = &SWM_SPI_MOSI[obj->spi_n];
    regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset);
    LPC_SWM->PINASSIGN[swm->n] = regVal |  (mosi   << swm->offset);
    
    swm = &SWM_SPI_MISO[obj->spi_n];
    regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset);
    LPC_SWM->PINASSIGN[swm->n] = regVal |  (miso   << swm->offset);
    
    swm = &SWM_SPI_SSEL[obj->spi_n];
    regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset);
    LPC_SWM->PINASSIGN[swm->n] = regVal |  (ssel   << swm->offset);
    
    // clear interrupts
    obj->spi->INTENCLR = 0x3f;
    
    // enable power and clocking
    switch (obj->spi_n) {
        case 0:
            LPC_SYSCON->SYSAHBCLKCTRL |= (1<<11);
            LPC_SYSCON->PRESETCTRL &= ~(0x1<<0);
            LPC_SYSCON->PRESETCTRL |= (0x1<<0);
            break;
        case 1:
            LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
            LPC_SYSCON->PRESETCTRL &= ~(0x1<<1);
            LPC_SYSCON->PRESETCTRL |= (0x1<<1);
            break;
    }
    
    // set default format and frequency
    if (ssel == NC) {
        spi_format(obj, 8, 0, 0);  // 8 bits, mode 0, master
    } else {
        spi_format(obj, 8, 0, 1);  // 8 bits, mode 0, slave
    }
    spi_frequency(obj, 1000000);
    
    // enable the ssp channel
    ssp_enable(obj);
}
Пример #18
0
void spi_frequency(spi_t *obj, int hz) {
    ssp_disable(obj);
    
    uint32_t PCLK = SystemCoreClock;
    
    obj->spi->DIV = PCLK/hz - 1;
    obj->spi->DLY = 0;
    ssp_enable(obj);
}
Пример #19
0
static void ssp_shutdown(struct spi_device *spi)
{
	struct ssp_data *data = spi_get_drvdata(spi);

	pr_err("[SSP] lpm %d recovery\n", lpcharge);
	func_dbg();
	if (data->bProbeIsDone == false)
		goto exit;

	disable_debug_timer(data);

//hoi
//	if (SUCCESS != ssp_send_cmd(data, MSG2SSP_AP_STATUS_SHUTDOWN, 0))
//		pr_err("[SSP]: %s MSG2SSP_AP_STATUS_SHUTDOWN failed\n",
//			__func__);

	ssp_enable(data, false);
	clean_pending_list(data);


#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&data->early_suspend);
#endif

	bbd_register(NULL, NULL);

//hoi
	cancel_work_sync(&data->work_bbd_on_packet);	// should be cancelled before removing iio dev
	destroy_workqueue(data->bbd_on_packet_wq);
	cancel_work_sync(&data->work_bbd_mcu_ready);
	destroy_workqueue(data->bbd_mcu_ready_wq);
//hoi

	remove_event_symlink(data);
	remove_sysfs(data);
	remove_input_dev(data);

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	ssp_sensorhub_remove(data);
#endif

	del_timer_sync(&data->debug_timer);
	cancel_work_sync(&data->work_debug);
	destroy_workqueue(data->debug_wq);
	wake_lock_destroy(&data->ssp_wake_lock);
#ifdef CONFIG_SENSORS_SSP_SHTC1
	mutex_destroy(&data->bulk_temp_read_lock);
	mutex_destroy(&data->cp_temp_adc_lock);
#endif
	mutex_destroy(&data->comm_mutex);
	mutex_destroy(&data->pending_mutex);
	mutex_destroy(&data->enable_mutex);
	pr_info("[SSP] %s done\n", __func__);
exit:
	kfree(data);
}
Пример #20
0
void reset_mcu(struct ssp_data *data)
{
	func_dbg();
	data->uResetCnt++;

	ssp_enable(data, false);
	clean_pending_list(data);

        bbd_mcu_reset();
}
Пример #21
0
static int ad_probe(struct platform_device *pdev)
{
	struct ad7877_platform_data *pdata = pdev->dev.platform_data;
	struct ad7877 *ad;
	int ret;
	int i;

	// Initialize ad data structure.
	ad = kzalloc(sizeof(*ad), GFP_KERNEL);
	if (!ad)
		return -ENOMEM;

	init_completion(&ad->comp);

	ret = request_irq(pdata->dav_irq, davirq
			  , IRQF_DISABLED | IRQF_TRIGGER_FALLING
			  , "ad7877-dav", ad);
	if (ret) {
		kfree(ad);
		return ret;
	}

	ret = ssp_init(&ad->ssp, 1, 0);
	if (ret) {
		printk(KERN_ERR "Unable to register SSP handler!\n");
		free_irq(pdata->dav_irq, ad);
		kfree(ad);
		return ret;
	}
	platform_set_drvdata(pdev, ad);

	ssp_disable(&ad->ssp);
	ssp_config(&ad->ssp, SSCR0_DataSize(16), 0, 0, SSCR0_SerClkDiv(6));
	ssp_enable(&ad->ssp);
	initChip(ad);

	for (i = 0; i < ARRAY_SIZE(acdevs); i++) {
		acdevs[i].sense = sense;

		ret = adc_classdev_register(&pdev->dev, &acdevs[i]);
		if (ret) {
			printk("ad7877: failed to register adc class "
			       "device %s\n", acdevs[i].name);
			goto adc_cdev_register_failed;
		}
	}

	return 0;

adc_cdev_register_failed:
	while (--i >= 0)
		adc_classdev_unregister(&acdevs[i]);

	return ret;
}
Пример #22
0
static void debug_work_func(struct work_struct *work)
{
	unsigned int uSensorCnt;
	struct ssp_data *data = container_of(work, struct ssp_data, work_debug);

	ssp_dbg("[SSP]: %s(%u) - Sensor state: 0x%x, RC: %u, MS: %u\n",
		__func__, data->uIrqCnt, data->uSensorState, data->uResetCnt,
		data->uMissSensorCnt);

	if (data->fw_dl_state >= FW_DL_STATE_DOWNLOADING &&
		data->fw_dl_state < FW_DL_STATE_DONE) {
		pr_info("[SSP] : %s firmware downloading state = %d\n",
			__func__, data->fw_dl_state);
		return;
	} else if (data->fw_dl_state == FW_DL_STATE_FAIL) {
		pr_err("[SSP] : %s firmware download failed = %d\n",
			__func__, data->fw_dl_state);
		return;
	}

	for (uSensorCnt = 0; uSensorCnt < (SENSOR_MAX - 1); uSensorCnt++)
		if (atomic_read(&data->aSensorEnable) & (1 << uSensorCnt))
			print_sensordata(data, uSensorCnt);

	if ((atomic_read(&data->aSensorEnable) & SSP_BYPASS_SENSORS_EN_ALL)\
			&& (data->uIrqCnt == 0))
		data->uIrqFailCnt++;
	else
		data->uIrqFailCnt = 0;

	if (((data->uSsdFailCnt >= LIMIT_SSD_FAIL_CNT)
		|| (data->uInstFailCnt >= LIMIT_INSTRUCTION_FAIL_CNT)
		|| (data->uIrqFailCnt >= LIMIT_IRQ_FAIL_CNT)
		|| ((data->uTimeOutCnt + data->uBusyCnt) > LIMIT_TIMEOUT_CNT))
		&& (data->bSspShutdown == false)) {

		if (data->uResetCnt < LIMIT_RESET_CNT) {
			pr_info("[SSP] : %s - uSsdFailCnt(%u), uInstFailCnt(%u),"\
				"uIrqFailCnt(%u), uTimeOutCnt(%u), uBusyCnt(%u)\n",
				__func__, data->uSsdFailCnt, data->uInstFailCnt, data->uIrqFailCnt,
				data->uTimeOutCnt, data->uBusyCnt);
			reset_mcu(data);
			data->uResetCnt++;
		} else
			ssp_enable(data, false);

		data->uSsdFailCnt = 0;
		data->uInstFailCnt = 0;
		data->uTimeOutCnt = 0;
		data->uBusyCnt = 0;
		data->uIrqFailCnt = 0;
	}

	data->uIrqCnt = 0;
}
Пример #23
0
static void ssp_shutdown(struct spi_device *spi_dev)
{
	struct ssp_data *data = spi_get_drvdata(spi_dev);

	func_dbg();
	if (data->bProbeIsDone == false)
		goto exit;

	if (data->fw_dl_state >= FW_DL_STATE_SCHEDULED &&
		data->fw_dl_state < FW_DL_STATE_DONE) {
		pr_err("%s, cancel_delayed_work_sync state = %d\n",
			__func__, data->fw_dl_state);
		cancel_delayed_work_sync(&data->work_firmware);
	}

	ssp_enable(data, false);
	clean_pending_list(data);

#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&data->early_suspend);
#endif

	disable_debug_timer(data);

	free_irq(data->iIrq, data);
	gpio_free(data->mcu_int1);

	remove_event_symlink(data);
	remove_sysfs(data);
	remove_input_dev(data);

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	ssp_sensorhub_remove(data);
#endif

	del_timer_sync(&data->debug_timer);
	cancel_work_sync(&data->work_debug);
	destroy_workqueue(data->debug_wq);
	wake_lock_destroy(&data->ssp_wake_lock);
#ifdef CONFIG_SENSORS_SSP_SHTC1
	mutex_destroy(&data->cp_temp_adc_lock);
	mutex_destroy(&data->bulk_temp_read_lock);
#endif
	mutex_destroy(&data->comm_mutex);
	mutex_destroy(&data->pending_mutex);
#if defined(CONFIG_MACH_VIKALCU)
	proximity_ldo_enable(0);
#endif
	toggle_mcu_reset(data);
/*	gpio_set_value_cansleep(data->rst, 0); */
	pr_info("[SSP]: %s done\n", __func__);
exit:
	kfree(data);
}
Пример #24
0
static int a716_ssp_resume(struct platform_device *pdev)
{
	a716_gpo_set(0x4000);

	ssp_restore_state(&a716_ssp_dev, &a716_ssp_state);
	ssp_enable(&a716_ssp_dev);

	irq_disable = 0;
	touch_pressed = 0;
	enable_irq(IRQ_GPIO(GPIO_NR_A716_STYLUS_IRQ_N));

	return 0;
}
Пример #25
0
static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
{
	struct ssp_priv *priv = cpu_dai->private_data;

	if (!cpu_dai->active)
		return 0;

	clk_enable(priv->dev.ssp->clk);
	ssp_restore_state(&priv->dev, &priv->state);
	ssp_enable(&priv->dev);

	return 0;
}
Пример #26
0
static void recovery_mcu(struct ssp_data *data)
{
	if (data->uComFailCnt < LIMIT_RESET_CNT) {
		ssp_infof("- uTimeOutCnt(%u), pending(%u)",
			data->uTimeOutCnt, !list_empty(&data->pending_list));
		data->uComFailCnt++;
		reset_mcu(data);
	} else {
		ssp_enable(data, false);
	}

	data->uTimeOutCnt = 0;
}
Пример #27
0
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
    // determine the SPI to use
    SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI);
    SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO);
    SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK);
    SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL);
    SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso);
    SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel);
    obj->spi = (SPI_TypeDef*)pinmap_merge(spi_data, spi_cntl);
    MBED_ASSERT((int)obj->spi != NC)

    // enable power and clocking
    switch ((int)obj->spi) {
        case SPI_1:
            RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN;
            RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
            break;
        case SPI_2:
            RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN;
            RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
            break;
        case SPI_3:
            RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN;
            RCC->APB1ENR |= RCC_APB1ENR_SPI3EN;
            break;
    }
    

    // set default format and frequency
    if (ssel == NC) {
        spi_format(obj, 8, 0, 0);  // 8 bits, mode 0, master
    } else {
        spi_format(obj, 8, 0, 1);  // 8 bits, mode 0, slave
    }
    spi_frequency(obj, 1000000);
    
    // enable the ssp channel
    ssp_enable(obj);

    // pin out the spi pins
    pinmap_pinout(mosi, PinMap_SPI_MOSI);
    pinmap_pinout(miso, PinMap_SPI_MISO);
    pinmap_pinout(sclk, PinMap_SPI_SCLK);
    if (ssel != NC) {
        pinmap_pinout(ssel, PinMap_SPI_SSEL);
    }
    else {
        // Use software slave management
        obj->spi->CR1 |= SPI_CR1_SSM | SPI_CR1_SSI;
    }
}
Пример #28
0
void reset_mcu(struct ssp_data *data)
{
	func_dbg();
	ssp_enable(data, false);

	clean_pending_list(data);
	toggle_mcu_reset(data);
	msleep(SSP_SW_RESET_TIME);
	ssp_enable(data, true);

	if (initialize_mcu(data) < 0)
		return;

	sync_sensor_state(data);

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	ssp_sensorhub_report_notice(data, MSG2SSP_AP_STATUS_RESET);
#endif
	if (data->uLastAPState != 0)
		ssp_send_cmd(data, data->uLastAPState, 0);
	if (data->uLastResumeState != 0)
		ssp_send_cmd(data, data->uLastResumeState, 0);
}
void reset_mcu(struct ssp_data *data) {
#if SSP_STATUS_MONITOR
	data->bRefreshing = true;
#endif

	func_dbg();
	ssp_enable(data, false);
	clean_pending_list(data);
#if SSP_STATUS_MONITOR
	if( (data->reg_hub) && ((current_cable_type==POWER_SUPPLY_TYPE_MAINS)
		|| (current_cable_type==POWER_SUPPLY_TYPE_HV_MAINS)))
		toggle_mcu_hw_reset(data);
	else
#endif
		toggle_mcu_reset(data);
	ssp_enable(data, true);

#if SSP_STATUS_MONITOR
	if((data->reg_hub) && ( (current_cable_type==POWER_SUPPLY_TYPE_MAINS)
		|| (current_cable_type==POWER_SUPPLY_TYPE_HV_MAINS)))
		queue_refresh_task(data, 0);
#endif
}
Пример #30
0
void palmtt3_ssp_init(void)
{
	printk(KERN_WARNING "palmtt3_tsc2101: Resetting SSP, move this to garux?\n");
	SSCR0 &= ~SSCR0_SSE;
	SSCR1 = SSCR1 & 0x3FFC;

	if (ssp_init(&palmtt3_ssp_dev, 1, 0))
		printk(KERN_ERR "palmtt3_tsc2101: Unable to register SSP handler!\n");
	else {
		ssp_enable(&palmtt3_ssp_dev);
		printk(KERN_INFO "palmtt3_tsc2101: SSP device initialized\n");
	}

	return;
}