#define VCNL4000_SLEEP_DELAY_MS 2000 /* before we enter pm_runtime_suspend */
-enum vcnl4000_device_ids {
- CM36672P,
- VCNL4000,
- VCNL4010,
- VCNL4040,
- VCNL4200,
-};
-
struct vcnl4200_channel {
u8 reg;
ktime_t last_measurement;
struct vcnl4000_data {
struct i2c_client *client;
- enum vcnl4000_device_ids id;
int rev;
int al_scale;
int ps_scale;
const int prod_id;
};
-static const struct i2c_device_id vcnl4000_id[] = {
- { "cm36672p", CM36672P },
- { "cm36686", VCNL4040 },
- { "vcnl4000", VCNL4000 },
- { "vcnl4010", VCNL4010 },
- { "vcnl4020", VCNL4010 },
- { "vcnl4040", VCNL4040 },
- { "vcnl4200", VCNL4200 },
- { }
-};
-MODULE_DEVICE_TABLE(i2c, vcnl4000_id);
-
static int vcnl4000_set_power_state(struct vcnl4000_data *data, bool on)
{
/* no suspend op */
.read_avail = vcnl4040_read_avail,
};
-static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
- [CM36672P] = {
- .prod = "CM36672P",
- .init = vcnl4200_init,
- .measure_proximity = vcnl4200_measure_proximity,
- .set_power_state = vcnl4200_set_power_state,
- .channels = cm36672p_channels,
- .num_channels = ARRAY_SIZE(cm36672p_channels),
- .info = &vcnl4040_info,
- .irq_thread = vcnl4040_irq_thread,
- .int_reg = VCNL4040_INT_FLAGS,
- .ps_it_times = &vcnl4040_ps_it_times,
- .num_ps_it_times = ARRAY_SIZE(vcnl4040_ps_it_times),
- .prod_id = VCNL4040_PROD_ID,
- },
- [VCNL4000] = {
- .prod = "VCNL4000",
- .init = vcnl4000_init,
- .measure_light = vcnl4000_measure_light,
- .measure_proximity = vcnl4000_measure_proximity,
- .set_power_state = vcnl4000_set_power_state,
- .channels = vcnl4000_channels,
- .num_channels = ARRAY_SIZE(vcnl4000_channels),
- .info = &vcnl4000_info,
- .prod_id = VCNL4000_PROD_ID,
- },
- [VCNL4010] = {
- .prod = "VCNL4010/4020",
- .init = vcnl4000_init,
- .measure_light = vcnl4000_measure_light,
- .measure_proximity = vcnl4000_measure_proximity,
- .set_power_state = vcnl4000_set_power_state,
- .channels = vcnl4010_channels,
- .num_channels = ARRAY_SIZE(vcnl4010_channels),
- .info = &vcnl4010_info,
- .irq_thread = vcnl4010_irq_thread,
- .trig_buffer_func = vcnl4010_trigger_handler,
- .buffer_setup_ops = &vcnl4010_buffer_ops,
- .prod_id = VCNL4010_PROD_ID,
- },
- [VCNL4040] = {
- .prod = "VCNL4040",
- .init = vcnl4200_init,
- .measure_light = vcnl4200_measure_light,
- .measure_proximity = vcnl4200_measure_proximity,
- .set_power_state = vcnl4200_set_power_state,
- .channels = vcnl4040_channels,
- .num_channels = ARRAY_SIZE(vcnl4040_channels),
- .info = &vcnl4040_info,
- .irq_thread = vcnl4040_irq_thread,
- .int_reg = VCNL4040_INT_FLAGS,
- .ps_it_times = &vcnl4040_ps_it_times,
- .num_ps_it_times = ARRAY_SIZE(vcnl4040_ps_it_times),
- .als_it_times = &vcnl4040_als_it_times,
- .num_als_it_times = ARRAY_SIZE(vcnl4040_als_it_times),
- .ulux_step = 100000,
- .prod_id = VCNL4040_PROD_ID,
- },
- [VCNL4200] = {
- .prod = "VCNL4200",
- .init = vcnl4200_init,
- .measure_light = vcnl4200_measure_light,
- .measure_proximity = vcnl4200_measure_proximity,
- .set_power_state = vcnl4200_set_power_state,
- .channels = vcnl4040_channels,
- .num_channels = ARRAY_SIZE(vcnl4000_channels),
- .info = &vcnl4040_info,
- .irq_thread = vcnl4040_irq_thread,
- .int_reg = VCNL4200_INT_FLAGS,
- .ps_it_times = &vcnl4200_ps_it_times,
- .num_ps_it_times = ARRAY_SIZE(vcnl4200_ps_it_times),
- .als_it_times = &vcnl4200_als_it_times,
- .num_als_it_times = ARRAY_SIZE(vcnl4200_als_it_times),
- .ulux_step = 24000,
- .prod_id = VCNL4200_PROD_ID,
- },
+static const struct vcnl4000_chip_spec cm36672p_spec = {
+ .prod = "CM36672P",
+ .init = vcnl4200_init,
+ .measure_proximity = vcnl4200_measure_proximity,
+ .set_power_state = vcnl4200_set_power_state,
+ .channels = cm36672p_channels,
+ .num_channels = ARRAY_SIZE(cm36672p_channels),
+ .info = &vcnl4040_info,
+ .irq_thread = vcnl4040_irq_thread,
+ .int_reg = VCNL4040_INT_FLAGS,
+ .ps_it_times = &vcnl4040_ps_it_times,
+ .num_ps_it_times = ARRAY_SIZE(vcnl4040_ps_it_times),
+ .prod_id = VCNL4040_PROD_ID,
+};
+
+static const struct vcnl4000_chip_spec vcnl4000_spec = {
+ .prod = "VCNL4000",
+ .init = vcnl4000_init,
+ .measure_light = vcnl4000_measure_light,
+ .measure_proximity = vcnl4000_measure_proximity,
+ .set_power_state = vcnl4000_set_power_state,
+ .channels = vcnl4000_channels,
+ .num_channels = ARRAY_SIZE(vcnl4000_channels),
+ .info = &vcnl4000_info,
+ .prod_id = VCNL4000_PROD_ID,
+};
+
+static const struct vcnl4000_chip_spec vcnl4010_spec = {
+ .prod = "VCNL4010/4020",
+ .init = vcnl4000_init,
+ .measure_light = vcnl4000_measure_light,
+ .measure_proximity = vcnl4000_measure_proximity,
+ .set_power_state = vcnl4000_set_power_state,
+ .channels = vcnl4010_channels,
+ .num_channels = ARRAY_SIZE(vcnl4010_channels),
+ .info = &vcnl4010_info,
+ .irq_thread = vcnl4010_irq_thread,
+ .trig_buffer_func = vcnl4010_trigger_handler,
+ .buffer_setup_ops = &vcnl4010_buffer_ops,
+ .prod_id = VCNL4010_PROD_ID,
+};
+
+static const struct vcnl4000_chip_spec vcnl4040_spec = {
+ .prod = "VCNL4040",
+ .init = vcnl4200_init,
+ .measure_light = vcnl4200_measure_light,
+ .measure_proximity = vcnl4200_measure_proximity,
+ .set_power_state = vcnl4200_set_power_state,
+ .channels = vcnl4040_channels,
+ .num_channels = ARRAY_SIZE(vcnl4040_channels),
+ .info = &vcnl4040_info,
+ .irq_thread = vcnl4040_irq_thread,
+ .int_reg = VCNL4040_INT_FLAGS,
+ .ps_it_times = &vcnl4040_ps_it_times,
+ .num_ps_it_times = ARRAY_SIZE(vcnl4040_ps_it_times),
+ .als_it_times = &vcnl4040_als_it_times,
+ .num_als_it_times = ARRAY_SIZE(vcnl4040_als_it_times),
+ .ulux_step = 100000,
+ .prod_id = VCNL4040_PROD_ID,
+};
+
+static const struct vcnl4000_chip_spec vcnl4200_spec = {
+ .prod = "VCNL4200",
+ .init = vcnl4200_init,
+ .measure_light = vcnl4200_measure_light,
+ .measure_proximity = vcnl4200_measure_proximity,
+ .set_power_state = vcnl4200_set_power_state,
+ .channels = vcnl4040_channels,
+ .num_channels = ARRAY_SIZE(vcnl4000_channels),
+ .info = &vcnl4040_info,
+ .irq_thread = vcnl4040_irq_thread,
+ .int_reg = VCNL4200_INT_FLAGS,
+ .ps_it_times = &vcnl4200_ps_it_times,
+ .num_ps_it_times = ARRAY_SIZE(vcnl4200_ps_it_times),
+ .als_it_times = &vcnl4200_als_it_times,
+ .num_als_it_times = ARRAY_SIZE(vcnl4200_als_it_times),
+ .ulux_step = 24000,
+ .prod_id = VCNL4200_PROD_ID,
};
static const struct iio_trigger_ops vcnl4010_trigger_ops = {
static int vcnl4000_probe(struct i2c_client *client)
{
- const struct i2c_device_id *id = i2c_client_get_device_id(client);
const char * const regulator_names[] = { "vdd", "vio", "vled" };
struct device *dev = &client->dev;
struct vcnl4000_data *data;
data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
data->client = client;
- data->id = id->driver_data;
- data->chip_spec = &vcnl4000_chip_spec_cfg[data->id];
+ data->chip_spec = i2c_get_match_data(client);
ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulator_names),
regulator_names);
static const struct of_device_id vcnl_4000_of_match[] = {
{
.compatible = "capella,cm36672p",
- .data = (void *)CM36672P,
+ .data = &cm36672p_spec,
},
/* Capella CM36686 is fully compatible with Vishay VCNL4040 */
{
.compatible = "capella,cm36686",
- .data = (void *)VCNL4040,
+ .data = &vcnl4040_spec,
},
{
.compatible = "vishay,vcnl4000",
- .data = (void *)VCNL4000,
+ .data = &vcnl4000_spec,
},
{
.compatible = "vishay,vcnl4010",
- .data = (void *)VCNL4010,
+ .data = &vcnl4010_spec,
},
{
.compatible = "vishay,vcnl4020",
- .data = (void *)VCNL4010,
+ .data = &vcnl4010_spec,
},
{
.compatible = "vishay,vcnl4040",
- .data = (void *)VCNL4040,
+ .data = &vcnl4040_spec,
},
{
.compatible = "vishay,vcnl4200",
- .data = (void *)VCNL4200,
+ .data = &vcnl4200_spec,
},
{ }
};
static DEFINE_RUNTIME_DEV_PM_OPS(vcnl4000_pm_ops, vcnl4000_runtime_suspend,
vcnl4000_runtime_resume, NULL);
+static const struct i2c_device_id vcnl4000_id[] = {
+ { "cm36672p", (kernel_ulong_t)&cm36672p_spec },
+ { "cm36686", (kernel_ulong_t)&vcnl4040_spec },
+ { "vcnl4000", (kernel_ulong_t)&vcnl4000_spec },
+ { "vcnl4010", (kernel_ulong_t)&vcnl4010_spec },
+ { "vcnl4020", (kernel_ulong_t)&vcnl4010_spec },
+ { "vcnl4040", (kernel_ulong_t)&vcnl4040_spec },
+ { "vcnl4200", (kernel_ulong_t)&vcnl4200_spec },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, vcnl4000_id);
+
static struct i2c_driver vcnl4000_driver = {
.driver = {
.name = VCNL4000_DRV_NAME,