Commit 2547428d authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

[media] smiapp: Allow using external clock from the clock framework

Instead of providing a function in platform data, allow also providing the
name of the external clock and use it through the clock framework.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@maxwell.research.nokia.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 13c6a9f7
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* *
*/ */
#include <linux/clk.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/gpio.h> #include <linux/gpio.h>
...@@ -1111,8 +1112,11 @@ static int smiapp_power_on(struct smiapp_sensor *sensor) ...@@ -1111,8 +1112,11 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
} }
usleep_range(1000, 1000); usleep_range(1000, 1000);
rval = sensor->platform_data->set_xclk(&sensor->src->sd, if (sensor->platform_data->set_xclk)
sensor->platform_data->ext_clk); rval = sensor->platform_data->set_xclk(
&sensor->src->sd, sensor->platform_data->ext_clk);
else
rval = clk_enable(sensor->ext_clk);
if (rval < 0) { if (rval < 0) {
dev_dbg(&client->dev, "failed to set xclk\n"); dev_dbg(&client->dev, "failed to set xclk\n");
goto out_xclk_fail; goto out_xclk_fail;
...@@ -1231,7 +1235,10 @@ static int smiapp_power_on(struct smiapp_sensor *sensor) ...@@ -1231,7 +1235,10 @@ static int smiapp_power_on(struct smiapp_sensor *sensor)
out_cci_addr_fail: out_cci_addr_fail:
if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
gpio_set_value(sensor->platform_data->xshutdown, 0); gpio_set_value(sensor->platform_data->xshutdown, 0);
sensor->platform_data->set_xclk(&sensor->src->sd, 0); if (sensor->platform_data->set_xclk)
sensor->platform_data->set_xclk(&sensor->src->sd, 0);
else
clk_disable(sensor->ext_clk);
out_xclk_fail: out_xclk_fail:
regulator_disable(sensor->vana); regulator_disable(sensor->vana);
...@@ -1256,7 +1263,10 @@ static void smiapp_power_off(struct smiapp_sensor *sensor) ...@@ -1256,7 +1263,10 @@ static void smiapp_power_off(struct smiapp_sensor *sensor)
if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
gpio_set_value(sensor->platform_data->xshutdown, 0); gpio_set_value(sensor->platform_data->xshutdown, 0);
sensor->platform_data->set_xclk(&sensor->src->sd, 0); if (sensor->platform_data->set_xclk)
sensor->platform_data->set_xclk(&sensor->src->sd, 0);
else
clk_disable(sensor->ext_clk);
usleep_range(5000, 5000); usleep_range(5000, 5000);
regulator_disable(sensor->vana); regulator_disable(sensor->vana);
sensor->streaming = 0; sensor->streaming = 0;
...@@ -2327,6 +2337,28 @@ static int smiapp_registered(struct v4l2_subdev *subdev) ...@@ -2327,6 +2337,28 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
return -ENODEV; return -ENODEV;
} }
if (!sensor->platform_data->set_xclk) {
sensor->ext_clk = clk_get(&client->dev,
sensor->platform_data->ext_clk_name);
if (IS_ERR(sensor->ext_clk)) {
dev_err(&client->dev, "could not get clock %s\n",
sensor->platform_data->ext_clk_name);
rval = -ENODEV;
goto out_clk_get;
}
rval = clk_set_rate(sensor->ext_clk,
sensor->platform_data->ext_clk);
if (rval < 0) {
dev_err(&client->dev,
"unable to set clock %s freq to %u\n",
sensor->platform_data->ext_clk_name,
sensor->platform_data->ext_clk);
rval = -ENODEV;
goto out_clk_set_rate;
}
}
if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) { if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
if (gpio_request_one(sensor->platform_data->xshutdown, 0, if (gpio_request_one(sensor->platform_data->xshutdown, 0,
"SMIA++ xshutdown") != 0) { "SMIA++ xshutdown") != 0) {
...@@ -2334,7 +2366,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev) ...@@ -2334,7 +2366,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
"unable to acquire reset gpio %d\n", "unable to acquire reset gpio %d\n",
sensor->platform_data->xshutdown); sensor->platform_data->xshutdown);
rval = -ENODEV; rval = -ENODEV;
goto out_gpio_request; goto out_clk_set_rate;
} }
} }
...@@ -2589,7 +2621,11 @@ static int smiapp_registered(struct v4l2_subdev *subdev) ...@@ -2589,7 +2621,11 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
gpio_free(sensor->platform_data->xshutdown); gpio_free(sensor->platform_data->xshutdown);
out_gpio_request: out_clk_set_rate:
clk_put(sensor->ext_clk);
sensor->ext_clk = NULL;
out_clk_get:
regulator_put(sensor->vana); regulator_put(sensor->vana);
sensor->vana = NULL; sensor->vana = NULL;
return rval; return rval;
...@@ -2778,7 +2814,10 @@ static int __exit smiapp_remove(struct i2c_client *client) ...@@ -2778,7 +2814,10 @@ static int __exit smiapp_remove(struct i2c_client *client)
if (sensor->power_count) { if (sensor->power_count) {
if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
gpio_set_value(sensor->platform_data->xshutdown, 0); gpio_set_value(sensor->platform_data->xshutdown, 0);
sensor->platform_data->set_xclk(&sensor->src->sd, 0); if (sensor->platform_data->set_xclk)
sensor->platform_data->set_xclk(&sensor->src->sd, 0);
else
clk_disable(sensor->ext_clk);
sensor->power_count = 0; sensor->power_count = 0;
} }
...@@ -2794,6 +2833,8 @@ static int __exit smiapp_remove(struct i2c_client *client) ...@@ -2794,6 +2833,8 @@ static int __exit smiapp_remove(struct i2c_client *client)
smiapp_free_controls(sensor); smiapp_free_controls(sensor);
if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
gpio_free(sensor->platform_data->xshutdown); gpio_free(sensor->platform_data->xshutdown);
if (sensor->ext_clk)
clk_put(sensor->ext_clk);
if (sensor->vana) if (sensor->vana)
regulator_put(sensor->vana); regulator_put(sensor->vana);
......
...@@ -198,6 +198,7 @@ struct smiapp_sensor { ...@@ -198,6 +198,7 @@ struct smiapp_sensor {
struct smiapp_subdev *pixel_array; struct smiapp_subdev *pixel_array;
struct smiapp_platform_data *platform_data; struct smiapp_platform_data *platform_data;
struct regulator *vana; struct regulator *vana;
struct clk *ext_clk;
u32 limits[SMIAPP_LIMIT_LAST]; u32 limits[SMIAPP_LIMIT_LAST];
u8 nbinning_subtypes; u8 nbinning_subtypes;
struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES]; struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES];
......
...@@ -77,6 +77,7 @@ struct smiapp_platform_data { ...@@ -77,6 +77,7 @@ struct smiapp_platform_data {
struct smiapp_flash_strobe_parms *strobe_setup; struct smiapp_flash_strobe_parms *strobe_setup;
int (*set_xclk)(struct v4l2_subdev *sd, int hz); int (*set_xclk)(struct v4l2_subdev *sd, int hz);
char *ext_clk_name;
int xshutdown; /* gpio or SMIAPP_NO_XSHUTDOWN */ int xshutdown; /* gpio or SMIAPP_NO_XSHUTDOWN */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment