void sync_sensor_state(struct ssp_data *data)
{
	unsigned char uBuf[9] = {0,};
	unsigned int uSensorCnt;
	int iRet = 0;

	iRet = set_gyro_cal(data);
	if (iRet < 0)
		ssp_errf("set_gyro_cal failed");

	iRet = set_accel_cal(data);
	if (iRet < 0)
		ssp_errf("set_accel_cal failed");

	udelay(10);

	for (uSensorCnt = 0; uSensorCnt < SENSOR_MAX; uSensorCnt++) {
		if (atomic64_read(&data->aSensorEnable) & (1 << uSensorCnt)) {
			s32 dMsDelay
				= get_msdelay(data->adDelayBuf[uSensorCnt]);
			memcpy(&uBuf[0], &dMsDelay, 4);
			memcpy(&uBuf[4], &data->batchLatencyBuf[uSensorCnt], 4);
			uBuf[8] = data->batchOptBuf[uSensorCnt];
			send_instruction(data, ADD_SENSOR, uSensorCnt, uBuf, 9);
			udelay(10);
		}
	}

	if (data->bProximityRawEnabled == true) {
		s32 dMsDelay = 20;
		memcpy(&uBuf[0], &dMsDelay, 4);
		send_instruction(data, ADD_SENSOR, PROXIMITY_RAW, uBuf, 4);
	}

	set_proximity_threshold(data, data->uProxHiThresh, data->uProxLoThresh);
	data->buf[PROXIMITY_SENSOR].prox = 0;
	report_sensordata(data, PROXIMITY_SENSOR, &data->buf[PROXIMITY_SENSOR]);

#if 1
    if(sec_debug_get_debug_level() > 0)
    {
        data->bMcuDumpMode = true;
        ssp_info("Mcu Dump Enabled");
    }

    iRet = ssp_send_cmd(data, MSG2SSP_AP_MCU_SET_DUMPMODE,
            data->bMcuDumpMode);
    if (iRet < 0)
        ssp_errf("MSG2SSP_AP_MCU_SET_DUMPMODE failed");

#else
#if CONFIG_SEC_DEBUG   
	data->bMcuDumpMode = sec_debug_is_enabled();
	iRet = ssp_send_cmd(data, MSG2SSP_AP_MCU_SET_DUMPMODE,
			data->bMcuDumpMode);
	if (iRet < 0)
		ssp_errf("MSG2SSP_AP_MCU_SET_DUMPMODE failed");
#endif
#endif
}
Exemple #2
0
static void initialize_variable(struct ssp_data *data)
{
	int iSensorIndex;

	for (iSensorIndex = 0; iSensorIndex < SENSOR_MAX; iSensorIndex++) {
		data->adDelayBuf[iSensorIndex] = DEFUALT_POLLING_DELAY;
		data->aiCheckStatus[iSensorIndex] = INITIALIZATION_STATE;
	}

	data->uSensorState = NORMAL_SENSOR_STATE_K;
	data->uMagCntlRegData = 1;

	data->bSspShutdown = true;
	data->bTimeSyncing = true;

	data->buf[GYROSCOPE_SENSOR].gyro_dps = GYROSCOPE_DPS2000;
	data->uIr_Current = DEFUALT_IR_CURRENT;

#if CONFIG_SEC_DEBUG
	data->bMcuDumpMode = sec_debug_is_enabled();
#endif
	INIT_LIST_HEAD(&data->pending_list);

	initialize_function_pointer(data);
}
/* Writing magic no for thermal reset detection */
void sec_debug_prepare_for_thermal_reset(void)
{
    if(sec_debug_is_enabled())
    {
        sec_debug_set_upload_magic(SECDEBUG_MODE);
        sec_debug_set_upload_cause(UPLOAD_CAUSE_POWER_THERMAL_RESET);
    }
}
void sec_debug_prepare_for_wdog_bark_reset(void)
{
    if(sec_debug_is_enabled())
    {
        sec_debug_set_upload_magic(SECDEBUG_MODE);
        sec_debug_set_upload_cause(UPLOAD_CAUSE_NON_SECURE_WDOG_BARK);
    }
}
Exemple #5
0
void printk_remap_nocache(void)
{
	unsigned long long nocache_base = 0;
	unsigned *sec_log_mag;
	unsigned long flags;
	unsigned start;

#if 1
	if( 0 == sec_debug_is_enabled() ) {
		sec_getlog_supply_kloginfo(log_buf);
		return;
	}
#endif

	pr_err("%s: sec_log_save_size %d at sec_log_save_base 0x%x \n", 
		__func__, sec_log_save_size, (unsigned int)sec_log_save_base);
	pr_err("%s: sec_log_reserve_size %d at sec_log_reserve_base 0x%x \n", 
		__func__, sec_log_reserve_size, (unsigned int)sec_log_reserve_base);
#if 0
	free_bootmem(sec_log_reserve_base, sec_log_reserve_size);
#endif

	nocache_base = ioremap_nocache(sec_log_save_base - 4096, sec_log_save_size + 8192);
	nocache_base = nocache_base + 4096;

	sec_log_mag = nocache_base - 8;
	sec_log_ptr = nocache_base - 4;
	sec_log_buf = nocache_base;
	sec_log_size = sec_log_save_size;
	sec_log_irq_en = nocache_base - 0xC ;

#if 0
	pr_err("%s: sec_log_save_size %d at sec_log_save_base 0x%x \n", 
		__func__, sec_log_save_size, (unsigned int)sec_log_save_base);
	pr_err("%s: nocache_base %x "
	       " sec_log_mag:0x%x "
	       "at sec_log_ptr 0x%x "
	       "at sec_log_buf 0x%p \n", __func__, 
	       nocache_base, *sec_log_mag, *sec_log_ptr, sec_log_buf);
#endif

	spin_lock_irqsave(&logbuf_lock, flags);
	if (*sec_log_mag != LOG_MAGIC) {
		*sec_log_ptr = 0;
		*sec_log_mag = LOG_MAGIC;
	}

	start = min(con_start, log_start);
	while (start != log_end) {
		emit_sec_log_char(__log_buf
				  [start++ & (__LOG_BUF_LEN - 1)]);
	}

	spin_unlock_irqrestore(&logbuf_lock, flags);

	sec_getlog_supply_kloginfo(sec_log_buf);
}
void sync_sensor_state(struct ssp_data *data)
{
	unsigned char uBuf[9] = {0,};
	unsigned int uSensorCnt;
	int iRet = 0;
#ifdef CONFIG_SENSORS_SSP_YAS532
	iRet = set_hw_offset(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - set_hw_offset failed\n", __func__);
	}
#endif
	iRet = set_gyro_cal(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - set_gyro_cal failed\n", __func__);
	}
	iRet = set_accel_cal(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - set_accel_cal failed\n", __func__);
	}
	udelay(10);

	for (uSensorCnt = 0; uSensorCnt < SENSOR_MAX; uSensorCnt++) {
		if (atomic_read(&data->aSensorEnable) & (1 << uSensorCnt)) {
			s32 dMsDelay = get_msdelay(data->adDelayBuf[uSensorCnt]);
			memcpy(&uBuf[0], &dMsDelay, 4);
			memcpy(&uBuf[4], &data->batchLatencyBuf[uSensorCnt], 4);
			uBuf[8] = data->batchOptBuf[uSensorCnt];
			send_instruction(data, ADD_SENSOR, uSensorCnt, uBuf, 9);
			udelay(10);
		}
	}

	if (data->bProximityRawEnabled == true) {
		s32 dMsDelay = 20;
		memcpy(&uBuf[0], &dMsDelay, 4);
		send_instruction(data, ADD_SENSOR, PROXIMITY_RAW, uBuf, 4);
	}

	set_proximity_threshold(data, data->uProxHiThresh,data->uProxLoThresh);

#if SSP_SEC_DEBUG
	data->bMcuDumpMode = sec_debug_is_enabled();
	iRet = ssp_send_cmd(data, MSG2SSP_AP_MCU_SET_DUMPMODE,data->bMcuDumpMode);
	if (iRet < 0) {
		pr_err("[SSP]: %s - MSG2SSP_AP_MCU_SET_DUMPMODE failed\n", __func__);
	}
#endif
}
int initialize_mcu(struct ssp_data *data)
{
	int iRet = 0;

	iRet = get_chipid(data);
	pr_info("[SSP] MCU device ID = %d, reading ID = %d\n", DEVICE_ID, iRet);
	if (iRet != DEVICE_ID) {
		if (iRet < 0) {
			pr_err("[SSP]: %s - MCU is not working : 0x%x\n",
				__func__, iRet);
		} else {
			pr_err("[SSP]: %s - MCU identification failed\n",
				__func__);
			iRet = -ENODEV;
		}
		goto out;
	}

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

	data->uSensorState = get_sensor_scanning_info(data);
	if (data->uSensorState == 0) {
		pr_err("[SSP]: %s - get_sensor_scanning_info failed\n",
			__func__);
		iRet = ERROR;
		goto out;
	}

	iRet = ssp_send_cmd(data, MSG2SSP_AP_MCU_SET_DUMPMODE,
			sec_debug_is_enabled());
	if (iRet < 0) {
		pr_err("[SSP]: %s - set_mcu_dump_mode failed\n", __func__);
		goto out;
	}

#if defined (CONFIG_SENSORS_SSP_YAS532)
	iRet = set_static_matrix(data);
	if (iRet < 0)
		pr_err("[SSP]: %s - yas set static matrix failed\n", __func__);
#endif
	iRet = SUCCESS;
out:
	return iRet;
}
void sync_sensor_state(struct ssp_data *data)
{
	unsigned char uBuf[2] = {0,};
	unsigned int uSensorCnt;
	int iRet = 0;
	iRet = set_hw_offset(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - set_hw_offset failed\n", __func__);
	}
	iRet = set_gyro_cal(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - set_gyro_cal failed\n", __func__);
	}
	iRet = set_accel_cal(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - set_accel_cal failed\n", __func__);
	}
	udelay(10);

	for (uSensorCnt = 0; uSensorCnt < (SENSOR_MAX - 1); uSensorCnt++) {
		if (atomic_read(&data->aSensorEnable) & (1 << uSensorCnt)) {
			uBuf[1] = (u8)get_msdelay(data->adDelayBuf[uSensorCnt]);
			uBuf[0] = (u8)get_delay_cmd(uBuf[1]);
			send_instruction(data, ADD_SENSOR, uSensorCnt, uBuf, 2);
			udelay(10);
		}
	}

	if (data->bProximityRawEnabled == true) {
		uBuf[0] = 1;
		uBuf[1] = 20;
		send_instruction(data, ADD_SENSOR, PROXIMITY_RAW, uBuf, 2);
	}

	set_proximity_threshold(data, data->uProxHiThresh,data->uProxLoThresh);
	


	data->bMcuDumpMode = sec_debug_is_enabled();
	iRet = ssp_send_cmd(data, MSG2SSP_AP_MCU_SET_DUMPMODE,data->bMcuDumpMode);
	if (iRet < 0) {
		pr_err("[SSP]: %s - MSG2SSP_AP_MCU_SET_DUMPMODE failed\n", __func__);
	}


}
Exemple #9
0
static int __init printk_remap_nocache(void)
{
	void __iomem *nocache_base = 0;
	unsigned *sec_log_mag;
	unsigned long flags;
	unsigned start;
	int rc = 0;

	sec_getlog_supply_kloginfo(log_buf);

	if (0 == sec_debug_is_enabled()) {
#ifdef CONFIG_SEC_SSR_DUMP
		nocache_base = ioremap_nocache(sec_log_save_base - 4096,
		sec_log_save_size + 8192);
		nocache_base = nocache_base + 4096;
		sec_log_mag = nocache_base - 8;
		sec_log_ptr = nocache_base - 4;
		sec_log_buf = nocache_base;
		ramdump_kernel_log_addr = sec_log_ptr;
		pr_debug("ramdump_kernel_log_addr = 0x%x\n",
		ramdump_kernel_log_addr);
		sec_log_size = sec_log_save_size;
		sec_log_irq_en = nocache_base - 0xC ;
#endif

#ifdef CONFIG_SEC_DEBUG_LOW_LOG
		nocache_base = ioremap_nocache(sec_log_save_base - 4096,
		sec_log_save_size + 8192);
		nocache_base = nocache_base + 4096;

		sec_log_mag = nocache_base - 8;
		sec_log_ptr = nocache_base - 4;
		sec_log_buf = nocache_base;
		sec_log_size = sec_log_save_size;
		sec_log_irq_en = nocache_base - 0xC ;
#endif
		return rc;
	}
	pr_err("%s: sec_log_save_size %d at sec_log_save_base 0x%x\n",
	__func__, sec_log_save_size, (unsigned int)sec_log_save_base);
	pr_err("%s: sec_log_reserve_size %d at sec_log_reserve_base 0x%x\n",
	__func__, sec_log_reserve_size, (unsigned int)sec_log_reserve_base);

	nocache_base = ioremap_nocache(sec_log_save_base - 4096,
					sec_log_save_size + 8192);
	nocache_base = nocache_base + 4096;

	sec_log_mag = nocache_base - 8;
	sec_log_ptr = nocache_base - 4;
	sec_log_buf = nocache_base;
#ifdef CONFIG_SEC_SSR_DUMP
		ramdump_kernel_log_addr = sec_log_ptr;
		pr_info("%s: ramdump_kernel_log_addr = 0x%x\n",
		__func__, ramdump_kernel_log_addr);
#endif
	sec_log_size = sec_log_save_size;
	sec_log_irq_en = nocache_base - 0xC ;

	spin_lock_irqsave(&logbuf_lock, flags);
	if (*sec_log_mag != LOG_MAGIC) {
		*sec_log_ptr = 0;
		*sec_log_mag = LOG_MAGIC;
	}

	start = min(con_start, log_start);
	while (start != log_end) {
		emit_sec_log_char(__log_buf
				  [start++ & (__LOG_BUF_LEN - 1)]);
	}

	spin_unlock_irqrestore(&logbuf_lock, flags);
	return rc;
}
Exemple #10
0
static void initialize_variable(struct ssp_data *data)
{
	int iSensorIndex;

	for (iSensorIndex = 0; iSensorIndex < SENSOR_MAX; iSensorIndex++) {
		data->adDelayBuf[iSensorIndex] = DEFUALT_POLLING_DELAY;
		data->batchLatencyBuf[iSensorIndex] = 0;
		data->batchOptBuf[iSensorIndex] = 0;
		data->aiCheckStatus[iSensorIndex] = INITIALIZATION_STATE;
	}

	atomic_set(&data->aSensorEnable, 0);
	data->iLibraryLength = 0;
	data->uSensorState = 0;
	data->uFactoryProxAvg[0] = 0;
	data->uMagCntlRegData = 1;

	data->uResetCnt = 0;
	data->uInstFailCnt = 0;
	data->uTimeOutCnt = 0;
	data->uSsdFailCnt = 0;
	data->uIrqCnt = 0;
	data->uIrqFailCnt = 0;
	data->uMissSensorCnt = 0;

	data->bSspShutdown = true;
	data->bProximityRawEnabled = false;
	data->bGeomagneticRawEnabled = false;
	data->bBarcodeEnabled = false;
	data->bAccelAlert = false;
	data->bTimeSyncing = true;

	data->accelcal.x = 0;
	data->accelcal.y = 0;
	data->accelcal.z = 0;

	data->gyrocal.x = 0;
	data->gyrocal.y = 0;
	data->gyrocal.z = 0;

	data->magoffset.x = 0;
	data->magoffset.y = 0;
	data->magoffset.z = 0;

	data->iPressureCal = 0;
	data->uProxCanc = 0;
	data->uProxHiThresh = 0;
	data->uProxLoThresh = 0;
	data->uGyroDps = GYROSCOPE_DPS500;
	data->uIr_Current = 0;

	data->mcu_device = NULL;
	data->acc_device = NULL;
	data->gyro_device = NULL;
	data->mag_device = NULL;
	data->prs_device = NULL;
	data->prox_device = NULL;
	data->light_device = NULL;
	data->ges_device = NULL;

	data->voice_device = NULL;
#if SSP_SEC_DEBUG
	data->bMcuDumpMode = sec_debug_is_enabled();
#endif
	INIT_LIST_HEAD(&data->pending_list);

	data->step_count_total = 0;
	initialize_function_pointer(data);
}
Exemple #11
0
static int __devinit
qpnp_pon_request_irqs(struct qpnp_pon *pon, struct qpnp_pon_config *cfg)
{
	int rc = 0;

	switch (cfg->pon_type) {
	case PON_KPDPWR:
#if CONFIG_SEC_DEBUG
		if (sec_debug_is_enabled()) {
			rc = qpnp_pon_input_dispatch(pon, PON_KPDPWR);
			if (rc)
				dev_err(&pon->spmi->dev, "Fail to first check to send input event\n");
		}
#endif
		rc = devm_request_irq(&pon->spmi->dev, cfg->state_irq,
							qpnp_kpdpwr_irq,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
						"qpnp_kpdpwr_status", pon);
		if (rc < 0) {
			dev_err(&pon->spmi->dev, "Can't request %d IRQ\n",
							cfg->state_irq);
			return rc;
		}
		if (cfg->support_reset) {
			rc = devm_request_irq(&pon->spmi->dev, cfg->bark_irq,
						qpnp_kpdpwr_bark_irq,
						IRQF_TRIGGER_RISING,
						"qpnp_kpdpwr_bark", pon);
			if (rc < 0) {
				dev_err(&pon->spmi->dev,
					"Can't request %d IRQ\n",
						cfg->bark_irq);
				return rc;
			}
		}
		break;
	case PON_RESIN:
		rc = devm_request_irq(&pon->spmi->dev, cfg->state_irq,
							qpnp_resin_irq,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
						"qpnp_resin_status", pon);
		if (rc < 0) {
			dev_err(&pon->spmi->dev, "Can't request %d IRQ\n",
							cfg->state_irq);
			return rc;
		}
		if (cfg->support_reset) {
			rc = devm_request_irq(&pon->spmi->dev, cfg->bark_irq,
						qpnp_resin_bark_irq,
						IRQF_TRIGGER_RISING,
						"qpnp_resin_bark", pon);
			if (rc < 0) {
				dev_err(&pon->spmi->dev,
					"Can't request %d IRQ\n",
						cfg->bark_irq);
				return rc;
			}
		}
		break;
	case PON_CBLPWR:
		rc = devm_request_irq(&pon->spmi->dev, cfg->state_irq,
							qpnp_cblpwr_irq,
				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
					"qpnp_cblpwr_status", pon);
		if (rc < 0) {
			dev_err(&pon->spmi->dev, "Can't request %d IRQ\n",
							cfg->state_irq);
			return rc;
		}
		break;
	default:
		return -EINVAL;
	}

	/* mark the interrupts wakeable if they support linux-key */
	if (cfg->key_code) {
		enable_irq_wake(cfg->state_irq);
		/* special handling for RESIN due to a hardware bug */
		if (cfg->pon_type == PON_RESIN && cfg->support_reset)
			enable_irq_wake(cfg->bark_irq);
	}

	return rc;
}
Exemple #12
0
static int __devinit qpnp_pon_probe(struct spmi_device *spmi)
{
	struct qpnp_pon *pon;
	struct resource *pon_resource;
	struct device_node *itr = NULL;
	u32 delay = 0;
	int rc, sys_reset;
	struct device *sec_powerkey;
#ifdef CONFIG_SEC_PM
	struct device *sec_power;
#endif
    	int ret;
	pon = devm_kzalloc(&spmi->dev, sizeof(struct qpnp_pon),
							GFP_KERNEL);
	if (!pon) {
		dev_err(&spmi->dev, "Can't allocate qpnp_pon\n");
		return -ENOMEM;
	}

	sys_reset = of_property_read_bool(spmi->dev.of_node,
						"qcom,system-reset");
	if (sys_reset && sys_reset_dev) {
		dev_err(&spmi->dev, "qcom,system-reset property can only be specified for one device on the system\n");
		return -EINVAL;
	} else if (sys_reset) {
		sys_reset_dev = pon;
	}

	pon->spmi = spmi;

	/* get the total number of pon configurations */
	while ((itr = of_get_next_child(spmi->dev.of_node, itr)))
		pon->num_pon_config++;

	if (!pon->num_pon_config) {
		/* No PON config., do not register the driver */
		dev_err(&spmi->dev, "No PON config. specified\n");
		return -EINVAL;
	}

	pon->pon_cfg = devm_kzalloc(&spmi->dev,
			sizeof(struct qpnp_pon_config) * pon->num_pon_config,
								GFP_KERNEL);

	pon_resource = spmi_get_resource(spmi, NULL, IORESOURCE_MEM, 0);
	if (!pon_resource) {
		dev_err(&spmi->dev, "Unable to get PON base address\n");
		return -ENXIO;
	}
	pon->base = pon_resource->start;

	rc = of_property_read_u32(pon->spmi->dev.of_node,
				"qcom,pon-dbc-delay", &delay);
	if (rc) {
		if (rc != -EINVAL) {
			dev_err(&spmi->dev, "Unable to read debounce delay\n");
			return rc;
		}
	} else {
		delay = (delay << QPNP_PON_DELAY_BIT_SHIFT) / USEC_PER_SEC;
		delay = ilog2(delay);
		rc = qpnp_pon_masked_write(pon, QPNP_PON_DBC_CTL(pon->base),
						QPNP_PON_DBC_DELAY_MASK, delay);
		if (rc) {
			dev_err(&spmi->dev, "Unable to set PON debounce\n");
			return rc;
		}
	}

	dev_set_drvdata(&spmi->dev, pon);

	INIT_DELAYED_WORK(&pon->bark_work, bark_work_func);

	/* register the PON configurations */
	rc = qpnp_pon_config_init(pon);
	if (rc) {
		dev_err(&spmi->dev,
			"Unable to intialize PON configurations\n");
		return rc;
	}

#ifdef CONFIG_CONTROL_S2_RESET
	if (0 == sec_debug_is_enabled())
		qpnp_control_s2_reset(0);
#endif

#ifdef CONFIG_SEC_PM
	qpnp_control_s3_reset_timer();
	
	sec_power = device_create(sec_class, NULL, 0, NULL, "sec_power");
	if (IS_ERR(sec_power))
		pr_err("Failed to create device(sec_power)!\n");
	ret = device_create_file(sec_power, &dev_attr_enable_hw_reset);
	if (ret) {
		pr_err("Failed to create device file in sysfs entries(%s)!\n",
			dev_attr_enable_hw_reset.attr.name);
	}
	dev_set_drvdata(sec_power, pon);
#endif

	sec_powerkey = device_create(sec_class, NULL, 0, NULL, "sec_powerkey");
	if (IS_ERR(sec_powerkey))
		pr_err("Failed to create device(sec_powerkey)!\n");
	ret = device_create_file(sec_powerkey, &dev_attr_sec_powerkey_pressed);
	if (ret) {
		pr_err("Failed to create device file in sysfs entries(%s)!\n",
			dev_attr_sec_powerkey_pressed.attr.name);
	}
	dev_set_drvdata(sec_powerkey, pon);

	return rc;
}
Exemple #13
0
struct apr_svc_ch_dev *apr_tal_open(uint32_t svc, uint32_t dest,
				uint32_t dl, apr_svc_cb_fn func, void *priv)
{
	int rc;

	if ((svc >= APR_CLIENT_MAX) || (dest >= APR_DEST_MAX) ||
						(dl >= APR_DL_MAX)) {
		pr_err("apr_tal: Invalid params\n");
		return NULL;
	}

	if (apr_svc_ch[dl][dest][svc].ch) {
		pr_err("apr_tal: This channel alreday openend\n");
		return NULL;
	}

	mutex_lock(&apr_svc_ch[dl][dest][svc].m_lock);
	if (!apr_svc_ch[dl][dest][svc].dest_state) {
		rc = wait_event_timeout(apr_svc_ch[dl][dest][svc].dest,
			apr_svc_ch[dl][dest][svc].dest_state,
				msecs_to_jiffies(APR_OPEN_TIMEOUT_MS));
		if (rc == 0) {
			pr_err("apr_tal:open timeout\n");
			mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock);
			apr_tal_close(&apr_svc_ch[dl][dest][svc]);
#if defined(WORKAROUND_FOR_Q6_FAILURE) && defined(CONFIG_SEC_DEBUG)
			if (!sec_debug_is_enabled()) {
				kernel_restart(NULL);
			}
#endif
			return NULL;
		}
		pr_debug("apr_tal:Wakeup done\n");
		apr_svc_ch[dl][dest][svc].dest_state = 0;
	}
	rc = smd_named_open_on_edge(svc_names[dest][svc], dest,
			&apr_svc_ch[dl][dest][svc].ch,
			&apr_svc_ch[dl][dest][svc],
			apr_tal_notify);
	if (rc < 0) {
		pr_err("apr_tal: smd_open failed %s\n",
					svc_names[dest][svc]);
		mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock);
		return NULL;
	}
	rc = wait_event_timeout(apr_svc_ch[dl][dest][svc].wait,
		(apr_svc_ch[dl][dest][svc].smd_state == 1), 5 * HZ);
	if (rc == 0) {
		pr_err("apr_tal:TIMEOUT for OPEN event\n");
		mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock);
		apr_tal_close(&apr_svc_ch[dl][dest][svc]);
#if defined(WORKAROUND_FOR_Q6_FAILURE) && defined(CONFIG_SEC_DEBUG)
		if (!sec_debug_is_enabled()) {
			kernel_restart(NULL);
		}
#endif
		return NULL;
	}
	if (!apr_svc_ch[dl][dest][svc].dest_state) {
		apr_svc_ch[dl][dest][svc].dest_state = 1;
		pr_debug("apr_tal:Waiting for apr svc init\n");
		msleep(200);
		pr_debug("apr_tal:apr svc init done\n");
	}
	apr_svc_ch[dl][dest][svc].smd_state = 0;

	apr_svc_ch[dl][dest][svc].func = func;
	apr_svc_ch[dl][dest][svc].priv = priv;
	mutex_unlock(&apr_svc_ch[dl][dest][svc].m_lock);

	return &apr_svc_ch[dl][dest][svc];
}
Exemple #14
0
 static int __init mdss_debug_init(void) {
#else
 int  mdss_debug_init(void) {
#endif
		
		u32 log_buff_len = 500*1024 - sizeof(struct debug_mdp);
		struct dentry *dent = debugfs_create_dir("dlog", NULL);
		dump_size = log_buff_len + sizeof(struct debug_mdp);
#ifdef __KERNEL__
		if(__debug_mdp_phys){
			debug_mdp = ioremap_nocache(__debug_mdp_phys,CARVEOUT_MEM_SIZE);
			pr_info("Using MDSS debug memory from LK:Phys: %x,  VA: %p\n",__debug_mdp_phys,debug_mdp);
			
		}
			
		if(!__debug_mdp_phys || !debug_mdp) {
			debug_mdp = kzalloc (dump_size, GFP_KERNEL);
			if(!debug_mdp) {
				pr_err("Memory allocation failed for MDP DEBUG MODULE\n");
				return -1;
			}
		} 
		//debug_mdp->log_buff.offset = 0;
		
		pr_info(KERN_INFO "MDP debug init:debug_mdp: %p \n",debug_mdp);


#else
		debug_mdp = __debug_mdp_phys;

		memset(debug_mdp,0x0,CARVEOUT_MEM_SIZE);

#endif
		if(!__debug_mdp_phys || (__debug_mdp_phys == (u32)debug_mdp)){
			debug_mdp->log_buff.len = log_buff_len; 
			
#if defined(DLOG_USER_VARIANT)
	#if defined(CONFIG_SEC_DEBUG)
					sec_debug_level = sec_debug_is_enabled();
					if(sec_debug_level) 
	#else
					if(1)
	#endif
#endif
{
			u32 event_desc_len = 10*1024;
			u32 reg_log_len = 10*11*1024;
			u32 clock_state_len = 2*1024;
			dump_size =  dump_size + event_desc_len + reg_log_len  \
					+ clock_state_len ;
			debug_mdp->event_desc.offset = debug_mdp->log_buff.offset + debug_mdp->log_buff.len;
			debug_mdp->event_desc.len = event_desc_len;   
			
			debug_mdp->reg_log.offset = debug_mdp->event_desc.offset + debug_mdp->event_desc.len;
			debug_mdp->reg_log.len = reg_log_len;

			debug_mdp->clock_state.offset = debug_mdp->reg_log.offset + debug_mdp->reg_log.len;
			debug_mdp->clock_state.len = clock_state_len;
		
			if (debugfs_create_file("reg_dump", 0644, dent, 0, &reg_fops)
					== NULL) {
				printk(KERN_ERR "%s(%d): debugfs_create_file: debug fail\n",
					__FILE__, __LINE__);
				return -1;
			}
}
			debug_mdp->size = dump_size;
			pr_info("size:%d",sizeof(debug_mdp));
			strncpy(debug_mdp->marker,"*#$$_START_OF_MDP_DEBUG_DUMP##$", sizeof("*#$$_START_OF_MDP_DEBUG_DUMP##$"));
		}else {
			pr_info("===DLogger Header=====\n");
			pr_info(" DUMP SIZE: %u\n",debug_mdp->size);
			pr_info("[0] first: %d last: %d  off: %d size: %d\n",
						debug_mdp->log_buff.first, debug_mdp->log_buff.last,
						debug_mdp->log_buff.offset, debug_mdp->log_buff.len);
			
			pr_info("[1] first: %d last: %d  off: %d size: %d\n",
						debug_mdp->event_desc.first, debug_mdp->event_desc.last,
						debug_mdp->event_desc.offset, debug_mdp->event_desc.len);
			pr_info("[2] first: %d last: %d  off: %d size: %d\n",
						debug_mdp->reg_log.first, debug_mdp->reg_log.last,
						debug_mdp->reg_log.offset, debug_mdp->reg_log.len);
			pr_info("[2] first: %d last: %d  off: %d size: %d\n",
						debug_mdp->clock_state.first, debug_mdp->clock_state.last,
						debug_mdp->clock_state.offset, debug_mdp->clock_state.len);
		}
		
#ifdef __KERNEL__
		init_clock_va();	
		vHWIO_GCC_DEBUG_CLK_CTL_ADDR = ioremap((0xfc401880),4);
		vHWIO_MMSS_DEBUG_CLK_CTL_ADDR = ioremap(0xfd8c0900,4);
		vHWIO_GCC_CLOCK_FRQ_MEASURE_STATUS_ADDR = ioremap(0xfc401888,4);
		vHWIO_GCC_CLOCK_FRQ_MEASURE_CTL_ADDR = ioremap(0xfc401884,4);
		vHWIO_GCC_XO_DIV4_CBCR_ADDR = ioremap(0xfc4010c8,4);

		spin_lock_init(&xlock);

{

	if (debugfs_create_file("dlogger", 0644, dent, 0, &dlog_fops)
			== NULL) {
		printk(KERN_ERR "%s(%d): debugfs_create_file: debug fail\n",
			__FILE__, __LINE__);
		return -1;
	}
}
#endif
return 0;
 }
static void initialize_variable(struct ssp_data *data)
{
	int iSensorIndex;

	for (iSensorIndex = 0; iSensorIndex < SENSOR_MAX; iSensorIndex++) {
		data->adDelayBuf[iSensorIndex] = DEFUALT_POLLING_DELAY;
		data->batchLatencyBuf[iSensorIndex] = 0;
		data->batchOptBuf[iSensorIndex] = 0;
		data->aiCheckStatus[iSensorIndex] = INITIALIZATION_STATE;
		data->lastTimestamp[iSensorIndex] = 0;
		data->reportedData[iSensorIndex] = false;
	}

	atomic_set(&data->aSensorEnable, 0);
	data->iLibraryLength = 0;
	data->uSensorState = NORMAL_SENSOR_STATE_K;
	data->uFactoryProxAvg[0] = 0;
	data->uMagCntlRegData = 1;

	data->uResetCnt = 0;
	data->uTimeOutCnt = 0;
	data->uListEmptyCnt = 0;
	data->uComFailCnt = 0;
	data->uIrqCnt = 0;
#if SSP_STATUS_MONITOR
	data->uSubIrqCnt = 0;
#endif

	data->bSspShutdown = true;
	data->bProximityRawEnabled = false;
	data->bGeomagneticRawEnabled = false;
	data->bBarcodeEnabled = false;
	data->bAccelAlert = false;
	data->bTimeSyncing = true;
	data->bSuspended = false;
#if SSP_STATUS_MONITOR
	data->bRefreshing = false;
#endif

	data->accelcal.x = 0;
	data->accelcal.y = 0;
	data->accelcal.z = 0;

	data->gyrocal.x = 0;
	data->gyrocal.y = 0;
	data->gyrocal.z = 0;

	data->magoffset.x = 0;
	data->magoffset.y = 0;
	data->magoffset.z = 0;

	data->iPressureCal = 0;
	data->uProxCanc = 0;
	data->uProxHiThresh = 0;
	data->uProxLoThresh = 0;
#if defined(CONFIG_SEC_TRLTE_PROJECT) || defined(CONFIG_SEC_TBLTE_PROJECT)
	data->uGyroDps = GYROSCOPE_DPS2000;
#else
	data->uGyroDps = GYROSCOPE_DPS500;
#endif
	data->uIr_Current = DEFUALT_IR_CURRENT;

	data->mcu_device = NULL;
	data->acc_device = NULL;
	data->gyro_device = NULL;
	data->mag_device = NULL;
	data->prs_device = NULL;
	data->prox_device = NULL;
	data->light_device = NULL;
	data->ges_device = NULL;

	data->voice_device = NULL;
#if SSP_SEC_DEBUG
	data->bMcuDumpMode = sec_debug_is_enabled();
#endif
	INIT_LIST_HEAD(&data->pending_list);

	data->sealevelpressure = 0;
	data->step_count_total = 0;
	initialize_function_pointer(data);
}
static int ssp_probe(struct spi_device *spi_dev)
{
	int iRet = 0;
	struct ssp_data *data;
	struct ssp_platform_data *pdata;

	if (poweroff_charging == 1) {
		pr_err("[SSP] probe exit : lpm %d\n", poweroff_charging);
		return -ENODEV;
	}

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (data == NULL) {
		pr_err("[SSP]: %s - failed to allocate memory for data\n",
			__func__);
		iRet = -ENOMEM;
		goto exit;
	}

#if defined (CONFIG_MACH_VIKALCU)
	proximity_ldo_enable(1);
#endif

	if (spi_dev->dev.of_node) {
		iRet = ssp_parse_dt(&spi_dev->dev, data);
		if (iRet) {
			pr_err("[SSP]: %s - Failed to parse DT\n", __func__);
			goto err_setup;
		}
		data->ssp_changes = SSP_MCU_L5; /* K330, MPU L5*/
	} else {
		pdata = spi_dev->dev.platform_data;
		if (pdata == NULL) {
			pr_err("[SSP]: %s - platform_data is null\n", __func__);
			iRet = -ENOMEM;
			goto err_setup;
		}
		data->wakeup_mcu = pdata->wakeup_mcu;
		data->check_mcu_ready = pdata->check_mcu_ready;
		data->check_mcu_busy = pdata->check_mcu_busy;
		data->set_mcu_reset = pdata->set_mcu_reset;
		data->read_chg = pdata->read_chg;

		/* AP system_rev */
		if (pdata->check_ap_rev)
			data->ap_rev = pdata->check_ap_rev();
		else
			data->ap_rev = 0;
		/* For changed devices */
		if (pdata->check_changes)
			data->ssp_changes = pdata->check_changes();
		else
			data->ssp_changes = SSP_MCU_L5; /* K330, MPU L5*/

		/* Get sensor positions */
		if (pdata->get_positions)
			pdata->get_positions(&data->accel_position,
				&data->mag_position);
		else if (spi_dev->dev.of_node == NULL) {
			data->accel_position = 0;
			data->mag_position = 0;
		}

	}
	spi_dev->mode = SPI_MODE_1;
	if (spi_setup(spi_dev)) {
		pr_err("failed to setup spi for ssp_spi\n");
		goto err_setup;
	}

	data->bProbeIsDone = false;
	data->fw_dl_state = FW_DL_STATE_NONE;
	data->spi = spi_dev;
	spi_set_drvdata(spi_dev, data);

#ifdef CONFIG_SENSORS_SSP_SHTC1
	mutex_init(&data->cp_temp_adc_lock);
	mutex_init(&data->bulk_temp_read_lock);
#endif
	mutex_init(&data->comm_mutex);
	mutex_init(&data->pending_mutex);

	if (((data->wakeup_mcu == NULL)
		|| (data->check_mcu_ready == NULL)
		|| (data->check_mcu_busy == NULL)
		|| (data->set_mcu_reset == NULL)
		|| (data->read_chg == NULL))
		&& (spi_dev->dev.of_node == NULL)) {
		pr_err("[SSP]: %s - function callback is null\n", __func__);
		iRet = -EIO;
		goto err_reset_null;
	}

	pr_info("\n#####################################################\n");

	INIT_DELAYED_WORK(&data->work_firmware, work_function_firmware_update);

	wake_lock_init(&data->ssp_wake_lock,
		WAKE_LOCK_SUSPEND, "ssp_wake_lock");

	iRet = initialize_input_dev(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create input device\n", __func__);
		goto err_input_register_device;
	}

	iRet = initialize_debug_timer(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create workqueue\n", __func__);
		goto err_create_workqueue;
	}

	iRet = initialize_irq(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create irq\n", __func__);
		goto err_setup_irq;
	}

	iRet = initialize_sysfs(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create sysfs\n", __func__);
		goto err_sysfs_create;
	}

	iRet = initialize_event_symlink(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create symlink\n", __func__);
		goto err_symlink_create;
	}

	initialize_variable(data);
	
	ssp_enable(data, true);
	/* check boot loader binary */
	data->fw_dl_state = check_fwbl(data);

	if (data->fw_dl_state == FW_DL_STATE_NONE) {
		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 err_read_reg;
		}
	}

#ifdef CONFIG_HAS_EARLYSUSPEND
	data->early_suspend.suspend = ssp_early_suspend;
	data->early_suspend.resume = ssp_late_resume;
	register_early_suspend(&data->early_suspend);
#endif

#ifdef CONFIG_SENSORS_SSP_SENSORHUB
	/* init sensorhub device */
	iRet = ssp_sensorhub_initialize(data);
	if (iRet < 0) {
		pr_err("%s: ssp_sensorhub_initialize err(%d)", __func__, iRet);
		ssp_sensorhub_remove(data);
	}
#endif

	data->bMcuDumpMode = sec_debug_is_enabled();
	pr_info("[SSP]: %s - setup debuglevel %d!\n", __func__,data->bMcuDumpMode);

	pr_info("[SSP]: %s - probe success!\n", __func__);

	enable_debug_timer(data);

	iRet = 0;
	if (data->fw_dl_state == FW_DL_STATE_NEED_TO_SCHEDULE) {
		pr_info("[SSP]: Firmware update is scheduled\n");
		schedule_delayed_work(&data->work_firmware,
				msecs_to_jiffies(1000));
		data->fw_dl_state = FW_DL_STATE_SCHEDULED;
	} else if (data->fw_dl_state == FW_DL_STATE_FAIL)
		data->bSspShutdown = true;
	data->bProbeIsDone = true;

	goto exit;

err_read_reg:
err_symlink_create:
	remove_sysfs(data);
err_sysfs_create:
	free_irq(data->iIrq, data);
	gpio_free(data->mcu_int1);
err_setup_irq:
	destroy_workqueue(data->debug_wq);
err_create_workqueue:
	remove_input_dev(data);
err_input_register_device:
	wake_lock_destroy(&data->ssp_wake_lock);
err_reset_null:
#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);

err_setup:
	kfree(data);
	pr_err("[SSP]: %s - probe failed!\n", __func__);
exit:
	pr_info("#####################################################\n\n");
	return iRet;
}