static int leds_sm5701_probe(struct platform_device *pdev)
{
        struct SM5701_dev *iodev = dev_get_drvdata(pdev->dev.parent);
        struct SM5701_leds_data *chip;
        struct SM5701_fled_platform_data *pdata;

        int err;

        printk("******* %s *******\n",__func__);
        pdata = &sm5701_default_fled_pdata;

        chip = kzalloc(sizeof(struct SM5701_leds_data), GFP_KERNEL);
        if (!chip)
           return -ENOMEM;

        chip->dev = &pdev->dev;
        chip->iodev = iodev;
        platform_set_drvdata(pdev, chip);
        /*
        if (!(leds_sm5701_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
            return -ENOMEM;
        }
        memset(leds_sm5701_client, 0, sizeof(struct i2c_client));
        */
        leds_sm5701_client = chip->iodev->i2c;

        mutex_init(&chip->lock);

        if (camera_class ==NULL){
                camera_class = class_create(THIS_MODULE, "camera");
                if (IS_ERR(camera_class))
			pr_err("failed to create device cam_dev_rear!\n");
        }
        /* flash */
        INIT_WORK(&chip->work_flash, sm5701_deferred_flash_brightness_set);
        chip->cdev_flash.name = "flash";
        chip->cdev_flash.max_brightness = 32-1;//0x1f
        chip->cdev_flash.brightness_set = sm5701_flash_brightness_set;
        chip->cdev_flash.default_trigger = "flash";
        err = led_classdev_register((struct device *)
                                    chip->dev, &chip->cdev_flash);

        if (err < 0) {
                dev_err(chip->dev, "failed to register flash\n");
                goto err_create_flash_file;
        }
        err = device_create_file(chip->cdev_flash.dev, &dev_attr_flash);
        if (err < 0) {
                dev_err(chip->dev, "failed to create flash file\n");
                goto err_create_flash_pin_file;
        }

	/* movie */
	INIT_WORK(&chip->work_movie, sm5701_deferred_movie_brightness_set);
	chip->cdev_movie.name = "flash";
	chip->cdev_movie.max_brightness = 32-1;//0x1f
	chip->cdev_movie.brightness_set = sm5701_movie_brightness_set;
	chip->cdev_movie.default_trigger = "flash";

        chip->cdev_movie.dev = device_create(camera_class, NULL, 0, NULL, "flash");
        if (IS_ERR(chip->cdev_movie.dev)) {
                pr_err("flash_sysfs: failed to create device(flash)\n");
                goto err_create_movie_file;
        }
        err = device_create_file(chip->cdev_movie.dev, &dev_attr_rear_flash);
        if (err < 0) {
                dev_err(chip->dev, "failed to create movie file\n");
                goto err_create_movie_pin_file;
        }

        err = sm5701_chip_init(chip);
        if (err < 0)
                goto err_out;
    #if  defined (CONFIG_MACH_VIVALTO5MVE3G) || defined(CONFIG_MACH_VIVALTO3MVE3G_LTN)
        if (!gpio_is_valid(flash_enable_gpio))
        {
              printk("flash_enable_gpio gpio pin error");
               return 1;
        }
        gpio_request(flash_enable_gpio, "gpioFlashhigh");
        gpio_direction_output(flash_enable_gpio,0);

        if (!gpio_is_valid(flash_torch_gpio)) 
        {
              printk("flash_torch_gpio gpio pin error");
               return 1;
        }
        gpio_request(flash_torch_gpio, "gpioFlashlow");
        gpio_direction_output(flash_torch_gpio,0);
    #endif
        //sm5701_dump_register();
        pdata->fled_pinctrl = devm_pinctrl_get(&pdev->dev);
        if (IS_ERR_OR_NULL(pdata->fled_pinctrl)) {
              pr_err("%s:%d Getting pinctrl handle failed\n", __func__, __LINE__);
              return -EINVAL;
        }

        pdata->gpio_state_active = pinctrl_lookup_state(pdata->fled_pinctrl, FLED_PINCTRL_STATE_DEFAULT);
        if (IS_ERR_OR_NULL(pdata->gpio_state_active)) {
              pr_err("%s:%d Failed to get the active state pinctrl handle\n", __func__, __LINE__);
              return -EINVAL;
        }

        pdata->gpio_state_suspend = pinctrl_lookup_state(pdata->fled_pinctrl, FLED_PINCTRL_STATE_SLEEP);
        if (IS_ERR_OR_NULL(pdata->gpio_state_suspend)) {
              pr_err("%s:%d Failed to get the active state pinctrl handle\n", __func__, __LINE__);
              return -EINVAL;
        }

        err = pinctrl_select_state(pdata->fled_pinctrl, pdata->gpio_state_suspend);
        if (err) {
              pr_err("%s:%d cannot set pin to active state", __func__, __LINE__);
              return err;
        }
        pr_err("%s End : X\n", __func__);

        dev_info(chip->dev, "LEDs_SM5701 Probe Done\n");
        return 0;

err_create_movie_file:
        device_remove_file(chip->cdev_movie.dev, &dev_attr_rear_flash);
err_create_movie_pin_file:
        led_classdev_unregister(&chip->cdev_movie);
err_create_flash_file:
        device_remove_file(chip->cdev_flash.dev, &dev_attr_flash);
err_create_flash_pin_file:
        led_classdev_unregister(&chip->cdev_flash);
err_out:
        return err;
}
示例#2
0
static int leds_sm5701_probe(struct platform_device *pdev)
{
    	struct SM5701_dev *iodev = dev_get_drvdata(pdev->dev.parent);
        struct SM5701_leds_data *chip;

        int err;

        printk("******* %s *******\n",__func__);

    	chip = kzalloc(sizeof(struct SM5701_leds_data), GFP_KERNEL);        
        if (!chip)
           return -ENOMEM;

        chip->dev = &pdev->dev;
        chip->iodev = iodev;
        platform_set_drvdata(pdev, chip);
        
        if (!(leds_sm5701_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
            return -ENOMEM;
        }    
        memset(leds_sm5701_client, 0, sizeof(struct i2c_client));

        leds_sm5701_client = chip->iodev->i2c;    

        mutex_init(&chip->lock);

        /* flash */
        INIT_WORK(&chip->work_flash, sm5701_deferred_flash_brightness_set);
        chip->cdev_flash.name = "flash";
        chip->cdev_flash.max_brightness = 32-1;//0x1f
        chip->cdev_flash.brightness_set = sm5701_flash_brightness_set;
        chip->cdev_flash.default_trigger = "flash";
        err = led_classdev_register((struct device *)
                                    chip->dev, &chip->cdev_flash);

        if (err < 0) {
                dev_err(chip->dev, "failed to register flash\n");
                goto err_create_flash_file;
        }
        err = device_create_file(chip->cdev_flash.dev, &dev_attr_flash);
        if (err < 0) {
                dev_err(chip->dev, "failed to create flash file\n");
                goto err_create_flash_pin_file;
        }

        /* movie */
        INIT_WORK(&chip->work_movie, sm5701_deferred_movie_brightness_set);
        chip->cdev_movie.name = "movie";
        chip->cdev_movie.max_brightness = 32-1;//0x1f
        chip->cdev_movie.brightness_set = sm5701_movie_brightness_set;
        chip->cdev_movie.default_trigger = "movie";
        err = led_classdev_register((struct device *)
                                    chip->dev, &chip->cdev_movie);
        if (err < 0) {
                dev_err(chip->dev, "failed to register movie\n");
                goto err_create_movie_file;
        }
        err = device_create_file(chip->cdev_movie.dev, &dev_attr_movie);
        if (err < 0) {
                dev_err(chip->dev, "failed to create movie file\n");
                goto err_create_movie_pin_file;
        }

        err = sm5701_chip_init(chip);
        if (err < 0)
                goto err_out;

        //sm5701_dump_register();

        dev_info(chip->dev, "LEDs_SM5701 Probe Done\n");
      return 0;

err_create_movie_file:
        device_remove_file(chip->cdev_movie.dev, &dev_attr_movie);
err_create_movie_pin_file:
        led_classdev_unregister(&chip->cdev_movie);
err_create_flash_file:
        device_remove_file(chip->cdev_flash.dev, &dev_attr_flash);
err_create_flash_pin_file:
        led_classdev_unregister(&chip->cdev_flash);
err_out:
        return err;
}