summaryrefslogtreecommitdiff
path: root/drivers/staging/media/atomisp/i2c/imx/dw9718.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-05-05 18:16:23 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2017-05-05 18:16:23 -0700
commitc6a677c6f37bb7abc85ba7e3465e82b9f7eb1d91 (patch)
tree9d0d4bb2e150837297cddc5be7f1b4950e9ab228 /drivers/staging/media/atomisp/i2c/imx/dw9718.c
parente87d51ac61f88ae44fe14b34abe08566032d726b (diff)
parent11270059e8d0b6f80801fac910c4ef751ca05c4c (diff)
Merge tag 'staging-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging/IIO updates from Greg KH: "Here is the big staging tree update for 4.12-rc1. It's a big one, adding about 350k new lines of crap^Wcode, mostly all in a big dump of media drivers from Intel. But there's other new drivers in here as well, yet-another-wifi driver, new IIO drivers, and a new crypto accelerator. We also deleted a bunch of stuff, mostly in patch cleanups, but also the Android ION code has shrunk a lot, and the Android low memory killer driver was finally deleted, much to the celebration of the -mm developers. All of these have been in linux-next with a few build issues that will show up when you merge to your tree" Merge conflicts in the new rtl8723bs driver (due to the wifi changes this merge window) handled as per linux-next, courtesy of Stephen Rothwell. * tag 'staging-4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (1182 commits) staging: fsl-mc/dpio: add cpu <--> LE conversion for dpaa2_fd staging: ks7010: remove line continuations in quoted strings staging: vt6656: use tabs instead of spaces staging: android: ion: Fix unnecessary initialization of static variable staging: media: atomisp: fix range checking on clk_num staging: media: atomisp: fix misspelled word in comment staging: media: atomisp: kmap() can't fail staging: atomisp: remove #ifdef for runtime PM functions staging: atomisp: satm include directory is gone atomisp: remove some more unused files atomisp: remove hmm_load/store/clear indirections atomisp: kill off mmgr_free atomisp: clean up the hmm init/cleanup indirections atomisp: handle allocation calls before init in the hmm layer staging: fsl-dpaa2/eth: Add maintainer for Ethernet driver staging: fsl-dpaa2/eth: Add TODO file staging: fsl-dpaa2/eth: Add trace points staging: fsl-dpaa2/eth: Add driver specific stats staging: fsl-dpaa2/eth: Add ethtool support staging: fsl-dpaa2/eth: Add Freescale DPAA2 Ethernet driver ...
Diffstat (limited to 'drivers/staging/media/atomisp/i2c/imx/dw9718.c')
-rw-r--r--drivers/staging/media/atomisp/i2c/imx/dw9718.c238
1 files changed, 238 insertions, 0 deletions
diff --git a/drivers/staging/media/atomisp/i2c/imx/dw9718.c b/drivers/staging/media/atomisp/i2c/imx/dw9718.c
new file mode 100644
index 000000000000..65a1fcf187d5
--- /dev/null
+++ b/drivers/staging/media/atomisp/i2c/imx/dw9718.c
@@ -0,0 +1,238 @@
+/*
+ * Support for dw9718 vcm driver.
+ *
+ * Copyright (c) 2014 Intel Corporation. All Rights Reserved.
+ *
+ * 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 Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ */
+
+#include <linux/delay.h>
+#include "dw9718.h"
+
+static struct dw9718_device dw9718_dev;
+
+static int dw9718_i2c_rd8(struct i2c_client *client, u8 reg, u8 *val)
+{
+ struct i2c_msg msg[2];
+ u8 buf[2] = { reg };
+
+ msg[0].addr = DW9718_VCM_ADDR;
+ msg[0].flags = 0;
+ msg[0].len = 1;
+ msg[0].buf = buf;
+
+ msg[1].addr = DW9718_VCM_ADDR;
+ msg[1].flags = I2C_M_RD;
+ msg[1].len = 1;
+ msg[1].buf = &buf[1];
+ *val = 0;
+
+ if (i2c_transfer(client->adapter, msg, 2) != 2)
+ return -EIO;
+ *val = buf[1];
+
+ return 0;
+}
+
+static int dw9718_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
+{
+ struct i2c_msg msg;
+ u8 buf[2] = { reg, val};
+
+ msg.addr = DW9718_VCM_ADDR;
+ msg.flags = 0;
+ msg.len = sizeof(buf);
+ msg.buf = buf;
+
+ if (i2c_transfer(client->adapter, &msg, 1) != 1)
+ return -EIO;
+
+ return 0;
+}
+
+static int dw9718_i2c_wr16(struct i2c_client *client, u8 reg, u16 val)
+{
+ struct i2c_msg msg;
+ u8 buf[3] = { reg, (u8)(val >> 8), (u8)(val & 0xff)};
+
+ msg.addr = DW9718_VCM_ADDR;
+ msg.flags = 0;
+ msg.len = sizeof(buf);
+ msg.buf = buf;
+
+ if (i2c_transfer(client->adapter, &msg, 1) != 1)
+ return -EIO;
+
+ return 0;
+}
+
+int dw9718_t_focus_abs(struct v4l2_subdev *sd, s32 value)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+
+ value = clamp(value, 0, DW9718_MAX_FOCUS_POS);
+ ret = dw9718_i2c_wr16(client, DW9718_DATA_M, value);
+ /*pr_info("%s: value = %d\n", __func__, value);*/
+ if (ret < 0)
+ return ret;
+
+ getnstimeofday(&dw9718_dev.focus_time);
+ dw9718_dev.focus = value;
+
+ return 0;
+}
+
+int dw9718_vcm_power_up(struct v4l2_subdev *sd)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+ u8 value;
+
+ if (dw9718_dev.power_on)
+ return 0;
+
+ /* Enable power */
+ ret = dw9718_dev.platform_data->power_ctrl(sd, 1);
+ if (ret) {
+ dev_err(&client->dev, "DW9718_PD power_ctrl failed %d\n", ret);
+ return ret;
+ }
+ /* Wait for VBAT to stabilize */
+ udelay(100);
+
+ /* Detect device */
+ ret = dw9718_i2c_rd8(client, DW9718_SACT, &value);
+ if (ret < 0) {
+ dev_err(&client->dev, "read DW9718_SACT failed %d\n", ret);
+ goto fail_powerdown;
+ }
+ /*
+ * WORKAROUND: for module P8V12F-203 which are used on
+ * Cherrytrail Refresh Davis Reef AoB, register SACT is not
+ * returning default value as spec. But VCM works as expected and
+ * root cause is still under discussion with vendor.
+ * workaround here to avoid aborting the power up sequence and just
+ * give a warning about this error.
+ */
+ if (value != DW9718_SACT_DEFAULT_VAL)
+ dev_warn(&client->dev, "%s error, incorrect ID\n", __func__);
+
+ /* Initialize according to recommended settings */
+ ret = dw9718_i2c_wr8(client, DW9718_CONTROL,
+ DW9718_CONTROL_SW_LINEAR |
+ DW9718_CONTROL_S_SAC4 |
+ DW9718_CONTROL_OCP_DISABLE |
+ DW9718_CONTROL_UVLO_DISABLE);
+ if (ret < 0) {
+ dev_err(&client->dev, "write DW9718_CONTROL failed %d\n", ret);
+ goto fail_powerdown;
+ }
+ ret = dw9718_i2c_wr8(client, DW9718_SACT,
+ DW9718_SACT_MULT_TWO |
+ DW9718_SACT_PERIOD_8_8MS);
+ if (ret < 0) {
+ dev_err(&client->dev, "write DW9718_SACT failed %d\n", ret);
+ goto fail_powerdown;
+ }
+
+ ret = dw9718_t_focus_abs(sd, dw9718_dev.focus);
+ if (ret)
+ return ret;
+ dw9718_dev.initialized = true;
+ dw9718_dev.power_on = 1;
+
+ return 0;
+
+fail_powerdown:
+ dev_err(&client->dev, "%s error, powerup failed\n", __func__);
+ dw9718_dev.platform_data->power_ctrl(sd, 0);
+ return ret;
+}
+
+int dw9718_vcm_power_down(struct v4l2_subdev *sd)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+
+ if (!dw9718_dev.power_on)
+ return 0;
+
+ ret = dw9718_dev.platform_data->power_ctrl(sd, 0);
+ if (ret) {
+ dev_err(&client->dev, "%s power_ctrl failed\n",
+ __func__);
+ return ret;
+ }
+ dw9718_dev.power_on = 0;
+
+ return 0;
+}
+
+int dw9718_q_focus_status(struct v4l2_subdev *sd, s32 *value)
+{
+ static const struct timespec move_time = {
+ .tv_sec = 0,
+ .tv_nsec = 60000000
+ };
+ struct timespec current_time, finish_time, delta_time;
+
+ getnstimeofday(&current_time);
+ finish_time = timespec_add(dw9718_dev.focus_time, move_time);
+ delta_time = timespec_sub(current_time, finish_time);
+ if (delta_time.tv_sec >= 0 && delta_time.tv_nsec >= 0) {
+ *value = ATOMISP_FOCUS_HP_COMPLETE |
+ ATOMISP_FOCUS_STATUS_ACCEPTS_NEW_MOVE;
+ } else {
+ *value = ATOMISP_FOCUS_STATUS_MOVING |
+ ATOMISP_FOCUS_HP_IN_PROGRESS;
+ }
+
+ return 0;
+}
+
+int dw9718_t_focus_vcm(struct v4l2_subdev *sd, u16 val)
+{
+ return -EINVAL;
+}
+
+int dw9718_t_focus_rel(struct v4l2_subdev *sd, s32 value)
+{
+ return dw9718_t_focus_abs(sd, dw9718_dev.focus + value);
+}
+
+int dw9718_q_focus_abs(struct v4l2_subdev *sd, s32 *value)
+{
+ *value = dw9718_dev.focus;
+ return 0;
+}
+int dw9718_t_vcm_slew(struct v4l2_subdev *sd, s32 value)
+{
+ return 0;
+}
+
+int dw9718_t_vcm_timing(struct v4l2_subdev *sd, s32 value)
+{
+ return 0;
+}
+
+int dw9718_vcm_init(struct v4l2_subdev *sd)
+{
+ dw9718_dev.platform_data = camera_get_af_platform_data();
+ dw9718_dev.focus = DW9718_DEFAULT_FOCUS_POSITION;
+ dw9718_dev.power_on = 0;
+ return (NULL == dw9718_dev.platform_data) ? -ENODEV : 0;
+}