aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorEnric Balletbo i Serra <enric.balletbo@collabora.com>2016-08-01 05:54:35 -0400
committerJonathan Cameron <jic23@kernel.org>2016-10-25 13:20:05 -0400
commit974e6f02e27e1b46c6c5e600e70ced25079f73eb (patch)
treefde95884c3df855863a55e44c1c2eff6c2a3d9ec /include/linux
parent1001354ca34179f3db924eb66672442a173147dc (diff)
iio: cros_ec_sensors_core: Add common functions for the ChromeOS EC Sensor Hub.
Add the core functions to be able to support the sensors attached behind the ChromeOS Embedded Controller and used by other IIO cros-ec sensor drivers. The cros_ec_sensor_core driver matches with current driver in ChromeOS 4.4 tree, so it includes all the fixes at the moment. The support for this driver was made by Gwendal Grignou. The original patch and all the fixes has been squashed and rebased on top of mainline. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Signed-off-by: Guenter Roeck <groeck@chromium.org> [eballetbo: split, squash and rebase on top of mainline the patches found in ChromeOS tree] Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/mfd/cros_ec.h9
-rw-r--r--include/linux/mfd/cros_ec_commands.h99
2 files changed, 103 insertions, 5 deletions
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index 76f7ef4d3a0d..1f85b7aff097 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -148,6 +148,15 @@ struct cros_ec_device {
148 int event_size; 148 int event_size;
149}; 149};
150 150
151/**
152 * struct cros_ec_sensor_platform - ChromeOS EC sensor platform information
153 *
154 * @sensor_num: Id of the sensor, as reported by the EC.
155 */
156struct cros_ec_sensor_platform {
157 u8 sensor_num;
158};
159
151/* struct cros_ec_platform - ChromeOS EC platform information 160/* struct cros_ec_platform - ChromeOS EC platform information
152 * 161 *
153 * @ec_name: name of EC device (e.g. 'cros-ec', 'cros-pd', ...) 162 * @ec_name: name of EC device (e.g. 'cros-ec', 'cros-pd', ...)
diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h
index 76728ff37d01..8826e0f64b0e 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -1315,6 +1315,24 @@ enum motionsense_command {
1315 */ 1315 */
1316 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, 1316 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1317 1317
1318 /*
1319 * Returns a single sensor data.
1320 */
1321 MOTIONSENSE_CMD_DATA = 6,
1322
1323 /*
1324 * Perform low level calibration.. On sensors that support it, ask to
1325 * do offset calibration.
1326 */
1327 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1328
1329 /*
1330 * Sensor Offset command is a setter/getter command for the offset used
1331 * for calibration. The offsets can be calculated by the host, or via
1332 * PERFORM_CALIB command.
1333 */
1334 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1335
1318 /* Number of motionsense sub-commands. */ 1336 /* Number of motionsense sub-commands. */
1319 MOTIONSENSE_NUM_CMDS 1337 MOTIONSENSE_NUM_CMDS
1320}; 1338};
@@ -1335,12 +1353,18 @@ enum motionsensor_id {
1335enum motionsensor_type { 1353enum motionsensor_type {
1336 MOTIONSENSE_TYPE_ACCEL = 0, 1354 MOTIONSENSE_TYPE_ACCEL = 0,
1337 MOTIONSENSE_TYPE_GYRO = 1, 1355 MOTIONSENSE_TYPE_GYRO = 1,
1356 MOTIONSENSE_TYPE_MAG = 2,
1357 MOTIONSENSE_TYPE_PROX = 3,
1358 MOTIONSENSE_TYPE_LIGHT = 4,
1359 MOTIONSENSE_TYPE_ACTIVITY = 5,
1360 MOTIONSENSE_TYPE_MAX
1338}; 1361};
1339 1362
1340/* List of motion sensor locations. */ 1363/* List of motion sensor locations. */
1341enum motionsensor_location { 1364enum motionsensor_location {
1342 MOTIONSENSE_LOC_BASE = 0, 1365 MOTIONSENSE_LOC_BASE = 0,
1343 MOTIONSENSE_LOC_LID = 1, 1366 MOTIONSENSE_LOC_LID = 1,
1367 MOTIONSENSE_LOC_MAX,
1344}; 1368};
1345 1369
1346/* List of motion sensor chips. */ 1370/* List of motion sensor chips. */
@@ -1361,6 +1385,31 @@ enum motionsensor_chip {
1361 */ 1385 */
1362#define EC_MOTION_SENSE_NO_VALUE -1 1386#define EC_MOTION_SENSE_NO_VALUE -1
1363 1387
1388#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1389
1390/* Set Calibration information */
1391#define MOTION_SENSE_SET_OFFSET 1
1392
1393struct ec_response_motion_sensor_data {
1394 /* Flags for each sensor. */
1395 uint8_t flags;
1396 /* Sensor number the data comes from */
1397 uint8_t sensor_num;
1398 /* Each sensor is up to 3-axis. */
1399 union {
1400 int16_t data[3];
1401 struct {
1402 uint16_t rsvd;
1403 uint32_t timestamp;
1404 } __packed;
1405 struct {
1406 uint8_t activity; /* motionsensor_activity */
1407 uint8_t state;
1408 int16_t add_info[2];
1409 };
1410 };
1411} __packed;
1412
1364struct ec_params_motion_sense { 1413struct ec_params_motion_sense {
1365 uint8_t cmd; 1414 uint8_t cmd;
1366 union { 1415 union {
@@ -1378,9 +1427,37 @@ struct ec_params_motion_sense {
1378 int16_t data; 1427 int16_t data;
1379 } ec_rate, kb_wake_angle; 1428 } ec_rate, kb_wake_angle;
1380 1429
1430 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1431 struct {
1432 uint8_t sensor_num;
1433
1434 /*
1435 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1436 * the calibration information in the EC.
1437 * If unset, just retrieve calibration information.
1438 */
1439 uint16_t flags;
1440
1441 /*
1442 * Temperature at calibration, in units of 0.01 C
1443 * 0x8000: invalid / unknown.
1444 * 0x0: 0C
1445 * 0x7fff: +327.67C
1446 */
1447 int16_t temp;
1448
1449 /*
1450 * Offset for calibration.
1451 * Unit:
1452 * Accelerometer: 1/1024 g
1453 * Gyro: 1/1024 deg/s
1454 * Compass: 1/16 uT
1455 */
1456 int16_t offset[3];
1457 } __packed sensor_offset;
1458
1381 /* Used for MOTIONSENSE_CMD_INFO. */ 1459 /* Used for MOTIONSENSE_CMD_INFO. */
1382 struct { 1460 struct {
1383 /* Should be element of enum motionsensor_id. */
1384 uint8_t sensor_num; 1461 uint8_t sensor_num;
1385 } info; 1462 } info;
1386 1463
@@ -1410,11 +1487,14 @@ struct ec_response_motion_sense {
1410 /* Flags representing the motion sensor module. */ 1487 /* Flags representing the motion sensor module. */
1411 uint8_t module_flags; 1488 uint8_t module_flags;
1412 1489
1413 /* Flags for each sensor in enum motionsensor_id. */ 1490 /* Number of sensors managed directly by the EC. */
1414 uint8_t sensor_flags[EC_MOTION_SENSOR_COUNT]; 1491 uint8_t sensor_count;
1415 1492
1416 /* Array of all sensor data. Each sensor is 3-axis. */ 1493 /*
1417 int16_t data[3*EC_MOTION_SENSOR_COUNT]; 1494 * Sensor data is truncated if response_max is too small
1495 * for holding all the data.
1496 */
1497 struct ec_response_motion_sensor_data sensor[0];
1418 } dump; 1498 } dump;
1419 1499
1420 /* Used for MOTIONSENSE_CMD_INFO. */ 1500 /* Used for MOTIONSENSE_CMD_INFO. */
@@ -1429,6 +1509,9 @@ struct ec_response_motion_sense {
1429 uint8_t chip; 1509 uint8_t chip;
1430 } info; 1510 } info;
1431 1511
1512 /* Used for MOTIONSENSE_CMD_DATA */
1513 struct ec_response_motion_sensor_data data;
1514
1432 /* 1515 /*
1433 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, 1516 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1434 * MOTIONSENSE_CMD_SENSOR_RANGE, and 1517 * MOTIONSENSE_CMD_SENSOR_RANGE, and
@@ -1438,6 +1521,12 @@ struct ec_response_motion_sense {
1438 /* Current value of the parameter queried. */ 1521 /* Current value of the parameter queried. */
1439 int32_t ret; 1522 int32_t ret;
1440 } ec_rate, sensor_odr, sensor_range, kb_wake_angle; 1523 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1524
1525 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1526 struct {
1527 int16_t temp;
1528 int16_t offset[3];
1529 } sensor_offset, perform_calib;
1441 }; 1530 };
1442} __packed; 1531} __packed;
1443 1532