コード例 #1
0
static int __init mtktsbattery2_init(void)
{
	int err = 0;
	struct proc_dir_entry *entry = NULL;
	struct proc_dir_entry *mtktsbattery2_dir = NULL;

	mtktsbattery2_dprintk("[mtktsbattery2_init] \n");

	err = mtktsbattery2_register_thermal();
	if (err)
		goto err_unreg;

	mtktsbattery2_dir = proc_mkdir("mtktsbattery2", NULL);
	if (!mtktsbattery2_dir)
	{
		mtktsbattery2_dprintk("[mtktsbattery2_init]: mkdir /proc/mtktsbattery2 failed\n");
	}
	else
	{
		entry = create_proc_entry("mtktsbattery2", S_IRUGO | S_IWUSR, mtktsbattery2_dir);
		if (entry)
		{
			entry->read_proc = mtktsbattery2_read;
			entry->write_proc = mtktsbattery2_write;
		}
	}

	return 0;

err_unreg:
	return err;
}
コード例 #2
0
ファイル: mtk_ts_battery2.c プロジェクト: Scorpio92/mediatek
static int get_hw_battery2_temp(void)
{

	int ret = 0, data[4], i, ret_value = 0, ret_temp = 0, output;
	int times=1, Channel=0;//6589=1,6582=0(AUX_IN0_NTC)

	if( IMM_IsAdcInitReady() == 0 )
	{
        printk("[thermal_auxadc_get_data]: AUXADC is not ready\n");
		return 0;
	}

	i = times;
	while (i--)
	{
		ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp);
		ret += ret_temp;
		mtktsbattery2_dprintk("[thermal_auxadc_get_data(AUX_IN0_NTC)]: ret_temp=%d\n",ret_temp);
	}

#if 0
	Channel = 0;
	ret = 0 ;
	ret_temp = 0;
	i = times;
	while (i--)
	{
		ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp);
		ret += ret_temp;
		printk("[thermal_auxadc_get_data(ADCIN %d)]: ret_temp=%d\n",Channel,ret_temp);
	}

	Channel = 2;
	ret = 0 ;
	ret_temp = 0;
	i = times;
	while (i--)
	{
		ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp);
		ret += ret_temp;
		printk("[thermal_auxadc_get_data(ADCIN %d)]: ret_temp=%d\n",Channel,ret_temp);
	}
