1 /* Sensor support for Samsung Tuna Board.
3 * Copyright (C) 2011 Google, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/kernel.h>
16 #include <linux/gpio.h>
17 #include <linux/i2c.h>
18 #include <linux/mpu.h>
19 #include <linux/gp2a.h>
20 #include <linux/i2c/twl6030-madc.h>
23 #include "board-tuna.h"
25 #define GPIO_GYRO_INT 45
26 #define GPIO_ACC_INT 122
27 #define GPIO_MAG_INT 176
29 #define GPIO_PS_VOUT 21
30 #define GPIO_MSENSE_IRQ 157
32 #define GP2A_LIGHT_ADC_CHANNEL 4
34 static int gp2a_light_adc_value(void)
36 return twl6030_get_madc_conversion(GP2A_LIGHT_ADC_CHANNEL
);
39 static void gp2a_power(bool on
)
41 /* this controls the power supply rail to the gp2a IC */
42 gpio_set_value(GPIO_PS_ON
, on
);
45 static void gp2a_gpio_init(void)
47 int ret
= gpio_request(GPIO_PS_ON
, "gp2a_power_supply_on");
49 pr_err("%s Failed to request gpio gp2a power supply\n",
53 /* set power pin to output, initially powered off*/
54 ret
= gpio_direction_output(GPIO_PS_ON
, 0);
56 pr_err("%s Failed in gpio_direction_output, value 0 with error %d\n",
61 static s8 orientation_back
[] = {
67 static s8 orientation_back_right_90
[] = {
73 static s8 orientation_back_left_90
[] = {
79 static s8 orientation_back_180
[] = {
86 * A correction matrix for YAS530
87 * which takes care of soft iron effect in TORO
89 static s32 compass_correction_matrix_toro
[] = {
95 static void rotcpy(s8 dst
[3 * 3], const s8 src
[3 * 3])
97 memcpy(dst
, src
, 3 * 3);
100 static struct mpu_platform_data mpu_data
= {
102 .orientation
= { 1, 0, 0,
107 .irq
= OMAP_GPIO_IRQ(GPIO_ACC_INT
),
109 .bus
= EXT_SLAVE_BUS_SECONDARY
,
111 .orientation
= { 1, 0, 0,
117 .irq
= OMAP_GPIO_IRQ(GPIO_MAG_INT
),
119 .bus
= EXT_SLAVE_BUS_PRIMARY
,
121 .orientation
= { 1, 0, 0,
127 static struct gp2a_platform_data gp2a_pdata
= {
129 .p_out
= GPIO_PS_VOUT
,
130 .light_adc_value
= gp2a_light_adc_value
,
133 static struct i2c_board_info __initdata tuna_sensors_i2c4_boardinfo
[] = {
135 I2C_BOARD_INFO("mpu3050", 0x68),
136 .irq
= OMAP_GPIO_IRQ(GPIO_GYRO_INT
),
137 .platform_data
= &mpu_data
,
140 I2C_BOARD_INFO("bma250", 0x18),
141 .irq
= OMAP_GPIO_IRQ(GPIO_ACC_INT
),
142 .platform_data
= &mpu_data
.accel
,
145 I2C_BOARD_INFO("yas530", 0x2e),
146 .irq
= OMAP_GPIO_IRQ(GPIO_MAG_INT
),
147 .platform_data
= &mpu_data
.compass
,
150 I2C_BOARD_INFO("gp2a", 0x44),
151 .platform_data
= &gp2a_pdata
,
154 I2C_BOARD_INFO("bmp180", 0x77),
158 static void omap4_tuna_fixup_orientations_maguro(int revision
)
161 rotcpy(mpu_data
.orientation
, orientation_back_right_90
);
162 rotcpy(mpu_data
.accel
.orientation
, orientation_back_left_90
);
163 } else if (revision
>= 2) {
164 rotcpy(mpu_data
.orientation
, orientation_back_right_90
);
165 rotcpy(mpu_data
.accel
.orientation
, orientation_back_180
);
166 } else if (revision
== 1) {
167 rotcpy(mpu_data
.accel
.orientation
, orientation_back_left_90
);
171 static void omap4_tuna_fixup_orientations_toro(int revision
)
173 pr_info("HW %d", revision
);
174 if (revision
>= 14) {
175 rotcpy(mpu_data
.orientation
, orientation_back_left_90
);
176 rotcpy(mpu_data
.accel
.orientation
, orientation_back
);
177 rotcpy(mpu_data
.compass
.orientation
, orientation_back
);
178 } else if (revision
>= 2) {
179 rotcpy(mpu_data
.orientation
, orientation_back_left_90
);
180 rotcpy(mpu_data
.accel
.orientation
, orientation_back
);
181 rotcpy(mpu_data
.compass
.orientation
, orientation_back_180
);
182 } else if (revision
>= 1) {
183 rotcpy(mpu_data
.orientation
, orientation_back_left_90
);
184 rotcpy(mpu_data
.accel
.orientation
, orientation_back_180
);
185 rotcpy(mpu_data
.compass
.orientation
, orientation_back_left_90
);
189 void __init
omap4_tuna_sensors_init(void)
191 omap_mux_init_gpio(GPIO_GYRO_INT
, OMAP_PIN_INPUT
);
192 omap_mux_init_gpio(GPIO_ACC_INT
, OMAP_PIN_INPUT
);
193 omap_mux_init_gpio(GPIO_MAG_INT
, OMAP_PIN_INPUT
);
194 omap_mux_init_gpio(GPIO_PS_ON
, OMAP_PIN_OUTPUT
);
195 omap_mux_init_gpio(GPIO_PS_VOUT
, OMAP_WAKEUP_EN
| OMAP_PIN_INPUT
);
197 gpio_request(GPIO_GYRO_INT
, "GYRO_INT");
198 gpio_direction_input(GPIO_GYRO_INT
);
199 gpio_request(GPIO_ACC_INT
, "ACC_INT");
200 gpio_direction_input(GPIO_ACC_INT
);
201 gpio_request(GPIO_MAG_INT
, "MAG_INT");
202 gpio_direction_input(GPIO_MAG_INT
);
203 gpio_request(GPIO_MSENSE_IRQ
, "MSENSE_IRQ");
204 gpio_direction_output(GPIO_MSENSE_IRQ
, 1);
208 if (omap4_tuna_get_type() == TUNA_TYPE_MAGURO
) {
209 omap4_tuna_fixup_orientations_maguro(omap4_tuna_get_revision());
210 } else if (omap4_tuna_get_type() == TUNA_TYPE_TORO
) {
211 omap4_tuna_fixup_orientations_toro(omap4_tuna_get_revision());
212 mpu_data
.compass
.private_data
= compass_correction_matrix_toro
;
215 i2c_register_board_info(4, tuna_sensors_i2c4_boardinfo
,
216 ARRAY_SIZE(tuna_sensors_i2c4_boardinfo
));