1 /* 2 * Driver for the s5k83a sensor 3 * 4 * Copyright (C) 2008 Erik Andrén 5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project. 6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br> 7 * 8 * Portions of code to USB interface and ALi driver software, 9 * Copyright (c) 2006 Willem Duinker 10 * v4l2 interface modeled after the V4L2 driver 11 * for SN9C10x PC Camera Controllers 12 * 13 * This program is free software; you can redistribute it and/or 14 * modify it under the terms of the GNU General Public License as 15 * published by the Free Software Foundation, version 2. 16 * 17 */ 18 19 #ifndef M5602_S5K83A_H_ 20 #define M5602_S5K83A_H_ 21 22 #include "m5602_sensor.h" 23 24 #define S5K83A_FLIP 0x01 25 #define S5K83A_HFLIP_TUNE 0x03 26 #define S5K83A_VFLIP_TUNE 0x05 27 #define S5K83A_BRIGHTNESS 0x0a 28 #define S5K83A_EXPOSURE 0x18 29 #define S5K83A_GAIN 0x1b 30 #define S5K83A_PAGE_MAP 0xec 31 32 #define S5K83A_DEFAULT_GAIN 0x71 33 #define S5K83A_DEFAULT_BRIGHTNESS 0x7e 34 #define S5K83A_DEFAULT_EXPOSURE 0x00 35 #define S5K83A_MAXIMUM_EXPOSURE 0x3c 36 #define S5K83A_FLIP_MASK 0x10 37 #define S5K83A_GPIO_LED_MASK 0x10 38 #define S5K83A_GPIO_ROTATION_MASK 0x40 39 40 /*****************************************************************************/ 41 42 /* Kernel module parameters */ 43 extern int force_sensor; 44 extern bool dump_sensor; 45 46 int s5k83a_probe(struct sd *sd); 47 int s5k83a_init(struct sd *sd); 48 int s5k83a_init_controls(struct sd *sd); 49 int s5k83a_start(struct sd *sd); 50 int s5k83a_stop(struct sd *sd); 51 void s5k83a_disconnect(struct sd *sd); 52 53 static const struct m5602_sensor s5k83a = { 54 .name = "S5K83A", 55 .probe = s5k83a_probe, 56 .init = s5k83a_init, 57 .init_controls = s5k83a_init_controls, 58 .start = s5k83a_start, 59 .stop = s5k83a_stop, 60 .disconnect = s5k83a_disconnect, 61 .i2c_slave_id = 0x5a, 62 .i2c_regW = 2, 63 }; 64 65 static const unsigned char preinit_s5k83a[][4] = { 66 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00}, 67 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00}, 68 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00}, 69 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00}, 70 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00}, 71 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00}, 72 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00}, 73 74 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00}, 75 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00}, 76 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00}, 77 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00}, 78 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00}, 79 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00}, 80 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00}, 81 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00}, 82 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00}, 83 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00}, 84 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00}, 85 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00}, 86 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00}, 87 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00}, 88 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00}, 89 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00}, 90 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00}, 91 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00}, 92 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00}, 93 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00}, 94 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00}, 95 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00}, 96 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00}, 97 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00}, 98 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00}, 99 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00}, 100 }; 101 102 /* This could probably be considerably shortened. 103 I don't have the hardware to experiment with it, patches welcome 104 */ 105 static const unsigned char init_s5k83a[][4] = { 106 /* The following sequence is useless after a clean boot 107 but is necessary after resume from suspend */ 108 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00}, 109 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00}, 110 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00}, 111 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00}, 112 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00}, 113 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00}, 114 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00}, 115 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00}, 116 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00}, 117 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00}, 118 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00}, 119 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00}, 120 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00}, 121 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00}, 122 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00}, 123 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00}, 124 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00}, 125 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00}, 126 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00}, 127 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00}, 128 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00}, 129 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00}, 130 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00}, 131 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00}, 132 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00}, 133 134 {SENSOR, S5K83A_PAGE_MAP, 0x04, 0x00}, 135 {SENSOR, 0xaf, 0x01, 0x00}, 136 {SENSOR, S5K83A_PAGE_MAP, 0x00, 0x00}, 137 {SENSOR, 0x7b, 0xff, 0x00}, 138 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00}, 139 {SENSOR, 0x01, 0x50, 0x00}, 140 {SENSOR, 0x12, 0x20, 0x00}, 141 {SENSOR, 0x17, 0x40, 0x00}, 142 {SENSOR, 0x1c, 0x00, 0x00}, 143 {SENSOR, 0x02, 0x70, 0x00}, 144 {SENSOR, 0x03, 0x0b, 0x00}, 145 {SENSOR, 0x04, 0xf0, 0x00}, 146 {SENSOR, 0x05, 0x0b, 0x00}, 147 {SENSOR, 0x06, 0x71, 0x00}, 148 {SENSOR, 0x07, 0xe8, 0x00}, /* 488 */ 149 {SENSOR, 0x08, 0x02, 0x00}, 150 {SENSOR, 0x09, 0x88, 0x00}, /* 648 */ 151 {SENSOR, 0x14, 0x00, 0x00}, 152 {SENSOR, 0x15, 0x20, 0x00}, /* 32 */ 153 {SENSOR, 0x19, 0x00, 0x00}, 154 {SENSOR, 0x1a, 0x98, 0x00}, /* 152 */ 155 {SENSOR, 0x0f, 0x02, 0x00}, 156 {SENSOR, 0x10, 0xe5, 0x00}, /* 741 */ 157 /* normal colors 158 (this is value after boot, but after tries can be different) */ 159 {SENSOR, 0x00, 0x06, 0x00}, 160 }; 161 162 static const unsigned char start_s5k83a[][4] = { 163 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00}, 164 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00}, 165 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00}, 166 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00}, 167 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00}, 168 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00}, 169 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00}, 170 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00}, 171 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00}, 172 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00}, 173 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00}, 174 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00}, 175 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00}, /* 484 */ 176 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00}, 177 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00}, 178 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00}, 179 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00}, 180 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00}, 181 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00}, 182 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00}, 183 {BRIDGE, M5602_XB_HSYNC_PARA, 0x7f, 0x00}, /* 639 */ 184 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00}, 185 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00}, 186 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00}, 187 }; 188 #endif 189