2 * SH532U focuser driver.
4 * Copyright (C) 2011 NVIDIA Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * The board level details about the device need to be provided in the board
24 * file with the sh532u_platform_data structure.
25 * Standard among NVC kernel drivers in this structure is:
26 * .cfg = Use the NVC_CFG_ defines that are in nvc.h.
27 * Descriptions of the configuration options are with the defines.
28 * This value is typically 0.
29 * .num = The number of the instance of the device. This should start at 1 and
30 * and increment for each device on the board. This number will be
31 * appended to the MISC driver name, Example: /dev/focuser.1
32 * If not used or 0, then nothing is appended to the name.
33 * .sync = If there is a need to synchronize two devices, then this value is
34 * the number of the device instance (.num above) this device is to
35 * sync to. For example:
36 * Device 1 platform entries =
39 * Device 2 platfrom entries =
42 * The above example sync's device 1 and 2.
43 * This is typically used for stereo applications.
44 * .dev_name = The MISC driver name the device registers as. If not used,
45 * then the part number of the device is used for the driver name.
46 * If using the NVC user driver then use the name found in this
47 * driver under _default_pdata.
49 * The following is specific to NVC kernel focus drivers:
50 * .nvc = Pointer to the nvc_focus_nvc structure. This structure needs to
51 * be defined and populated if overriding the driver defaults.
52 * .cap = Pointer to the nvc_focus_cap structure. This structure needs to
53 * be defined and populated if overriding the driver defaults.
55 * The following is specific to only this NVC kernel focus driver:
56 * .info = Pointer to the sh532u_pdata_info structure. This structure does
57 * not need to be defined and populated unless overriding ROM data.
58 .* .i2c_addr_rom = The I2C address of the onboard ROM.
59 * .gpio_reset = The GPIO connected to the devices reset. If not used then
61 * .gpio_en = Due to a Linux limitation, a GPIO is defined to "enable" the
62 * device. This workaround is for when the device's power GPIO's
63 * are behind an I2C expander. The Linux limitation doesn't allow
64 * the I2C GPIO expander to be ready for use when this device is
65 * probed. When this problem is solved, this driver needs to
66 * remove the gpio_en WAR.
69 * The board power file must contain the following labels for the power
70 * regulator(s) of this device:
71 * "vdd" = the power regulator for the device's power.
72 * "vdd_i2c" = the power regulator for the I2C power.
74 * The above values should be all that is needed to use the device with this
75 * driver. Modifications of this driver should not be needed.
80 #include <linux/i2c.h>
81 #include <linux/miscdevice.h>
82 #include <linux/slab.h>
83 #include <linux/delay.h>
84 #include <linux/uaccess.h>
85 #include <linux/list.h>
86 #include <linux/jiffies.h>
87 #include <linux/gpio.h>
88 #include <linux/module.h>
90 #include <media/nvc.h>
91 #include <media/sh532u.h>
93 #define SH532U_ID 0xF0
94 /* defaults if no ROM data */
95 #define SH532U_HYPERFOCAL_RATIO 1836 /* 41.2f/224.4f Ratio source: SEMCO */
96 /* _HYPERFOCAL_RATIO is multiplied and _HYPERFOCAL_DIV divides for float */
97 #define SH532U_HYPERFOCAL_DIV 10000
98 #define SH532U_FOCAL_LENGTH 0x408D70A4
99 #define SH532U_FNUMBER 0x40333333
100 #define SH532U_MAX_APERATURE 0x3FCA0EA1
101 /* SH532U_CAPS_VER = 0: invalid value */
102 /* SH532U_CAPS_VER = 1: added NVC_PARAM_STS */
103 /* SH532U_CAPS_VER = 2: expanded nvc_focus_cap */
104 #define SH532U_CAPS_VER 2
105 #define SH532U_ACTUATOR_RANGE 1000
106 #define SH532U_SETTLETIME 30
107 #define SH532U_FOCUS_MACRO 950
108 #define SH532U_FOCUS_HYPER 250
109 #define SH532U_FOCUS_INFINITY 50
110 #define SH532U_TIMEOUT_MS 200
111 #define SH532U_POS_LOW_DEFAULT 0xA000
112 #define SH532U_POS_HIGH_DEFAULT 0x6000
117 struct i2c_client *i2c_client;
118 struct sh532u_platform_data *pdata;
119 struct miscdevice miscdev;
120 struct list_head list;
123 struct nvc_regulator vreg_vdd;
124 struct nvc_regulator vreg_i2c;
126 struct sh532u_info *s_info;
127 unsigned i2c_addr_rom;
128 struct nvc_focus_nvc nvc;
129 struct nvc_focus_cap cap;
130 enum nvc_focus_sts sts;
131 struct sh532u_pdata_info cfg;
132 bool gpio_flag_reset;
141 static struct sh532u_pdata_info sh532u_default_info = {
142 .move_timeoutms = SH532U_TIMEOUT_MS,
143 .focus_hyper_ratio = SH532U_HYPERFOCAL_RATIO,
144 .focus_hyper_div = SH532U_HYPERFOCAL_DIV,
147 static struct nvc_focus_cap sh532u_default_cap = {
148 .version = SH532U_CAPS_VER,
149 .actuator_range = SH532U_ACTUATOR_RANGE,
150 .settle_time = SH532U_SETTLETIME,
151 .focus_macro = SH532U_FOCUS_MACRO,
152 .focus_hyper = SH532U_FOCUS_HYPER,
153 .focus_infinity = SH532U_FOCUS_INFINITY,
156 static struct nvc_focus_nvc sh532u_default_nvc = {
157 .focal_length = SH532U_FOCAL_LENGTH,
158 .fnumber = SH532U_FNUMBER,
159 .max_aperature = SH532U_MAX_APERATURE,
162 static struct sh532u_platform_data sh532u_default_pdata = {
166 .dev_name = "focuser",
167 .i2c_addr_rom = 0x50,
170 static u32 sh532u_a2buf[] = {
189 static LIST_HEAD(sh532u_info_list);
190 static DEFINE_SPINLOCK(sh532u_spinlock);
193 static int sh532u_i2c_rd8(struct sh532u_info *info, u8 addr, u8 reg, u8 *val)
195 struct i2c_msg msg[2];
203 msg[0].addr = info->i2c_client->addr;
204 msg[1].addr = info->i2c_client->addr;
208 msg[0].buf = &buf[0];
209 msg[1].flags = I2C_M_RD;
211 msg[1].buf = &buf[1];
213 if (i2c_transfer(info->i2c_client->adapter, msg, 2) != 2)
220 static int sh532u_i2c_wr8(struct sh532u_info *info, u8 reg, u8 val)
227 msg.addr = info->i2c_client->addr;
231 if (i2c_transfer(info->i2c_client->adapter, &msg, 1) != 1)
237 static int sh532u_i2c_rd16(struct sh532u_info *info, u8 reg, u16 *val)
239 struct i2c_msg msg[2];
243 msg[0].addr = info->i2c_client->addr;
246 msg[0].buf = &buf[0];
247 msg[1].addr = info->i2c_client->addr;
248 msg[1].flags = I2C_M_RD;
250 msg[1].buf = &buf[1];
251 if (i2c_transfer(info->i2c_client->adapter, msg, 2) != 2)
254 *val = (((u16)buf[1] << 8) | (u16)buf[2]);
259 static int sh532u_i2c_wr16(struct sh532u_info *info, u8 reg, u16 val)
265 buf[1] = (u8)(val >> 8);
266 buf[2] = (u8)(val & 0xff);
267 msg.addr = info->i2c_client->addr;
271 if (i2c_transfer(info->i2c_client->adapter, &msg, 1) != 1)
277 static int sh532u_i2c_rd32(struct sh532u_info *info, u8 addr, u8 reg, u32 *val)
279 struct i2c_msg msg[2];
287 msg[0].addr = info->i2c_client->addr;
288 msg[1].addr = info->i2c_client->addr;
292 msg[0].buf = &buf[0];
293 msg[1].flags = I2C_M_RD;
295 msg[1].buf = &buf[1];
296 if (i2c_transfer(info->i2c_client->adapter, msg, 2) != 2)
299 *val = (((u32)buf[4] << 24) | ((u32)buf[3] << 16) |
300 ((u32)buf[2] << 8) | ((u32)buf[1]));
304 static void sh532u_gpio_en(struct sh532u_info *info, int val)
306 if (info->pdata->gpio_en)
307 gpio_set_value_cansleep(info->pdata->gpio_en, val);
310 static void sh532u_gpio_reset(struct sh532u_info *info, int val)
313 if (!info->gpio_flag_reset && info->pdata->gpio_reset) {
314 gpio_set_value_cansleep(info->pdata->gpio_reset, 0);
316 gpio_set_value_cansleep(info->pdata->gpio_reset, 1);
317 mdelay(10); /* delay for device startup */
318 info->gpio_flag_reset = 1;
321 info->gpio_flag_reset = 0;
325 static void sh532u_pm_regulator_put(struct nvc_regulator *sreg)
327 regulator_put(sreg->vreg);
331 static int sh532u_pm_regulator_get(struct sh532u_info *info,
332 struct nvc_regulator *sreg,
338 sreg->vreg = regulator_get(&info->i2c_client->dev, vreg_name);
339 if (IS_ERR_OR_NULL(sreg->vreg)) {
340 dev_err(&info->i2c_client->dev,
341 "%s err for regulator: %s err: %d\n",
342 __func__, vreg_name, (int)sreg->vreg);
343 err = PTR_ERR(sreg->vreg);
346 sreg->vreg_name = vreg_name;
347 dev_dbg(&info->i2c_client->dev,
348 "%s vreg_name: %s\n",
349 __func__, sreg->vreg_name);
354 static int sh532u_pm_regulator_en(struct sh532u_info *info,
355 struct nvc_regulator *sreg)
359 if (!sreg->vreg_flag && (sreg->vreg != NULL)) {
360 err = regulator_enable(sreg->vreg);
362 dev_dbg(&info->i2c_client->dev,
363 "%s vreg_name: %s\n",
364 __func__, sreg->vreg_name);
366 err = 1; /* flag regulator state change */
368 dev_err(&info->i2c_client->dev,
369 "%s err, regulator: %s\n",
370 __func__, sreg->vreg_name);
376 static int sh532u_pm_regulator_dis(struct sh532u_info *info,
377 struct nvc_regulator *sreg)
381 if (sreg->vreg_flag && (sreg->vreg != NULL)) {
382 err = regulator_disable(sreg->vreg);
384 dev_err(&info->i2c_client->dev,
385 "%s err, regulator: %s\n",
386 __func__, sreg->vreg_name);
392 static int sh532u_pm_wr(struct sh532u_info *info, int pwr)
396 if ((info->pdata->cfg & (NVC_CFG_OFF2STDBY | NVC_CFG_BOOT_INIT)) &&
397 (pwr == NVC_PWR_OFF ||
398 pwr == NVC_PWR_STDBY_OFF))
401 if (pwr == info->pwr_dev)
405 case NVC_PWR_OFF_FORCE:
407 sh532u_gpio_en(info, 0);
408 err = sh532u_pm_regulator_dis(info, &info->vreg_vdd);
409 err |= sh532u_pm_regulator_dis(info, &info->vreg_i2c);
410 sh532u_gpio_reset(info, 0);
413 case NVC_PWR_STDBY_OFF:
415 err = sh532u_pm_regulator_en(info, &info->vreg_vdd);
416 err |= sh532u_pm_regulator_en(info, &info->vreg_i2c);
417 sh532u_gpio_en(info, 1);
418 sh532u_gpio_reset(info, 1);
419 err |= sh532u_i2c_wr8(info, STBY_211, 0x80);
420 err |= sh532u_i2c_wr8(info, CLKSEL_211, 0x38);
421 err |= sh532u_i2c_wr8(info, CLKSEL_211, 0x39);
426 err = sh532u_pm_regulator_en(info, &info->vreg_vdd);
427 err |= sh532u_pm_regulator_en(info, &info->vreg_i2c);
428 sh532u_gpio_en(info, 1);
429 sh532u_gpio_reset(info, 1);
430 err |= sh532u_i2c_wr8(info, CLKSEL_211, 0x38);
431 err |= sh532u_i2c_wr8(info, CLKSEL_211, 0x34);
432 err |= sh532u_i2c_wr8(info, STBY_211, 0xF0);
441 dev_err(&info->i2c_client->dev, "%s pwr err: %d\n",
452 static int sh532u_pm_wr_s(struct sh532u_info *info, int pwr)
457 if ((info->s_mode == NVC_SYNC_OFF) ||
458 (info->s_mode == NVC_SYNC_MASTER) ||
459 (info->s_mode == NVC_SYNC_STEREO))
460 err1 = sh532u_pm_wr(info, pwr);
461 if ((info->s_mode == NVC_SYNC_SLAVE) ||
462 (info->s_mode == NVC_SYNC_STEREO))
463 err2 = sh532u_pm_wr(info->s_info, pwr);
467 static int sh532u_pm_api_wr(struct sh532u_info *info, int pwr)
471 if (!pwr || (pwr > NVC_PWR_ON))
474 if (pwr > info->pwr_dev)
475 err = sh532u_pm_wr_s(info, pwr);
479 info->pwr_api = NVC_PWR_ERR;
480 if (info->pdata->cfg & NVC_CFG_NOERR)
486 static int sh532u_pm_dev_wr(struct sh532u_info *info, int pwr)
488 if (pwr < info->pwr_api)
490 if (info->sts == NVC_FOCUS_STS_WAIT_FOR_MOVE_END)
492 return sh532u_pm_wr(info, pwr);
495 static void sh532u_pm_exit(struct sh532u_info *info)
497 sh532u_pm_wr(info, NVC_PWR_OFF_FORCE);
498 sh532u_pm_regulator_put(&info->vreg_vdd);
499 sh532u_pm_regulator_put(&info->vreg_i2c);
500 if (info->s_info != NULL) {
501 sh532u_pm_wr(info->s_info, NVC_PWR_OFF_FORCE);
502 sh532u_pm_regulator_put(&info->s_info->vreg_vdd);
503 sh532u_pm_regulator_put(&info->s_info->vreg_i2c);
507 static void sh532u_pm_init(struct sh532u_info *info)
509 sh532u_pm_regulator_get(info, &info->vreg_vdd, "vdd");
510 sh532u_pm_regulator_get(info, &info->vreg_i2c, "vdd_i2c");
513 static int sh532u_dev_id(struct sh532u_info *info)
518 err = sh532u_i2c_rd8(info, 0, HVCA_DEVICE_ID, &val);
519 if (!err && (val == SH532U_ID))
525 static void sh532u_sts_rd(struct sh532u_info *info)
531 if (info->sts == NVC_FOCUS_STS_INITIALIZING)
534 info->sts = NVC_FOCUS_STS_NO_DEVICE; /* assume I2C err */
535 err = sh532u_i2c_rd8(info, 0, STMVEN_211, &us_tmp);
536 err |= sh532u_i2c_rd16(info, RZ_211H, &us_smv_fin);
540 /* StepMove Error Handling, Unexpected Position */
541 if ((us_smv_fin == 0x7FFF) || (us_smv_fin == 0x8001))
542 /* Stop StepMove Operation */
543 sh532u_i2c_wr8(info, STMVEN_211, us_tmp & 0xFE);
544 if (us_tmp & STMVEN_ON) {
545 err = sh532u_i2c_rd8(info, 0, MSSET_211, &us_tmp);
547 if (us_tmp & CHTGST_ON)
548 info->sts = NVC_FOCUS_STS_WAIT_FOR_SETTLE;
550 info->sts = NVC_FOCUS_STS_LENS_SETTLED;
553 info->sts = NVC_FOCUS_STS_WAIT_FOR_MOVE_END;
557 static s16 sh532u_rel2abs(struct sh532u_info *info, u32 rel_position)
561 if (rel_position > info->cap.actuator_range)
562 rel_position = info->cap.actuator_range;
563 rel_position = info->cap.actuator_range - rel_position;
565 rel_position *= info->abs_range;
566 rel_position /= info->cap.actuator_range;
568 abs_pos = (s16)(info->abs_base + rel_position);
569 if (abs_pos < info->cfg.limit_low)
570 abs_pos = info->cfg.limit_low;
571 if (abs_pos > info->cfg.limit_high)
572 abs_pos = info->cfg.limit_high;
576 static u32 sh532u_abs2rel(struct sh532u_info *info, s16 abs_position)
580 if (abs_position > info->cfg.limit_high)
581 abs_position = info->cfg.limit_high;
582 if (abs_position < info->abs_base)
583 abs_position = info->abs_base;
584 rel_pos = (u32)(abs_position - info->abs_base);
585 rel_pos *= info->cap.actuator_range;
586 rel_pos /= info->abs_range;
587 if (rel_pos > info->cap.actuator_range)
588 rel_pos = info->cap.actuator_range;
589 rel_pos = info->cap.actuator_range - rel_pos;
593 static int sh532u_abs_pos_rd(struct sh532u_info *info, s16 *position)
598 err = sh532u_i2c_rd16(info, RZ_211H, &abs_pos);
599 *position = (s16)abs_pos;
603 static int sh532u_rel_pos_rd(struct sh532u_info *info, u32 *position)
610 err = sh532u_abs_pos_rd(info, &abs_pos);
614 if ((abs_pos >= (info->pos_abs - STMV_SIZE)) &&
615 (abs_pos <= (info->pos_abs + STMV_SIZE))) {
616 pos = (int)info->pos_rel;
619 msec -= info->pos_time_wr;
620 msec = msec * 1000 / HZ;
622 if ((info->sts == NVC_FOCUS_STS_LENS_SETTLED) ||
623 (msec > info->cfg.move_timeoutms)) {
624 pos = (int)info->pos_rel;
626 pos = (int)sh532u_abs2rel(info, abs_pos);
627 if ((pos == (info->pos_rel - 1)) ||
628 (pos == (info->pos_rel + 1)))
629 pos = (int)info->pos_rel;
634 *position = (u32)pos;
638 static int sh532u_calibration(struct sh532u_info *info, bool use_defaults)
651 if (info->init_cal_flag)
655 memcpy(&info->cfg, &sh532u_default_info, sizeof(info->cfg));
656 memcpy(&info->nvc, &sh532u_default_nvc, sizeof(info->nvc));
657 memcpy(&info->cap, &sh532u_default_cap, sizeof(info->cap));
658 if (info->pdata->i2c_addr_rom)
659 info->i2c_addr_rom = info->pdata->i2c_addr_rom;
661 info->i2c_addr_rom = sh532u_default_pdata.i2c_addr_rom;
662 /* set overrides if any */
663 if (info->pdata->nvc) {
664 if (info->pdata->nvc->fnumber)
665 info->nvc.fnumber = info->pdata->nvc->fnumber;
666 if (info->pdata->nvc->focal_length)
667 info->nvc.focal_length =
668 info->pdata->nvc->focal_length;
669 if (info->pdata->nvc->max_aperature)
670 info->nvc.max_aperature =
671 info->pdata->nvc->max_aperature;
673 if (info->pdata->cap) {
674 if (info->pdata->cap->actuator_range)
675 info->cap.actuator_range =
676 info->pdata->cap->actuator_range;
677 if (info->pdata->cap->settle_time)
678 info->cap.settle_time = info->pdata->cap->settle_time;
679 if (info->pdata->cap->focus_macro)
680 info->cap.focus_macro = info->pdata->cap->focus_macro;
681 if (info->pdata->cap->focus_hyper)
682 info->cap.focus_hyper = info->pdata->cap->focus_hyper;
683 if (info->pdata->cap->focus_infinity)
684 info->cap.focus_infinity =
685 info->pdata->cap->focus_infinity;
689 * Inf1 and Mac1 are the mechanical limit position.
691 * Mac1: bottom limit.
693 err = sh532u_i2c_rd8(info, info->i2c_addr_rom, addrMac1, ®);
694 if (!err && (reg != 0) && (reg != 0xFF))
695 info->cfg.limit_low = (reg<<8) & 0xff00;
697 err = sh532u_i2c_rd8(info, info->i2c_addr_rom, addrInf1, ®);
698 if (!err && (reg != 0) && (reg != 0xFF))
699 info->cfg.limit_high = (reg<<8) & 0xff00;
703 * Inf2 and Mac2 are the calibration data for SEMCO AF lens.
704 * Inf2: Best focus (lens position) when object distance is 1.2M.
705 * Mac2: Best focus (lens position) when object distance is 10cm.
707 err = sh532u_i2c_rd8(info, info->i2c_addr_rom, addrMac2, ®);
708 if (!err && (reg != 0) && (reg != 0xFF))
709 info->cfg.pos_low = (reg << 8) & 0xff00;
711 err = sh532u_i2c_rd8(info, info->i2c_addr_rom, addrInf2, ®);
712 if (!err && (reg != 0) && (reg != 0xFF))
713 info->cfg.pos_high = (reg << 8) & 0xff00;
716 if (info->pdata->info) {
717 if (info->pdata->info->pos_low)
718 info->cfg.pos_low = info->pdata->info->pos_low;
719 if (info->pdata->info->pos_high)
720 info->cfg.pos_high = info->pdata->info->pos_high;
721 if (info->pdata->info->limit_low)
722 info->cfg.limit_low = info->pdata->info->limit_low;
723 if (info->pdata->info->limit_high)
724 info->cfg.limit_high = info->pdata->info->limit_high;
725 if (info->pdata->info->move_timeoutms)
726 info->cfg.move_timeoutms =
727 info->pdata->info->move_timeoutms;
728 if (info->pdata->info->focus_hyper_ratio)
729 info->cfg.focus_hyper_ratio =
730 info->pdata->info->focus_hyper_ratio;
731 if (info->pdata->info->focus_hyper_div)
732 info->cfg.focus_hyper_div =
733 info->pdata->info->focus_hyper_div;
736 * There is known to be many sh532u devices with no EPROM data.
737 * Using default data is known to reduce the sh532u performance since
738 * the defaults may no where be close to the correct values that
739 * should be used. However, we don't want to prevent the camera from
740 * starting due to the lack of the EPROM data.
741 * The following truth table shows the action to take at this point:
742 * DFLT = the use_defaults flag (used after multiple attempts)
743 * I2C = the I2C transactions to get the data.
744 * DATA = the needed data either from the EPROM or board file.
745 * DFLT I2C DATA Action
746 * --------------------------
747 * 0 FAIL FAIL Exit with -EIO
748 * 0 FAIL PASS Continue to calculations
749 * 0 PASS FAIL Use defaults
750 * 0 PASS PASS Continue to calculations
751 * 1 FAIL FAIL Use defaults
752 * 1 FAIL PASS Continue to calculations
753 * 1 PASS FAIL Use defaults
754 * 1 PASS PASS Continue to calculations
756 /* err = DATA where FAIL = 1 */
757 if (!info->cfg.pos_low || !info->cfg.pos_high ||
758 !info->cfg.limit_low || !info->cfg.limit_high)
763 if (!use_defaults && ret && err) {
764 dev_err(&info->i2c_client->dev, "%s ERR\n", __func__);
770 info->cfg.pos_low = SH532U_POS_LOW_DEFAULT;
771 info->cfg.pos_high = SH532U_POS_HIGH_DEFAULT;
772 info->cfg.limit_low = SH532U_POS_LOW_DEFAULT;
773 info->cfg.limit_high = SH532U_POS_HIGH_DEFAULT;
774 dev_err(&info->i2c_client->dev, "%s ERR: ERPOM data is void! "
775 "Focuser will use defaults that will cause "
776 "reduced functionality!\n", __func__);
778 if (info->cfg.pos_low < info->cfg.limit_low)
779 info->cfg.pos_low = info->cfg.limit_low;
780 if (info->cfg.pos_high > info->cfg.limit_high)
781 info->cfg.pos_high = info->cfg.limit_high;
782 dev_dbg(&info->i2c_client->dev, "%s pos_low=%d\n", __func__,
783 (int)info->cfg.pos_low);
784 dev_dbg(&info->i2c_client->dev, "%s pos_high=%d\n", __func__,
785 (int)info->cfg.pos_high);
786 dev_dbg(&info->i2c_client->dev, "%s limit_low=%d\n", __func__,
787 (int)info->cfg.limit_low);
788 dev_dbg(&info->i2c_client->dev, "%s limit_high=%d\n", __func__,
789 (int)info->cfg.limit_high);
791 * calculate relative and absolute positions
792 * Note that relative values, what upper SW uses, are the
793 * abstraction of HW (absolute) values.
794 * |<--limit_low limit_high-->|
795 * | |<-------------------_ACTUATOR_RANGE------------------->| |
796 * -focus_inf -focus_mac
797 * |<---RI--->| |<---RM--->|
798 * -abs_base -pos_low -pos_high -abs_top
800 * The pos_low and pos_high are fixed absolute positions and correspond
801 * to the relative focus_infinity and focus_macro, respectively. We'd
802 * like to have "wiggle" room (RI and RM) around these relative
803 * positions so the loop below finds the best fit for RI and RM without
804 * passing the absolute limits.
805 * We want our _ACTUATOR_RANGE to be infinity on the 0 end and macro
806 * on the max end. However, the focuser HW is opposite this.
807 * Therefore we use the rel(ative)_lo/hi variables in the calculation
808 * loop and assign them the focus_infinity and focus_macro values.
810 rel_lo = (info->cap.actuator_range - info->cap.focus_macro);
811 rel_hi = info->cap.focus_infinity;
812 info->abs_range = (u32)(info->cfg.pos_high - info->cfg.pos_low);
813 loop_limit = (rel_lo > rel_hi) ? rel_lo : rel_hi;
814 for (i = 0; i <= loop_limit; i++) {
815 rel_range = info->cap.actuator_range - (rel_lo + rel_hi);
816 step = info->abs_range / rel_range;
817 info->abs_base = info->cfg.pos_low - (step * rel_lo);
818 abs_top = info->cfg.pos_high + (step * rel_hi);
819 if (info->abs_base < info->cfg.limit_low) {
823 if (abs_top > info->cfg.limit_high) {
827 if (info->abs_base >= info->cfg.limit_low &&
828 abs_top <= info->cfg.limit_high)
831 info->cap.focus_hyper = info->abs_range;
832 info->abs_range = (u32)(abs_top - info->abs_base);
833 /* calculate absolute hyperfocus position */
834 info->cap.focus_hyper *= info->cfg.focus_hyper_ratio;
835 info->cap.focus_hyper /= info->cfg.focus_hyper_div;
836 abs_top = (s16)(info->cfg.pos_high - info->cap.focus_hyper);
837 /* update actual relative positions */
838 info->cap.focus_hyper = sh532u_abs2rel(info, abs_top);
839 info->cap.focus_infinity = sh532u_abs2rel(info, info->cfg.pos_high);
840 info->cap.focus_macro = sh532u_abs2rel(info, info->cfg.pos_low);
841 dev_dbg(&info->i2c_client->dev, "%s focus_macro=%u\n", __func__,
842 info->cap.focus_macro);
843 dev_dbg(&info->i2c_client->dev, "%s focus_infinity=%u\n", __func__,
844 info->cap.focus_infinity);
845 dev_dbg(&info->i2c_client->dev, "%s focus_hyper=%u\n", __func__,
846 info->cap.focus_hyper);
847 info->init_cal_flag = 1;
848 dev_dbg(&info->i2c_client->dev, "%s complete\n", __func__);
852 /* Write 1 byte data to the HVCA Drive IC by data type */
853 static int sh532u_hvca_wr1(struct sh532u_info *info,
854 u8 ep_type, u8 ep_data1, u8 ep_addr)
859 switch (ep_type & 0xF0) {
864 case INDIRECT_EEPROM:
865 err = sh532u_i2c_rd8(info,
872 err = sh532u_i2c_rd8(info, 0, ep_data1, &us_data);
876 err = sh532u_i2c_rd8(info, 0, ep_addr, &us_data);
881 err = sh532u_i2c_rd8(info, 0, ep_addr, &us_data);
889 err = sh532u_i2c_wr8(info, ep_addr, us_data);
893 /* Write 2 byte data to the HVCA Drive IC by data type */
894 static int sh532u_hvca_wr2(struct sh532u_info *info, u8 ep_type,
895 u8 ep_data1, u8 ep_data2, u8 ep_addr)
902 switch (ep_type & 0xF0) {
904 us_data = (((u16)ep_data1 << 8) & 0xFF00) |
905 ((u16)ep_data2 & 0x00FF);
908 case INDIRECT_EEPROM:
909 err = sh532u_i2c_rd8(info,
913 err |= sh532u_i2c_rd8(info,
917 us_data = (((u16)uc_data1 << 8) & 0xFF00) |
918 ((u16)uc_data2 & 0x00FF);
922 err = sh532u_i2c_rd8(info, 0, ep_data1, &uc_data1);
923 err |= sh532u_i2c_rd8(info, 0, ep_data2, &uc_data2);
924 us_data = (((u16)uc_data1 << 8) & 0xFF00) |
925 ((u16)uc_data2 & 0x00FF);
929 err = sh532u_i2c_rd16(info, ep_addr, &us_data);
930 us_data &= ((((u16)ep_data1 << 8) & 0xFF00) |
931 ((u16)ep_data2 & 0x00FF));
935 err = sh532u_i2c_rd16(info, ep_addr, &us_data);
936 us_data |= ((((u16)ep_data1 << 8) & 0xFF00) |
937 ((u16)ep_data2 & 0x00FF));
944 err = sh532u_i2c_wr16(info, ep_addr, us_data);
948 static int sh532u_dev_init(struct sh532u_info *info)
951 unsigned eeprom_data = 0;
959 err = sh532u_i2c_rd8(info, 0, SWTCH_211, &ep_data1);
961 err |= sh532u_i2c_rd8(info, 0, ANA1_211, &ep_data1);
962 ep_data2 |= ep_data1;
963 if (!err && ep_data2)
964 return 0; /* Already initialized */
966 info->sts = NVC_FOCUS_STS_INITIALIZING;
967 for (eeprom_reg = 0x30; eeprom_reg <= 0x013C; eeprom_reg += 4) {
968 if (eeprom_reg > 0xFF) {
969 /* use hardcoded data instead */
970 eeprom_data = sh532u_a2buf[(eeprom_reg & 0xFF) / 4];
972 err = (sh532u_i2c_rd32(info,
982 /* HVCA Address to write eeprom Data1,Data2 by the Data type */
983 ep_addr = (u8)(eeprom_data & 0x000000ff);
984 ep_type = (u8)((eeprom_data & 0x0000ff00) >> 8);
985 ep_data1 = (u8)((eeprom_data & 0x00ff0000) >> 16);
986 ep_data2 = (u8)((eeprom_data & 0xff000000) >> 24);
990 if (ep_addr == 0xDD) {
991 mdelay((unsigned int)((ep_data1 << 8) | ep_data2));
993 if ((ep_type & 0x0F) == DATA_1BYTE) {
994 err = sh532u_hvca_wr1(info,
999 err = sh532u_hvca_wr2(info,
1011 dev_err(&info->i2c_client->dev, "%s programming err=%d\n",
1013 err |= sh532u_calibration(info, false);
1014 info->sts = NVC_FOCUS_STS_LENS_SETTLED;
1018 static int sh532u_pos_abs_wr(struct sh532u_info *info, s16 tar_pos)
1025 sh532u_pm_dev_wr(info, NVC_PWR_ON);
1026 err = sh532u_dev_init(info);
1030 /* Read Current Position */
1031 err = sh532u_abs_pos_rd(info, &cur_pos);
1035 dev_dbg(&info->i2c_client->dev, "%s cur_pos=%d tar_pos=%d\n",
1036 __func__, (int)cur_pos, (int)tar_pos);
1037 info->sts = NVC_FOCUS_STS_WAIT_FOR_MOVE_END;
1038 /* Check move distance to Target Position */
1039 move_distance = abs((int)cur_pos - (int)tar_pos);
1040 /* if move distance is shorter than MS1Z12(=Step width) */
1041 if (move_distance <= STMV_SIZE) {
1042 err = sh532u_i2c_wr8(info, MSSET_211,
1043 (INI_MSSET_211 | 0x01));
1044 err |= sh532u_i2c_wr16(info, MS1Z22_211H, tar_pos);
1046 if (cur_pos < tar_pos)
1047 move_step = STMV_SIZE;
1049 move_step = -STMV_SIZE;
1050 /* Set StepMove Target Positon */
1051 err = sh532u_i2c_wr16(info, MS1Z12_211H, move_step);
1052 err |= sh532u_i2c_wr16(info, STMVENDH_211, tar_pos);
1053 /* Start StepMove */
1054 err |= sh532u_i2c_wr8(info, STMVEN_211,
1063 static int sh532u_move_wait(struct sh532u_info *info)
1074 err = sh532u_i2c_rd8(info, 0, STMVEN_211, &ucParMod);
1075 err |= sh532u_i2c_rd16(info, RZ_211H, &us_smv_fin);
1079 /* StepMove Error Handling, Unexpected Position */
1080 if ((us_smv_fin == 0x7FFF) || (us_smv_fin == 0x8001)) {
1081 /* Stop StepMove Operation */
1082 err = sh532u_i2c_wr8(info, STMVEN_211,
1089 /* Wait StepMove operation end */
1090 } while ((ucParMod & STMVEN_ON) && (moveTime < 50));
1093 if ((ucParMod & 0x08) == STMCHTG_ON) {
1098 err = sh532u_i2c_rd8(info, 0, MSSET_211, &tmp);
1102 } while ((tmp & CHTGST_ON) && (moveTime < 15));
1107 static int sh532u_move_pulse(struct sh532u_info *info, s16 position)
1111 err = sh532u_pos_abs_wr(info, position);
1112 err |= sh532u_move_wait(info);
1116 static int sh532u_hvca_pos_init(struct sh532u_info *info)
1122 limit_bottom = (((int)info->cfg.limit_low * 5) >> 3) & 0xFFC0;
1123 if (limit_bottom < info->cfg.limit_low)
1124 limit_bottom = info->cfg.limit_low;
1125 limit_top = (((int)info->cfg.limit_high * 5) >> 3) & 0xFFC0;
1126 if (limit_top > info->cfg.limit_high)
1127 limit_top = info->cfg.limit_high;
1128 err = sh532u_move_pulse(info, limit_bottom);
1129 err |= sh532u_move_pulse(info, limit_top);
1130 err |= sh532u_move_pulse(info, info->cfg.pos_high);
1134 static int sh532u_pos_rel_wr(struct sh532u_info *info, u32 position)
1138 if (position > info->cap.actuator_range) {
1139 dev_err(&info->i2c_client->dev, "%s invalid position %u\n",
1140 __func__, position);
1144 abs_pos = sh532u_rel2abs(info, position);
1145 info->pos_rel = position;
1146 info->pos_abs = abs_pos;
1147 info->pos_time_wr = jiffies;
1148 return sh532u_pos_abs_wr(info, abs_pos);
1152 static int sh532u_param_rd(struct sh532u_info *info, unsigned long arg)
1154 struct nvc_param params;
1155 const void *data_ptr;
1160 if (copy_from_user(¶ms,
1161 (const void __user *)arg,
1162 sizeof(struct nvc_param))) {
1163 dev_err(&info->i2c_client->dev, "%s %d copy_from_user err\n",
1164 __func__, __LINE__);
1168 if (info->s_mode == NVC_SYNC_SLAVE)
1169 info = info->s_info;
1170 switch (params.param) {
1171 case NVC_PARAM_LOCUS:
1172 sh532u_pm_dev_wr(info, NVC_PWR_COMM);
1173 err = sh532u_rel_pos_rd(info, &position);
1174 if (err && !(info->pdata->cfg & NVC_CFG_NOERR))
1177 data_ptr = &position;
1178 data_size = sizeof(position);
1179 sh532u_pm_dev_wr(info, NVC_PWR_STDBY);
1180 dev_dbg(&info->i2c_client->dev, "%s LOCUS: %d\n",
1181 __func__, position);
1184 case NVC_PARAM_FOCAL_LEN:
1185 data_ptr = &info->nvc.focal_length;
1186 data_size = sizeof(info->nvc.focal_length);
1187 dev_dbg(&info->i2c_client->dev, "%s FOCAL_LEN: %x\n",
1188 __func__, info->nvc.focal_length);
1191 case NVC_PARAM_MAX_APERTURE:
1192 data_ptr = &info->nvc.max_aperature;
1193 data_size = sizeof(info->nvc.max_aperature);
1194 dev_dbg(&info->i2c_client->dev, "%s MAX_APERTURE: %x\n",
1195 __func__, info->nvc.max_aperature);
1198 case NVC_PARAM_FNUMBER:
1199 data_ptr = &info->nvc.fnumber;
1200 data_size = sizeof(info->nvc.fnumber);
1201 dev_dbg(&info->i2c_client->dev, "%s FNUMBER: %x\n",
1202 __func__, info->nvc.fnumber);
1205 case NVC_PARAM_CAPS:
1206 sh532u_pm_dev_wr(info, NVC_PWR_COMM);
1207 err = sh532u_calibration(info, true);
1208 sh532u_pm_dev_wr(info, NVC_PWR_STDBY);
1212 data_ptr = &info->cap;
1213 /* there are different sizes depending on the version */
1214 /* send back just what's requested or our max size */
1215 if (params.sizeofvalue < sizeof(info->cap))
1216 data_size = params.sizeofvalue;
1218 data_size = sizeof(info->cap);
1219 dev_dbg(&info->i2c_client->dev, "%s CAPS\n",
1224 data_ptr = &info->sts;
1225 data_size = sizeof(info->sts);
1226 dev_dbg(&info->i2c_client->dev, "%s STS: %d\n",
1227 __func__, info->sts);
1230 case NVC_PARAM_STEREO:
1231 data_ptr = &info->s_mode;
1232 data_size = sizeof(info->s_mode);
1233 dev_dbg(&info->i2c_client->dev, "%s STEREO: %d\n",
1234 __func__, info->s_mode);
1238 dev_err(&info->i2c_client->dev,
1239 "%s unsupported parameter: %d\n",
1240 __func__, params.param);
1244 if (params.sizeofvalue < data_size) {
1245 dev_err(&info->i2c_client->dev, "%s %d data size err\n",
1246 __func__, __LINE__);
1250 if (copy_to_user((void __user *)params.p_value,
1253 dev_err(&info->i2c_client->dev, "%s %d copy_to_user err\n",
1254 __func__, __LINE__);
1261 static int sh532u_param_wr_s(struct sh532u_info *info,
1262 struct nvc_param *params,
1267 switch (params->param) {
1268 case NVC_PARAM_LOCUS:
1269 dev_dbg(&info->i2c_client->dev, "%s LOCUS: %u\n",
1271 err = sh532u_pos_rel_wr(info, u32_val);
1274 case NVC_PARAM_RESET:
1275 err = sh532u_pm_wr(info, NVC_PWR_OFF);
1276 err |= sh532u_pm_wr(info, NVC_PWR_ON);
1277 err |= sh532u_pm_wr(info, info->pwr_api);
1278 dev_dbg(&info->i2c_client->dev, "%s RESET: %d\n",
1282 case NVC_PARAM_SELF_TEST:
1283 err = sh532u_hvca_pos_init(info);
1284 dev_dbg(&info->i2c_client->dev, "%s SELF_TEST: %d\n",
1289 dev_err(&info->i2c_client->dev,
1290 "%s unsupported parameter: %d\n",
1291 __func__, params->param);
1296 static int sh532u_param_wr(struct sh532u_info *info, unsigned long arg)
1298 struct nvc_param params;
1303 if (copy_from_user(¶ms,
1304 (const void __user *)arg,
1305 sizeof(struct nvc_param))) {
1306 dev_err(&info->i2c_client->dev, "%s %d copy_from_user err\n",
1307 __func__, __LINE__);
1311 if (copy_from_user(&u32_val, (const void __user *)params.p_value,
1313 dev_err(&info->i2c_client->dev, "%s %d copy_from_user err\n",
1314 __func__, __LINE__);
1318 /* parameters independent of sync mode */
1319 switch (params.param) {
1320 case NVC_PARAM_STEREO:
1321 dev_dbg(&info->i2c_client->dev, "%s STEREO: %u\n",
1324 if (val == info->s_mode)
1330 if (info->s_info != NULL) {
1331 info->s_info->s_mode = val;
1332 sh532u_pm_wr(info->s_info, NVC_PWR_OFF);
1336 case NVC_SYNC_MASTER:
1338 if (info->s_info != NULL)
1339 info->s_info->s_mode = val;
1342 case NVC_SYNC_SLAVE:
1343 if (info->s_info != NULL) {
1344 /* default slave lens position */
1345 err = sh532u_pos_rel_wr(info->s_info,
1346 info->s_info->cap.focus_infinity);
1349 info->s_info->s_mode = val;
1351 if (info->s_mode != NVC_SYNC_STEREO)
1352 sh532u_pm_wr(info->s_info,
1361 case NVC_SYNC_STEREO:
1362 if (info->s_info != NULL) {
1364 info->s_info->pwr_api = info->pwr_api;
1365 /* move slave lens to master position */
1366 err = sh532u_pos_rel_wr(info->s_info,
1370 info->s_info->s_mode = val;
1372 if (info->s_mode != NVC_SYNC_SLAVE)
1373 sh532u_pm_wr(info->s_info,
1385 if (info->pdata->cfg & NVC_CFG_NOERR)
1391 /* parameters dependent on sync mode */
1392 switch (info->s_mode) {
1394 case NVC_SYNC_MASTER:
1395 return sh532u_param_wr_s(info, ¶ms, u32_val);
1397 case NVC_SYNC_SLAVE:
1398 return sh532u_param_wr_s(info->s_info,
1402 case NVC_SYNC_STEREO:
1403 err = sh532u_param_wr_s(info, ¶ms, u32_val);
1404 if (!(info->pdata->cfg & NVC_CFG_SYNC_I2C_MUX))
1405 err |= sh532u_param_wr_s(info->s_info,
1411 dev_err(&info->i2c_client->dev, "%s %d internal err\n",
1412 __func__, __LINE__);
1418 static long sh532u_ioctl(struct file *file,
1422 struct sh532u_info *info = file->private_data;
1426 case NVC_IOCTL_PARAM_WR:
1427 return sh532u_param_wr(info, arg);
1429 case NVC_IOCTL_PARAM_RD:
1430 return sh532u_param_rd(info, arg);
1432 case NVC_IOCTL_PWR_WR:
1433 /* This is a Guaranteed Level of Service (GLOS) call */
1435 dev_dbg(&info->i2c_client->dev, "%s PWR: %d\n",
1437 return sh532u_pm_api_wr(info, pwr);
1439 case NVC_IOCTL_PWR_RD:
1440 if (info->s_mode == NVC_SYNC_SLAVE)
1441 pwr = info->s_info->pwr_api / 2;
1443 pwr = info->pwr_api / 2;
1444 dev_dbg(&info->i2c_client->dev, "%s PWR_RD: %d\n",
1446 if (copy_to_user((void __user *)arg, (const void *)&pwr,
1448 dev_err(&info->i2c_client->dev,
1449 "%s copy_to_user err line %d\n",
1450 __func__, __LINE__);
1457 dev_err(&info->i2c_client->dev, "%s unsupported ioctl: %x\n",
1463 static int sh532u_sync_en(int dev1, int dev2)
1465 struct sh532u_info *sync1 = NULL;
1466 struct sh532u_info *sync2 = NULL;
1467 struct sh532u_info *pos = NULL;
1470 list_for_each_entry_rcu(pos, &sh532u_info_list, list) {
1471 if (pos->pdata->num == dev1) {
1477 list_for_each_entry_rcu(pos, &sh532u_info_list, list) {
1478 if (pos->pdata->num == dev2) {
1485 sync1->s_info = NULL;
1487 sync2->s_info = NULL;
1489 return 0; /* no err if default instance 0's used */
1492 return -EINVAL; /* err if sync instance is itself */
1494 if ((sync1 != NULL) && (sync2 != NULL)) {
1495 sync1->s_info = sync2;
1496 sync2->s_info = sync1;
1501 static int sh532u_sync_dis(struct sh532u_info *info)
1503 if (info->s_info != NULL) {
1504 info->s_info->s_mode = 0;
1505 info->s_info->s_info = NULL;
1507 info->s_info = NULL;
1514 static int sh532u_open(struct inode *inode, struct file *file)
1516 struct sh532u_info *info = NULL;
1517 struct sh532u_info *pos = NULL;
1521 list_for_each_entry_rcu(pos, &sh532u_info_list, list) {
1522 if (pos->miscdev.minor == iminor(inode)) {
1531 err = sh532u_sync_en(info->pdata->num, info->pdata->sync);
1533 dev_err(&info->i2c_client->dev,
1534 "%s err: invalid num (%u) and sync (%u) instance\n",
1535 __func__, info->pdata->num, info->pdata->sync);
1536 if (atomic_xchg(&info->in_use, 1))
1539 if (info->s_info != NULL) {
1540 if (atomic_xchg(&info->s_info->in_use, 1))
1544 file->private_data = info;
1545 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
1546 sh532u_pos_rel_wr(info, info->cap.focus_infinity);
1550 int sh532u_release(struct inode *inode, struct file *file)
1552 struct sh532u_info *info = file->private_data;
1554 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
1555 sh532u_pm_wr_s(info, NVC_PWR_OFF);
1556 file->private_data = NULL;
1557 WARN_ON(!atomic_xchg(&info->in_use, 0));
1558 if (info->s_info != NULL)
1559 WARN_ON(!atomic_xchg(&info->s_info->in_use, 0));
1560 sh532u_sync_dis(info);
1564 static const struct file_operations sh532u_fileops = {
1565 .owner = THIS_MODULE,
1566 .open = sh532u_open,
1567 .unlocked_ioctl = sh532u_ioctl,
1568 .release = sh532u_release,
1571 static void sh532u_del(struct sh532u_info *info)
1573 sh532u_pm_exit(info);
1574 sh532u_sync_dis(info);
1575 spin_lock(&sh532u_spinlock);
1576 list_del_rcu(&info->list);
1577 spin_unlock(&sh532u_spinlock);
1581 static int sh532u_remove(struct i2c_client *client)
1583 struct sh532u_info *info = i2c_get_clientdata(client);
1585 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
1586 misc_deregister(&info->miscdev);
1591 static int sh532u_probe(
1592 struct i2c_client *client,
1593 const struct i2c_device_id *id)
1595 struct sh532u_info *info = NULL;
1599 dev_dbg(&client->dev, "%s\n", __func__);
1600 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
1602 dev_err(&client->dev, "%s: kzalloc error\n", __func__);
1606 info->i2c_client = client;
1607 if (client->dev.platform_data) {
1608 info->pdata = client->dev.platform_data;
1610 info->pdata = &sh532u_default_pdata;
1611 dev_dbg(&client->dev,
1612 "%s No platform data. Using defaults.\n",
1615 i2c_set_clientdata(client, info);
1616 INIT_LIST_HEAD(&info->list);
1617 spin_lock(&sh532u_spinlock);
1618 list_add_rcu(&info->list, &sh532u_info_list);
1619 spin_unlock(&sh532u_spinlock);
1620 sh532u_pm_init(info);
1621 sh532u_pm_dev_wr(info, NVC_PWR_COMM);
1622 err = sh532u_dev_id(info);
1624 dev_err(&client->dev, "%s device not found\n", __func__);
1625 sh532u_pm_wr(info, NVC_PWR_OFF);
1626 if (info->pdata->cfg & NVC_CFG_NODEV) {
1631 dev_dbg(&client->dev, "%s device found\n", __func__);
1632 sh532u_calibration(info, false);
1633 if (info->pdata->cfg & NVC_CFG_BOOT_INIT) {
1634 /* initial move causes full initialization */
1635 sh532u_pos_rel_wr(info, info->cap.focus_infinity);
1637 sh532u_pm_wr(info, NVC_PWR_OFF);
1641 if (info->pdata->dev_name != 0)
1642 strcpy(dname, info->pdata->dev_name);
1644 strcpy(dname, "sh532u");
1645 if (info->pdata->num)
1646 snprintf(dname, sizeof(dname), "%s.%u",
1647 dname, info->pdata->num);
1648 info->miscdev.name = dname;
1649 info->miscdev.fops = &sh532u_fileops;
1650 info->miscdev.minor = MISC_DYNAMIC_MINOR;
1651 if (misc_register(&info->miscdev)) {
1652 dev_err(&client->dev, "%s unable to register misc device %s\n",
1661 static const struct i2c_device_id sh532u_id[] = {
1666 MODULE_DEVICE_TABLE(i2c, sh532u_id);
1668 static struct i2c_driver sh532u_i2c_driver = {
1671 .owner = THIS_MODULE,
1673 .id_table = sh532u_id,
1674 .probe = sh532u_probe,
1675 .remove = sh532u_remove,
1678 static int __init sh532u_init(void)
1680 return i2c_add_driver(&sh532u_i2c_driver);
1683 static void __exit sh532u_exit(void)
1685 i2c_del_driver(&sh532u_i2c_driver);
1688 module_init(sh532u_init);
1689 module_exit(sh532u_exit);