Source
x
/*
* CM3232 Ambient Light Sensor
*
* Copyright (C) 2014-2015 Capella Microsystems Inc.
* Author: Kevin Tsai <ktsai@capellamicro.com>
*
* 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.
*
* IIO driver for CM3232 (7-bit I2C slave address 0x10).
*/
/* Registers Address */
static const struct {
int val;
int val2;
u8 it;
} cm3232_als_it_scales[] = {
{0, 100000, 0}, /* 0.100000 */
{0, 200000, 1}, /* 0.200000 */
{0, 400000, 2}, /* 0.400000 */
{0, 800000, 3}, /* 0.800000 */
{1, 600000, 4}, /* 1.600000 */
{3, 200000, 5}, /* 3.200000 */
};
struct cm3232_als_info {
u8 regs_cmd_default;
u8 hw_id;
int calibscale;
int mlux_per_bit;
int mlux_per_bit_base_it;
};
static struct cm3232_als_info cm3232_als_info_default = {
.regs_cmd_default = CM3232_CMD_DEFAULT,
.hw_id = CM3232_HW_ID,
.calibscale = CM3232_CALIBSCALE_DEFAULT,
.mlux_per_bit = CM3232_MLUX_PER_BIT_DEFAULT,
.mlux_per_bit_base_it = CM3232_MLUX_PER_BIT_BASE_IT,
};
struct cm3232_chip {
struct i2c_client *client;
struct cm3232_als_info *als_info;
u8 regs_cmd;
u16 regs_als;
};
/**
* cm3232_reg_init() - Initialize CM3232
* @chip: pointer of struct cm3232_chip.
*
* Check and initialize CM3232 ambient light sensor.
*
* Return: 0 for success; otherwise for error code.
*/
static int cm3232_reg_init(struct cm3232_chip *chip)
{
struct i2c_client *client = chip->client;
s32 ret;
chip->als_info = &cm3232_als_info_default;