From ccfc97bdb5ae8b8edc55169ac6924e08449836ac Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Sat, 3 Mar 2012 17:19:52 -0300 Subject: [media] smiapp: Add driver Add driver for SMIA++/SMIA image sensors. The driver exposes the sensor as three subdevs, pixel array, binner and scaler --- in case the device has a scaler. Currently it relies on the board code for external clock handling. There is no fast way out of this dependency before the ISP drivers (omap3isp) among others will be able to export that clock through the clock framework instead. Signed-off-by: Sakari Ailus Acked-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/smiapp/smiapp.h | 251 ++++++++++++++++++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 drivers/media/video/smiapp/smiapp.h (limited to 'drivers/media/video/smiapp/smiapp.h') diff --git a/drivers/media/video/smiapp/smiapp.h b/drivers/media/video/smiapp/smiapp.h new file mode 100644 index 00000000000..805d8c8a3c1 --- /dev/null +++ b/drivers/media/video/smiapp/smiapp.h @@ -0,0 +1,251 @@ +/* + * drivers/media/video/smiapp/smiapp.h + * + * Generic driver for SMIA/SMIA++ compliant camera modules + * + * Copyright (C) 2010--2012 Nokia Corporation + * Contact: Sakari Ailus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#ifndef __SMIAPP_PRIV_H_ +#define __SMIAPP_PRIV_H_ + +#include +#include +#include +#include + +#include "../smiapp-pll.h" +#include "smiapp-reg.h" +#include "smiapp-regs.h" +#include "smiapp-quirk.h" + +/* + * Standard SMIA++ constants + */ +#define SMIA_VERSION_1 10 +#define SMIAPP_VERSION_0_8 8 /* Draft 0.8 */ +#define SMIAPP_VERSION_0_9 9 /* Draft 0.9 */ +#define SMIAPP_VERSION_1 10 + +#define SMIAPP_PROFILE_0 0 +#define SMIAPP_PROFILE_1 1 +#define SMIAPP_PROFILE_2 2 + +#define SMIAPP_NVM_PAGE_SIZE 64 /* bytes */ + +#define SMIAPP_RESET_DELAY_CLOCKS 2400 +#define SMIAPP_RESET_DELAY(clk) \ + (1000 + (SMIAPP_RESET_DELAY_CLOCKS * 1000 \ + + (clk) / 1000 - 1) / ((clk) / 1000)) + +#include "smiapp-limits.h" + +struct smiapp_quirk; + +#define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0) + +struct smiapp_module_ident { + u8 manufacturer_id; + u16 model_id; + u8 revision_number_major; + + u8 flags; + + char *name; + const struct smiapp_quirk *quirk; +}; + +struct smiapp_module_info { + u32 manufacturer_id; + u32 model_id; + u32 revision_number_major; + u32 revision_number_minor; + + u32 module_year; + u32 module_month; + u32 module_day; + + u32 sensor_manufacturer_id; + u32 sensor_model_id; + u32 sensor_revision_number; + u32 sensor_firmware_version; + + u32 smia_version; + u32 smiapp_version; + + u32 smiapp_profile; + + char *name; + const struct smiapp_quirk *quirk; +}; + +#define SMIAPP_IDENT_FQ(manufacturer, model, rev, fl, _name, _quirk) \ + { .manufacturer_id = manufacturer, \ + .model_id = model, \ + .revision_number_major = rev, \ + .flags = fl, \ + .name = _name, \ + .quirk = _quirk, } + +#define SMIAPP_IDENT_LQ(manufacturer, model, rev, _name, _quirk) \ + { .manufacturer_id = manufacturer, \ + .model_id = model, \ + .revision_number_major = rev, \ + .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ + .name = _name, \ + .quirk = _quirk, } + +#define SMIAPP_IDENT_L(manufacturer, model, rev, _name) \ + { .manufacturer_id = manufacturer, \ + .model_id = model, \ + .revision_number_major = rev, \ + .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ + .name = _name, } + +#define SMIAPP_IDENT_Q(manufacturer, model, rev, _name, _quirk) \ + { .manufacturer_id = manufacturer, \ + .model_id = model, \ + .revision_number_major = rev, \ + .flags = 0, \ + .name = _name, \ + .quirk = _quirk, } + +#define SMIAPP_IDENT(manufacturer, model, rev, _name) \ + { .manufacturer_id = manufacturer, \ + .model_id = model, \ + .revision_number_major = rev, \ + .flags = 0, \ + .name = _name, } + +struct smiapp_reg_limits { + u32 addr; + char *what; +}; + +extern struct smiapp_reg_limits smiapp_reg_limits[]; + +struct smiapp_csi_data_format { + u32 code; + u8 width; + u8 compressed; + u8 pixel_order; +}; + +#define SMIAPP_SUBDEVS 3 + +#define SMIAPP_PA_PAD_SRC 0 +#define SMIAPP_PAD_SINK 0 +#define SMIAPP_PAD_SRC 1 +#define SMIAPP_PADS 2 + +struct smiapp_binning_subtype { + u8 horizontal:4; + u8 vertical:4; +} __packed; + +struct smiapp_subdev { + struct v4l2_subdev sd; + struct media_pad pads[2]; + struct v4l2_rect sink_fmt; + struct v4l2_rect crop[2]; + struct v4l2_rect compose; /* compose on sink */ + unsigned short sink_pad; + unsigned short source_pad; + int npads; + struct smiapp_sensor *sensor; + struct v4l2_ctrl_handler ctrl_handler; +}; + +/* + * struct smiapp_sensor - Main device structure + */ +struct smiapp_sensor { + /* + * "mutex" is used to serialise access to all fields here + * except v4l2_ctrls at the end of the struct. "mutex" is also + * used to serialise access to file handle specific + * information. The exception to this rule is the power_mutex + * below. + */ + struct mutex mutex; + /* + * power_mutex is used to serialise power management related + * activities. Acquiring "mutex" at that time isn't necessary + * since there are no other users anyway. + */ + struct mutex power_mutex; + struct smiapp_subdev ssds[SMIAPP_SUBDEVS]; + u32 ssds_used; + struct smiapp_subdev *src; + struct smiapp_subdev *binner; + struct smiapp_subdev *scaler; + struct smiapp_subdev *pixel_array; + struct smiapp_platform_data *platform_data; + struct regulator *vana; + u32 limits[SMIAPP_LIMIT_LAST]; + u8 nbinning_subtypes; + struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES]; + u32 mbus_frame_fmts; + const struct smiapp_csi_data_format *csi_format; + const struct smiapp_csi_data_format *internal_csi_format; + u32 default_mbus_frame_fmts; + int default_pixel_order; + + u8 binning_horizontal; + u8 binning_vertical; + + u8 scale_m; + u8 scaling_mode; + + u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */ + u8 flash_capability; + u8 frame_skip; + + int power_count; + + bool streaming; + bool dev_init_done; + + u8 *nvm; /* nvm memory buffer */ + unsigned int nvm_size; /* bytes */ + + struct smiapp_module_info minfo; + + struct smiapp_pll pll; + + /* Pixel array controls */ + struct v4l2_ctrl *analog_gain; + struct v4l2_ctrl *exposure; + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vflip; + struct v4l2_ctrl *vblank; + struct v4l2_ctrl *hblank; + struct v4l2_ctrl *pixel_rate_parray; + /* src controls */ + struct v4l2_ctrl *link_freq; + struct v4l2_ctrl *pixel_rate_csi; +}; + +#define to_smiapp_subdev(_sd) \ + container_of(_sd, struct smiapp_subdev, sd) + +#define to_smiapp_sensor(_sd) \ + (to_smiapp_subdev(_sd)->sensor) + +#endif /* __SMIAPP_PRIV_H_ */ -- cgit v1.2.3-70-g09d2 From f9b26cd8e2cb8979694c48ea642d30784e7aceb3 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Tue, 15 May 2012 10:36:09 -0300 Subject: [media] smiapp: fix compilation breakage The usage of ../*.h breaks out-of-tree compilation and likely breaks compilation when O= argument is used. Instead of doing that, just add the include path via Makefile. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/smiapp/Makefile | 2 ++ drivers/media/video/smiapp/smiapp.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers/media/video/smiapp/smiapp.h') diff --git a/drivers/media/video/smiapp/Makefile b/drivers/media/video/smiapp/Makefile index 5a207eecd35..36b0cfa2c54 100644 --- a/drivers/media/video/smiapp/Makefile +++ b/drivers/media/video/smiapp/Makefile @@ -1,3 +1,5 @@ smiapp-objs += smiapp-core.o smiapp-regs.o \ smiapp-quirk.o smiapp-limits.o obj-$(CONFIG_VIDEO_SMIAPP) += smiapp.o + +ccflags-y += -Idrivers/media/video diff --git a/drivers/media/video/smiapp/smiapp.h b/drivers/media/video/smiapp/smiapp.h index 805d8c8a3c1..35b9216e48c 100644 --- a/drivers/media/video/smiapp/smiapp.h +++ b/drivers/media/video/smiapp/smiapp.h @@ -30,7 +30,7 @@ #include #include -#include "../smiapp-pll.h" +#include "smiapp-pll.h" #include "smiapp-reg.h" #include "smiapp-regs.h" #include "smiapp-quirk.h" -- cgit v1.2.3-70-g09d2 From 2547428de05d5bc45d3144a0ebc51e3f249a2bc0 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Sun, 22 Apr 2012 08:24:33 -0300 Subject: [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: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/smiapp/smiapp-core.c | 55 ++++++++++++++++++++++++++++---- drivers/media/video/smiapp/smiapp.h | 1 + include/media/smiapp.h | 1 + 3 files changed, 50 insertions(+), 7 deletions(-) (limited to 'drivers/media/video/smiapp/smiapp.h') diff --git a/drivers/media/video/smiapp/smiapp-core.c b/drivers/media/video/smiapp/smiapp-core.c index a8a1db9563b..999f3fc867c 100644 --- a/drivers/media/video/smiapp/smiapp-core.c +++ b/drivers/media/video/smiapp/smiapp-core.c @@ -26,6 +26,7 @@ * */ +#include #include #include #include @@ -1111,8 +1112,11 @@ static int smiapp_power_on(struct smiapp_sensor *sensor) } usleep_range(1000, 1000); - rval = sensor->platform_data->set_xclk(&sensor->src->sd, - sensor->platform_data->ext_clk); + if (sensor->platform_data->set_xclk) + rval = sensor->platform_data->set_xclk( + &sensor->src->sd, sensor->platform_data->ext_clk); + else + rval = clk_enable(sensor->ext_clk); if (rval < 0) { dev_dbg(&client->dev, "failed to set xclk\n"); goto out_xclk_fail; @@ -1231,7 +1235,10 @@ static int smiapp_power_on(struct smiapp_sensor *sensor) out_cci_addr_fail: if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) 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: regulator_disable(sensor->vana); @@ -1256,7 +1263,10 @@ static void smiapp_power_off(struct smiapp_sensor *sensor) if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) 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); regulator_disable(sensor->vana); sensor->streaming = 0; @@ -2327,6 +2337,28 @@ static int smiapp_registered(struct v4l2_subdev *subdev) 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 (gpio_request_one(sensor->platform_data->xshutdown, 0, "SMIA++ xshutdown") != 0) { @@ -2334,7 +2366,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev) "unable to acquire reset gpio %d\n", sensor->platform_data->xshutdown); rval = -ENODEV; - goto out_gpio_request; + goto out_clk_set_rate; } } @@ -2589,7 +2621,11 @@ out_smiapp_power_on: if (sensor->platform_data->xshutdown != SMIAPP_NO_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); sensor->vana = NULL; return rval; @@ -2778,7 +2814,10 @@ static int __exit smiapp_remove(struct i2c_client *client) if (sensor->power_count) { if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) 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; } @@ -2794,6 +2833,8 @@ static int __exit smiapp_remove(struct i2c_client *client) smiapp_free_controls(sensor); if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) gpio_free(sensor->platform_data->xshutdown); + if (sensor->ext_clk) + clk_put(sensor->ext_clk); if (sensor->vana) regulator_put(sensor->vana); diff --git a/drivers/media/video/smiapp/smiapp.h b/drivers/media/video/smiapp/smiapp.h index 35b9216e48c..587f7f11238 100644 --- a/drivers/media/video/smiapp/smiapp.h +++ b/drivers/media/video/smiapp/smiapp.h @@ -198,6 +198,7 @@ struct smiapp_sensor { struct smiapp_subdev *pixel_array; struct smiapp_platform_data *platform_data; struct regulator *vana; + struct clk *ext_clk; u32 limits[SMIAPP_LIMIT_LAST]; u8 nbinning_subtypes; struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES]; diff --git a/include/media/smiapp.h b/include/media/smiapp.h index a7877cd0733..9ab07fd45d5 100644 --- a/include/media/smiapp.h +++ b/include/media/smiapp.h @@ -77,6 +77,7 @@ struct smiapp_platform_data { struct smiapp_flash_strobe_parms *strobe_setup; int (*set_xclk)(struct v4l2_subdev *sd, int hz); + char *ext_clk_name; int xshutdown; /* gpio or SMIAPP_NO_XSHUTDOWN */ }; -- cgit v1.2.3-70-g09d2