#endif

	//ret = ret*1500/4096	;
	ret = ret*1800/4096;//82's ADC power
	mtktsbattery2_dprintk("Battery output mV = %d\n",ret);
	output = BattVoltToTemp(ret);
	mtktsbattery2_dprintk("Battery output temperature = %d\n",output);

	return output;
}
コード例 #3
0
static int mtktsbattery2_get_temp(struct thermal_zone_device *thermal,
				   unsigned long *t)
{
	*t = (unsigned long)get_hw_battery2_temp() * 1000;
	mtktsbattery2_dprintk("[mtktsbattery2_get_hw_temp] T_Battery, %d\n", *t);

	return 0;
}
コード例 #4
0
static void mtktsbattery2_unregister_thermal(void)
{
	mtktsbattery2_dprintk("[mtktsbattery2_unregister_thermal] \n");

	if (thz_dev) {
		mtk_thermal_zone_device_unregister(thz_dev);
		thz_dev = NULL;
	}
}
コード例 #5
0
static int mtktsbattery2_register_thermal(void)
{
	mtktsbattery2_dprintk("[mtktsbattery2_register_thermal] \n");

	/* trips : trip 0~1 */
	thz_dev = mtk_thermal_zone_device_register("mtktsbattery2", num_trip, NULL,
		&mtktsbattery2_dev_ops, 0, 0, 0, interval*1000);

	return 0;
}
コード例 #6
0
static int get_hw_battery2_temp(void)
{
	int data[4], ret_value = 0, ret_temp = 0, output;

	if( IMM_IsAdcInitReady() == 0 )
	{
		mtktsbattery2_dprintk("[thermal_auxadc_get_data]: AUXADC is not ready\n");
		return 0;
	}

	ret_value = IMM_GetOneChannelValue(AUXADC_CHANNEL, data, &ret_temp);
	mtktsbattery2_dprintk("[thermal_auxadc_get_data(ADCIN1)]: ret_temp=%d\n",ret_temp);

	ret_temp = ret_temp*1500/4096;
	output = BattVoltageToTemp(ret_temp);
	mtktsbattery2_dprintk("Battery output temperature mV= %d  %d\n",output, ret_temp);

	return output;
}
コード例 #7
0
static int mtktsbattery2_get_hw_temp(void)
{
	int t_ret=0;
	static int battery2[60]={0};
	static int counter=0, first_time=0;
	int i=0;
	
	mutex_lock(&battery2_lock);

    //get HW battery2 temp (TSbattery2)
    //cat /sys/class/power_supply/battery2/batt_temp
	t_ret = get_hw_battery2_temp();
	t_ret = t_ret * 1000;
	battery2[counter]=t_ret;

	if(first_time!=0)
	{
		t_ret = 0;
		for(i=0; i<MA_len; i++)
		{
			t_ret += battery2[i];
		}
		t_ret = t_ret / MA_len;
	}

	counter++;
	if(counter==MA_len)
	{
		counter=0;
		first_time=1;
	}
	if(counter>MA_len)
	{
		counter=0;
		first_time=0;
	}
	mutex_unlock(&battery2_lock);

	mtktsbattery2_dprintk("[mtktsbattery2_get_hw_temp] counter=%d, first_time =%d, MA_len=%d\n", counter, first_time, MA_len);
	mtktsbattery2_dprintk("[mtktsbattery2_get_hw_temp] T_battery2, %d\n", t_ret);
	return t_ret;
}
コード例 #8
0
static int mtktsbattery2_bind(struct thermal_zone_device *thermal,
			struct thermal_cooling_device *cdev)
{
	int table_val=0;
	table_val = mtkts_match(cdev,g_bind);
	if(table_val >= MTK_TZ_COOLER_MAX)
	{
		return 0;
	}
	else
	{
		mtktsbattery2_dprintk("[mtktsbattery2_bind] %s\n", cdev->type);
		if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) {
			mtktsbattery2_dprintk("[mtktsbattery2_bind] error binding cooling dev\n");
			return -EINVAL;
		} else {
			mtktsbattery2_dprintk("[mtktsbattery2_bind] binding OK, %d\n", table_val);
		}
	}
	return 0;
}
コード例 #9
0
static ssize_t mtktsbattery2_write(struct file *file, const char *buffer, unsigned long count, void *data)
{
	int len=0,time_msec=0;
	int trip[MTK_TZ_COOLER_MAX]={0};
	int t_type[MTK_TZ_COOLER_MAX]={0};
	int i;
	char bind[MTK_TZ_COOLER_MAX][THERMAL_NAME_LENGTH];
	char desc[512];


	len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
	if (copy_from_user(desc, buffer, len))
	{
		return 0;
	}
	desc[len] = '\0';

	if (sscanf(desc, "%d %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d %d %19s %d",
				&num_trip,
				&trip[0],&t_type[0],bind[0], &trip[1],&t_type[1],bind[1],
				&trip[2],&t_type[2],bind[2], &trip[3],&t_type[3],bind[3],
				&trip[4],&t_type[4],bind[4], &trip[5],&t_type[5],bind[5],
				&trip[6],&t_type[6],bind[6], &trip[7],&t_type[7],bind[7],
				&trip[8],&t_type[8],bind[8], &trip[9],&t_type[9],bind[9],
				&time_msec) == 32)
	{
		mtktsbattery2_dprintk("[mtktsbattery2_write] unregister_thermal\n");
		mtktsbattery2_unregister_thermal();

		for(i=0; i<MTK_TZ_COOLER_MAX; i++)
		{
			g_THERMAL_TRIP[i] = t_type[i];
			memcpy(g_bind[i], bind[i], THERMAL_NAME_LENGTH);
			trip_temp[i]=trip[i];
		}
		interval=time_msec / 1000;

		mtktsbattery2_dprintk("[mtktsbattery2_write] [trip_type]=%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
				g_THERMAL_TRIP[0],g_THERMAL_TRIP[1],g_THERMAL_TRIP[2],g_THERMAL_TRIP[3],g_THERMAL_TRIP[4],
				g_THERMAL_TRIP[5],g_THERMAL_TRIP[6],g_THERMAL_TRIP[7],g_THERMAL_TRIP[8],g_THERMAL_TRIP[9]);

		mtktsbattery2_dprintk("[mtktsbattery2_write] [cool_bind]=%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",
				g_bind[0],g_bind[1],g_bind[2],g_bind[3],g_bind[4],g_bind[5],g_bind[6],g_bind[7],g_bind[8],g_bind[9]);

		mtktsbattery2_dprintk("[mtktsbattery2_write] [trip_temp]==%d,%d,%d,%d,%d,%d,%d,%d,%d,%d, [time_ms]=%d\n",
				trip_temp[0],trip_temp[1],trip_temp[2],trip_temp[3],trip_temp[4],
				trip_temp[5],trip_temp[6],trip_temp[7],trip_temp[8],trip_temp[9],interval*1000);

		mtktsbattery2_dprintk("[mtktsbattery2_write] register_thermal\n");
		mtktsbattery2_register_thermal();

		return count;
	}
	else
	{
		mtktsbattery2_dprintk("[mtktsbattery2_write] bad argument\n");
	}

	return -EINVAL;
}
コード例 #10
0
ファイル: mtk_ts_battery2.c プロジェクト: Scorpio92/mediatek
static int mtktsbattery2_get_hw_temp(void)
{
	int t_ret=0;
//	static int battery2[60]={0};
//	int i=0;

	mutex_lock(&battery2_lock);

    //get HW battery2 temp (TSbattery2)
    //cat /sys/class/power_supply/battery2/batt_temp
	t_ret = get_hw_battery2_temp();
	t_ret = t_ret * 1000;

	mutex_unlock(&battery2_lock);


	mtktsbattery2_dprintk("[mtktsbattery2_get_hw_temp] T_battery2, %d\n", t_ret);
	return t_ret;
}
コード例 #11
0
static void __exit mtktsbattery2_exit(void)
{
	mtktsbattery2_dprintk("[mtktsbattery2_exit] \n");
	mtktsbattery2_unregister_thermal();
}
コード例 #12
0
ファイル: mtk_ts_battery2.c プロジェクト: Scorpio92/mediatek
static ssize_t mtktsbattery2_write(struct file *file, const char *buffer, unsigned long count, void *data)
{
	int len=0,time_msec=0;
	int trip[10]={0};
	int t_type[10]={0};
	int i;
	char bind0[20],bind1[20],bind2[20],bind3[20],bind4[20];
	char bind5[20],bind6[20],bind7[20],bind8[20],bind9[20];
	char desc[512];


	len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
	if (copy_from_user(desc, buffer, len))
	{
		return 0;
	}
	desc[len] = '\0';

	if (sscanf(desc, "%d %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d",
				&num_trip, &trip[0],&t_type[0],bind0, &trip[1],&t_type[1],bind1,
				&trip[2],&t_type[2],bind2, &trip[3],&t_type[3],bind3,
				&trip[4],&t_type[4],bind4, &trip[5],&t_type[5],bind5,
				&trip[6],&t_type[6],bind6, &trip[7],&t_type[7],bind7,
				&trip[8],&t_type[8],bind8, &trip[9],&t_type[9],bind9,
				&time_msec) == 32)
	{
		mtktsbattery2_dprintk("[mtktsbattery2_write] mtktsbattery2_unregister_thermal\n");
		mtktsbattery2_unregister_thermal();

		for(i=0; i<num_trip; i++)
			g_THERMAL_TRIP[i] = t_type[i];

		g_bind0[0]=g_bind1[0]=g_bind2[0]=g_bind3[0]=g_bind4[0]=g_bind5[0]=g_bind6[0]=g_bind7[0]=g_bind8[0]=g_bind9[0]='\0';

		for(i=0; i<20; i++)
		{
			g_bind0[i]=bind0[i];
			g_bind1[i]=bind1[i];
			g_bind2[i]=bind2[i];
			g_bind3[i]=bind3[i];
			g_bind4[i]=bind4[i];
			g_bind5[i]=bind5[i];
			g_bind6[i]=bind6[i];
			g_bind7[i]=bind7[i];
			g_bind8[i]=bind8[i];
			g_bind9[i]=bind9[i];
		}

		mtktsbattery2_dprintk("[mtktsbattery2_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,\
					g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n",
				g_THERMAL_TRIP[0],g_THERMAL_TRIP[1],g_THERMAL_TRIP[2],g_THERMAL_TRIP[3],g_THERMAL_TRIP[4],
				g_THERMAL_TRIP[5],g_THERMAL_TRIP[6],g_THERMAL_TRIP[7],g_THERMAL_TRIP[8],g_THERMAL_TRIP[9]);
		mtktsbattery2_dprintk("[mtktsbattery2_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\
					cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n",
				g_bind0,g_bind1,g_bind2,g_bind3,g_bind4,g_bind5,g_bind6,g_bind7,g_bind8,g_bind9);

		for(i=0; i<num_trip; i++)
		{
			trip_temp[i]=trip[i];
		}

		interval=time_msec / 1000;

		mtktsbattery2_dprintk("[mtktsbattery2_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,trip_4_temp=%d,\
trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,time_ms=%d\n",
				trip_temp[0],trip_temp[1],trip_temp[2],trip_temp[3],trip_temp[4],
				trip_temp[5],trip_temp[6],trip_temp[7],trip_temp[8],trip_temp[9],interval*1000);

		mtktsbattery2_dprintk("[mtktsbattery2_write] mtktsbattery2_register_thermal\n");
		mtktsbattery2_register_thermal();

		//battery2_write_flag=1;
		return count;
	}
コード例 #13
0
ファイル: mtk_ts_battery2.c プロジェクト: Scorpio92/mediatek
static int mtktsbattery2_unbind(struct thermal_zone_device *thermal,
			  struct thermal_cooling_device *cdev)
{
    int table_val=0;

	if(!strcmp(cdev->type, g_bind0))
	{
		table_val = 0;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind1))
	{
		table_val = 1;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind2))
	{
		table_val = 2;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind3))
	{
		table_val = 3;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind4))
	{
		table_val = 4;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind5))
	{
		table_val = 5;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind6))
	{
		table_val = 6;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind7))
	{
		table_val = 7;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind8))
	{
		table_val = 8;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else if(!strcmp(cdev->type, g_bind9))
	{
		table_val = 9;
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] %s\n", cdev->type);
	}
	else
		return 0;

	if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) {
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] error unbinding cooling dev\n");
		return -EINVAL;
	} else {
		mtktsbattery2_dprintk("[mtktsbattery2_unbind] unbinding OK\n");
	}

	return 0;
}