Skip to content

Commit

Permalink
staging: media: atomisp: Convert to GPIO descriptors
Browse files Browse the repository at this point in the history
Convert the atomisp LM3554 driver to use GPIO descriptors
fully. It was already retrieveing the GPIO lines as descriptors
but for some reason converting them back into global GPIO
numbers. There is no reason to do this, just deal with the
descriptors as-is.

Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20200827081445.186882-1-linus.walleij@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
linusw authored and gregkh committed Aug 28, 2020
1 parent d8eb176 commit 9289cdf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 43 deletions.
68 changes: 28 additions & 40 deletions drivers/staging/media/atomisp/i2c/atomisp-lm3554.c
Expand Up @@ -19,14 +19,13 @@
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/slab.h>

#include "../include/media/lm3554.h"
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <linux/acpi.h>
#include <linux/gpio/consumer.h>
#include "../include/linux/atomisp_gmin_platform.h"
#include "../include/linux/atomisp.h"

Expand Down Expand Up @@ -173,7 +172,7 @@ static void lm3554_flash_off_delay(struct timer_list *t)
struct lm3554 *flash = from_timer(flash, t, flash_off_delay);
struct lm3554_platform_data *pdata = flash->pdata;

gpio_set_value(pdata->gpio_strobe, 0);
gpiod_set_value(pdata->gpio_strobe, 0);
}

static int lm3554_hw_strobe(struct i2c_client *client, bool strobe)
Expand Down Expand Up @@ -209,15 +208,15 @@ static int lm3554_hw_strobe(struct i2c_client *client, bool strobe)
* so must strobe off here
*/
if (timer_pending)
gpio_set_value(pdata->gpio_strobe, 0);
gpiod_set_value(pdata->gpio_strobe, 0);

/* Restore flash current settings */
ret = lm3554_set_flash(flash);
if (ret < 0)
goto err;

/* Strobe on Flash */
gpio_set_value(pdata->gpio_strobe, 1);
gpiod_set_value(pdata->gpio_strobe, 1);

return 0;
err:
Expand Down Expand Up @@ -627,7 +626,7 @@ static int __lm3554_s_power(struct lm3554 *flash, int power)
int ret;

/*initialize flash driver*/
gpio_set_value(pdata->gpio_reset, power);
gpiod_set_value(pdata->gpio_reset, power);
usleep_range(100, 100 + 1);

if (power) {
Expand Down Expand Up @@ -766,33 +765,22 @@ static int lm3554_gpio_init(struct i2c_client *client)
struct lm3554_platform_data *pdata = flash->pdata;
int ret;

if (!gpio_is_valid(pdata->gpio_reset))
if (!pdata->gpio_reset)
return -EINVAL;

ret = gpio_direction_output(pdata->gpio_reset, 0);
ret = gpiod_direction_output(pdata->gpio_reset, 0);
if (ret < 0)
goto err_gpio_reset;
return ret;
dev_info(&client->dev, "flash led reset successfully\n");

if (!gpio_is_valid(pdata->gpio_strobe)) {
ret = -EINVAL;
goto err_gpio_dir_reset;
}
if (!pdata->gpio_strobe)
return -EINVAL;

ret = gpio_direction_output(pdata->gpio_strobe, 0);
ret = gpiod_direction_output(pdata->gpio_strobe, 0);
if (ret < 0)
goto err_gpio_strobe;
return ret;

return 0;

err_gpio_strobe:
gpio_free(pdata->gpio_strobe);
err_gpio_dir_reset:
gpio_direction_output(pdata->gpio_reset, 0);
err_gpio_reset:
gpio_free(pdata->gpio_reset);

return ret;
}

static int lm3554_gpio_uninit(struct i2c_client *client)
Expand All @@ -802,35 +790,33 @@ static int lm3554_gpio_uninit(struct i2c_client *client)
struct lm3554_platform_data *pdata = flash->pdata;
int ret;

ret = gpio_direction_output(pdata->gpio_strobe, 0);
ret = gpiod_direction_output(pdata->gpio_strobe, 0);
if (ret < 0)
return ret;

ret = gpio_direction_output(pdata->gpio_reset, 0);
ret = gpiod_direction_output(pdata->gpio_reset, 0);
if (ret < 0)
return ret;

gpio_free(pdata->gpio_strobe);
gpio_free(pdata->gpio_reset);
return 0;
}

static void *lm3554_platform_data_func(struct i2c_client *client)
{
static struct lm3554_platform_data platform_data;

platform_data.gpio_reset =
desc_to_gpio(gpiod_get_index(&client->dev,
NULL, 2, GPIOD_OUT_LOW));
platform_data.gpio_strobe =
desc_to_gpio(gpiod_get_index(&client->dev,
NULL, 0, GPIOD_OUT_LOW));
platform_data.gpio_torch =
desc_to_gpio(gpiod_get_index(&client->dev,
NULL, 1, GPIOD_OUT_LOW));
dev_info(&client->dev, "camera pdata: lm3554: reset: %d strobe %d torch %d\n",
platform_data.gpio_reset, platform_data.gpio_strobe,
platform_data.gpio_torch);
platform_data.gpio_reset = gpiod_get_index(&client->dev,
NULL, 2, GPIOD_OUT_LOW);
if (IS_ERR(platform_data.gpio_reset))
return ERR_CAST(platform_data.gpio_reset);
platform_data.gpio_strobe = gpiod_get_index(&client->dev,
NULL, 0, GPIOD_OUT_LOW);
if (IS_ERR(platform_data.gpio_strobe))
return ERR_CAST(platform_data.gpio_strobe);
platform_data.gpio_torch = gpiod_get_index(&client->dev,
NULL, 1, GPIOD_OUT_LOW);
if (IS_ERR(platform_data.gpio_torch))
return ERR_CAST(platform_data.gpio_torch);

/* Set to TX2 mode, then ENVM/TX2 pin is a power amplifier sync input:
* ENVM/TX pin asserted, flash forced into torch;
Expand All @@ -857,6 +843,8 @@ static int lm3554_probe(struct i2c_client *client)
return -ENOMEM;

flash->pdata = lm3554_platform_data_func(client);
if (IS_ERR(flash->pdata))
return PTR_ERR(flash->pdata);

v4l2_i2c_subdev_init(&flash->sd, client, &lm3554_ops);
flash->sd.internal_ops = &lm3554_internal_ops;
Expand Down
7 changes: 4 additions & 3 deletions drivers/staging/media/atomisp/include/media/lm3554.h
Expand Up @@ -18,6 +18,7 @@
#ifndef _LM3554_H_
#define _LM3554_H_

#include <linux/gpio/consumer.h>
#include <linux/videodev2.h>
#include <media/v4l2-subdev.h>

Expand Down Expand Up @@ -119,9 +120,9 @@
* lm3554_platform_data - Flash controller platform data
*/
struct lm3554_platform_data {
int gpio_torch;
int gpio_strobe;
int gpio_reset;
struct gpio_desc *gpio_torch;
struct gpio_desc *gpio_strobe;
struct gpio_desc *gpio_reset;

unsigned int current_limit;
unsigned int envm_tx2;
Expand Down

0 comments on commit 9289cdf

Please sign in to comment.