static int mmc328x_magnetic_resume(struct early_suspend *handler)
{
	unsigned char data[16] = {0};

	atomic_set(&suspend_flag,RESUME);
#ifdef MMC328X_SENSOR_DEBUG
	printk("mmc328x resume mode :%d \n",suspend_flag.counter);
#endif
	if (g_client){
		kfree(g_client);
	}
	g_client = omap_gpio_i2c_init(OMAP_GPIO_FM_SDA	, OMAP_GPIO_FM_SCL, MMC328X_I2C_ADDR, 200);
	msleep(MMC328X_DELAY_RRM);
	/* send SET/RESET cmd to mag sensor first of all */
#ifdef CONFIG_SENSORS_MMC328X 
	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_RRM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
	}
	msleep(MMC328X_DELAY_RRM);
	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_TM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
	}
	msleep(5*MMC328X_DELAY_TM);
#endif

	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_RM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
		/* assume RM always success */
	}
#ifndef CONFIG_SENSORS_MMC328X 
	/* wait external capacitor charging done for next RM */
	msleep(MMC328X_DELAY_RM);
#else
	msleep(10*MMC328X_DELAY_RM);
	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_TM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
	}
#endif
	return 0;
}
static int mmc328x_init_probe(struct platform_device *pdev)
{
	unsigned char data[16] = {0};
	int res = 0;
	int ret33 = 0;

	if (get_hw_revision() == 0x09) {
		printk("[SENSOR] hw_revision : 0x09\n ");
		vreg_sensor = regulator_get(NULL, "vmmc2");
		ret33 = regulator_enable(vreg_sensor);

		if (ret33) {
			printk("[SENSOR] Error, %s: vreg enable failed (%d)\n", __func__, ret33);
		}

	}

	pr_info("mmc328x driver: probe\n");
	g_client = omap_gpio_i2c_init(OMAP_GPIO_FM_SDA	, OMAP_GPIO_FM_SCL, MMC328X_I2C_ADDR, 200);

	res = misc_register(&mmc328x_device);
	if (res) {
		pr_err("%s: mmc328x_device register failed\n", __FUNCTION__);
		goto out;
	}

	res = device_create_file(mmc328x_device.this_device, &dev_attr_mmc328x);
	if (res) {
		pr_err("%s: device_create_file failed\n", __FUNCTION__);
		goto out_deregister;
	}

	res = sysfs_create_group(&mmc328x_device.this_device->kobj,&mmc328x_group);
	if (res < 0){
		pr_info("failed to create sysfs files\n");
		goto out_sysinfo;
	}

	/* send SET/RESET cmd to mag sensor first of all */
#ifdef CONFIG_SENSORS_MMC328X 
	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_RRM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
	}
	msleep(MMC328X_DELAY_RRM);
	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_TM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
	}
	msleep(5*MMC328X_DELAY_TM);
#endif

	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_RM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
		/* assume RM always success */
	}
#ifndef CONFIG_SENSORS_MMC328X 
	/* wait external capacitor charging done for next RM */
	msleep(MMC328X_DELAY_RM);
#else
	msleep(10*MMC328X_DELAY_RM);
	data[0] = MMC328X_REG_CTRL;
	data[1] = MMC328X_CTRL_TM;
	if (mmc328x_i2c_tx_data(data, 2) < 0) {
	}
#endif

#if defined(CONFIG_HAS_EARLYSUSPEND)
	early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	early_suspend.suspend = (void *)mmc328x_magnetic_suspend;
	early_suspend.resume  = (void *)mmc328x_magnetic_resume;
	register_early_suspend(&early_suspend);
#endif

	return 0;
out_sysinfo:
	sysfs_remove_group(&mmc328x_device.this_device->kobj,&mmc328x_group);
out_deregister:
	misc_deregister(&mmc328x_device);
out:
	return res;
}
Пример #3
0
//static int yas_acc_probe(struct i2c_client *client, const struct i2c_device_id *id)
static int bma222_init_proc()
{
    struct yas_acc_private_data *data;
    int err;
     printk(KERN_ERR "bma222_init_proc +\n");
    /* Setup private data */
    data = kzalloc(sizeof(struct yas_acc_private_data), GFP_KERNEL);
    if (!data) {
        err = -ENOMEM;
        goto ERR1;
    }
    yas_acc_set_data(data);

    mutex_init(&data->driver_mutex);
    mutex_init(&data->data_mutex);

    data->client = omap_gpio_i2c_init(OMAP_GPIO_SENSOR_SDA, OMAP_GPIO_SENSOR_SCL, 0x08, 200);
	
/*
    // Setup i2c client
    if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
        err = -ENODEV;
        goto ERR2;
    }
    i2c_set_clientdata(client, data);
    data->client = client;
*/
    /* Setup accelerometer core driver */
    err = yas_acc_core_driver_init(data);
    if (err < 0) {
        goto ERR2;
    }

    /* Setup driver interface */
    INIT_DELAYED_WORK(&data->work, yas_acc_work_func);

    /* Setup input device interface */
    err = yas_acc_input_init(data);
    if (err < 0) {
        goto ERR3;
    }

    /* Setup sysfs */
    err = sysfs_create_group(&data->input->dev.kobj, &yas_acc_attribute_group);
    if (err < 0) {
        goto ERR4;
    }

    err = sensors_register(accel_sensor_device, NULL, accel_sensor_attrs, "accelerometer_sensor");
    if(err) {
    	printk(KERN_ERR "%s: cound not register accelerometer sensor device(%d).\n", __func__, err);
    }
	
#if defined(CONFIG_HAS_EARLYSUSPEND)
    data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
    data->early_suspend.suspend = (void *)bma222_early_suspend;
    data->early_suspend.resume  = (void *)bma222_early_resume;
    register_early_suspend(&data->early_suspend);
#endif	

	printk(KERN_ERR "bma222_init_proc -\n");


    return 0;

 ERR4:
    yas_acc_input_fini(data);
 ERR3:
    yas_acc_core_driver_fini(data);
 ERR2:
    kfree(data);
 ERR1:
    return err;
}