コード例 #1
0
ファイル: bq27410_battery.c プロジェクト: gtlinyun/bq-DC-v2
static void bq27410_battery_work(struct work_struct *work)
{
	struct bq27410_device_info *di = container_of(work, struct bq27410_device_info, work.work); 
	static int flag = 0;
	if(flag == 0){
		mutex_lock(&g_bq27410_mutex);
		bq27410_write_batt_insert(g_client);
		mutex_unlock(&g_bq27410_mutex);

		virtual_battery_enable = 0;
		flag = 1;
	}

	bq27410_battery_update_status(di);
	/* reschedule for the next time */
	schedule_delayed_work(&di->work, di->interval);
}
コード例 #2
0
static void bq27410_battery_work(struct work_struct *work)
{
	struct bq27410_device_info *di = container_of(work, struct bq27410_device_info, work.work); 
	int ret = 0;
	u8 buf[2];
	int battflags = 0;
	static int flag = 0;

	if(flag == 0){
#if 0
		mutex_lock(&g_bq27410_mutex);
		bq27410_write_batt_insert(g_client);
		mutex_unlock(&g_bq27410_mutex);

		virtual_battery_enable = 0;
		flag = 1;
#else
		mutex_lock(&g_bq27410_mutex);
		ret = bq27410_read(g_client,BQ27410_REG_FLAGS, buf, 2);
		if (ret < 0) {
			DBG("error reading flags\n");
			return ret;
		}
		mutex_unlock(&g_bq27410_mutex);
		battflags = get_unaligned_le16(buf);
		if ((battflags & BQ27410_FLAG_BAT_DET)){
			printk("27410: %s, battflags = 0x%x, set virtual_battery_enable = 0\n",__FUNCTION__,battflags);
			flag = 1;
			virtual_battery_enable = 0;
		}
#endif
	}

	bq27410_battery_update_status(di);
	/* reschedule for the next time */
	schedule_delayed_work(&di->work, di->interval);
}
コード例 #3
0
ファイル: bq27410_battery.c プロジェクト: gtlinyun/bq-DC-v2
static int bq27410_battery_probe(struct i2c_client *client,
				 const struct i2c_device_id *id)
{
	struct bq27410_device_info *di;
	int retval = 0;
	u8 buf[2];
	struct bq27410_platform_data *pdata;
	
	DBG("**********  bq27410_battery_probe**************  \n");
	
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)){
		client->addr = 0x0B;
		if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)){
			return -ENODEV;
		}
		else{
			g_bq27410_mode = BQ27410_ROM_MODE;
		}
	}
	else{
		g_bq27410_mode = BQ27410_NORMAL_MODE;
	}
	printk("+ g_bq27410_mode=%d \n", g_bq27410_mode);
	
	pdata = client->dev.platform_data;
	g_pdata = pdata;
	g_client = client;

	di = kzalloc(sizeof(*di), GFP_KERNEL);
	if (!di) {
		dev_err(&client->dev, "failed to allocate device info data\n");
		retval = -ENOMEM;
		goto batt_failed_2;
	}
	mutex_init(&g_bq27410_mutex);
		

	i2c_set_clientdata(client, di);
	di->dev = &client->dev;
	di->bat.name = "battery";
	di->client = client;
	/* 4 seconds between monotor runs interval */
	di->interval = msecs_to_jiffies(4 * 1000);
	
	di->bat_num = pdata->bat_num;
	di->dc_check_pin = pdata->dc_check_pin;
	di->bat_check_pin = pdata->bat_check_pin;
	di->wake_irq = pdata->low_power_pin;
	
	if (pdata->io_init)
		pdata->io_init();

	bq27410_di = di;
	retval = bq27410_read(client,0x00,buf,2);
	if(retval < 0){
		printk("failed to find bq27410\n");
		goto batt_failed_2;
	}else{
		rk30_bat_unregister();
		bq27410_init = 1;
	}

	//command batt insert.
	bq27410_write_batt_insert(client);

	if(g_bq27410_mode == BQ27410_NORMAL_MODE){

		if(!bq27410_read_control_status(client))
		{
			virtual_battery_enable = 1;

			bq27410_powersupply_init(di);
			retval = power_supply_register(&client->dev, &di->bat);

			INIT_DELAYED_WORK(&di->update_work, bq27410_battery_update_work);
			schedule_delayed_work(&di->update_work, msecs_to_jiffies(15 * 1000));
		}
		else{
			printk("NOT need bq27410_update_firmware \n");
			bq27410_powersupply_init(di);
			
			retval = power_supply_register(&client->dev, &di->bat);
			if (retval) {
				dev_err(&client->dev, "failed to register battery\n");
				goto batt_failed_4;
			}
			INIT_DELAYED_WORK(&di->work, bq27410_battery_work);
			schedule_delayed_work(&di->work, di->interval);
			dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);
		}
	}
	else
	{
		INIT_DELAYED_WORK(&di->update_work, bq27410_battery_update_work);
		schedule_delayed_work(&di->update_work, msecs_to_jiffies(15 * 1000));
	}
	printk("- g_bq27410_mode=%d \n", g_bq27410_mode);
	
	//M-MT:setup discharge/charge current threshold. 
	//bq27410_write_current_threshold(client);

	// battery low irq
	if(pdata->low_power_pin != INVALID_GPIO)
	{
		di->wake_irq = gpio_to_irq(pdata->low_power_pin);
		retval = request_irq(di->wake_irq, bq27410_bat_wakeup, IRQF_TRIGGER_FALLING, "bq27410_battery", di);
		if (retval) {
			printk("failed to request low_power_pin irq\n");
			goto err_batirq_failed;
		}

		INIT_DELAYED_WORK(&di->wakeup_work, bq27410_battery_wake_work);
		enable_irq_wake(di->wake_irq);
	}
	
	bq27410_proc_entry = create_proc_entry("bq27410-update", 0666, NULL);
	if(bq27410_proc_entry == NULL)
	{
		printk("Malata bq27410 Couldn't create proc entry!\n");
		return -ENOMEM;
	}
	else
	{
		printk("Malata bq27410 Create proc entry success!\n");
		bq27410_proc_entry->write_proc = bq27410_update_write;
		bq27410_proc_entry->read_proc = bq27410_update_read;
	}

	battery_capacity_check(di);

	return 0;

batt_failed_4:
	kfree(di);
batt_failed_2:

err_batirq_failed:
	gpio_free(pdata->bat_check_pin);

	return retval;
}