Skip to content

Commit

Permalink
staging:iio:max1363 add support for 8 bit equivalent devices, max1036…
Browse files Browse the repository at this point in the history
…-9, max11600-5

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Jonathan Cameron authored and Greg Kroah-Hartman committed May 11, 2010
1 parent c3fa0fd commit 3bf877c
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 17 deletions.
12 changes: 7 additions & 5 deletions drivers/staging/iio/adc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ config MAX1363
select MAX1363_RING_BUFFER
help
Say yes here to build support for many MAXIM i2c analog to digital
convertors (ADC). (max1361, max1362, max1363, max1364, max1136,
max1136, max1137, max1138, max1139, max1236, max1237, max11238,
max1239, max11606, max11607, max11608, max11609, max11610,
max11611, max11612, max11613, max11614, max11615, max11616,
max11617) Provides direct access via sysfs.
convertors (ADC). (max1361, max1362, max1363, max1364, max1036,
max1037, max1038, max1039, max1136, max1136, max1137, max1138,
max1139, max1236, max1237, max11238, max1239, max11600, max11601,
max11602, max11603, max11604, max11605, max11606, max11607,
max11608, max11609, max11610, max11611, max11612, max11613,
max11614, max11615, max11616, max11617) Provides direct access
via sysfs.

config MAX1363_RING_BUFFER
bool "MAXIM max1363: use ring buffer"
Expand Down
143 changes: 137 additions & 6 deletions drivers/staging/iio/adc/max1363_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,24 @@ static ssize_t max1363_read_single_channel(struct device *dev,
if (ret)
goto error_ret;
}
/* Get reading */
data = i2c_master_recv(client, rxbuf, 2);
if (data < 0) {
ret = data;
goto error_ret;
if (st->chip_info->bits != 8) {
/* Get reading */
data = i2c_master_recv(client, rxbuf, 2);
if (data < 0) {
ret = data;
goto error_ret;
}

data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8;
} else {
/* Get reading */
data = i2c_master_recv(client, rxbuf, 1);
if (data < 0) {
ret = data;
goto error_ret;
}
data = rxbuf[0];
}
data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8;
}
/* Pretty print the result */
len = sprintf(buf, "%u\n", data);
Expand Down Expand Up @@ -508,6 +519,10 @@ enum { max1361,
max1362,
max1363,
max1364,
max1036,
max1037,
max1038,
max1039,
max1136,
max1137,
max1138,
Expand All @@ -516,6 +531,12 @@ enum { max1361,
max1237,
max1238,
max1239,
max11600,
max11601,
max11602,
max11603,
max11604,
max11605,
max11606,
max11607,
max11608,
Expand Down Expand Up @@ -576,6 +597,46 @@ static const struct max1363_chip_info max1363_chip_info_tbl[] = {
.default_mode = s0to3,
.dev_attrs = &max1363_dev_attr_group,
.scan_attrs = &max1363_scan_el_group,
}, {
.name = "max1036",
.num_inputs = 4,
.bits = 8,
.int_vref_mv = 4096,
.mode_list = max1236_mode_list,
.num_modes = ARRAY_SIZE(max1236_mode_list),
.default_mode = s0to3,
.dev_attrs = &max1363_dev_attr_group,
.scan_attrs = &max1363_scan_el_group,
}, {
.name = "max1037",
.num_inputs = 4,
.bits = 8,
.int_vref_mv = 2048,
.mode_list = max1236_mode_list,
.num_modes = ARRAY_SIZE(max1236_mode_list),
.default_mode = s0to3,
.dev_attrs = &max1363_dev_attr_group,
.scan_attrs = &max1363_scan_el_group,
}, {
.name = "max1038",
.num_inputs = 12,
.bits = 8,
.int_vref_mv = 4096,
.mode_list = max1238_mode_list,
.num_modes = ARRAY_SIZE(max1238_mode_list),
.default_mode = s0to11,
.dev_attrs = &max1238_dev_attr_group,
.scan_attrs = &max1238_scan_el_group,
}, {
.name = "max1039",
.num_inputs = 12,
.bits = 8,
.int_vref_mv = 2048,
.mode_list = max1238_mode_list,
.num_modes = ARRAY_SIZE(max1238_mode_list),
.default_mode = s0to11,
.dev_attrs = &max1238_dev_attr_group,
.scan_attrs = &max1238_scan_el_group,
}, {
.name = "max1136",
.num_inputs = 4,
Expand Down Expand Up @@ -656,6 +717,66 @@ static const struct max1363_chip_info max1363_chip_info_tbl[] = {
.default_mode = s0to11,
.dev_attrs = &max1238_dev_attr_group,
.scan_attrs = &max1238_scan_el_group,
}, {
.name = "max11600",
.num_inputs = 4,
.bits = 8,
.int_vref_mv = 4096,
.mode_list = max11607_mode_list,
.num_modes = ARRAY_SIZE(max11607_mode_list),
.default_mode = s0to3,
.dev_attrs = &max1363_dev_attr_group,
.scan_attrs = &max1363_scan_el_group,
}, {
.name = "max11601",
.num_inputs = 4,
.bits = 8,
.int_vref_mv = 2048,
.mode_list = max11607_mode_list,
.num_modes = ARRAY_SIZE(max11607_mode_list),
.default_mode = s0to3,
.dev_attrs = &max1363_dev_attr_group,
.scan_attrs = &max1363_scan_el_group,
}, {
.name = "max11602",
.num_inputs = 8,
.bits = 8,
.int_vref_mv = 4096,
.mode_list = max11608_mode_list,
.num_modes = ARRAY_SIZE(max11608_mode_list),
.default_mode = s0to7,
.dev_attrs = &max11608_dev_attr_group,
.scan_attrs = &max11608_scan_el_group,
}, {
.name = "max11603",
.num_inputs = 8,
.bits = 8,
.int_vref_mv = 2048,
.mode_list = max11608_mode_list,
.num_modes = ARRAY_SIZE(max11608_mode_list),
.default_mode = s0to7,
.dev_attrs = &max11608_dev_attr_group,
.scan_attrs = &max11608_scan_el_group,
}, {
.name = "max11604",
.num_inputs = 12,
.bits = 8,
.int_vref_mv = 4098,
.mode_list = max1238_mode_list,
.num_modes = ARRAY_SIZE(max1238_mode_list),
.default_mode = s0to11,
.dev_attrs = &max1238_dev_attr_group,
.scan_attrs = &max1238_scan_el_group,
}, {
.name = "max11605",
.num_inputs = 12,
.bits = 8,
.int_vref_mv = 2048,
.mode_list = max1238_mode_list,
.num_modes = ARRAY_SIZE(max1238_mode_list),
.default_mode = s0to11,
.dev_attrs = &max1238_dev_attr_group,
.scan_attrs = &max1238_scan_el_group,
}, {
.name = "max11606",
.num_inputs = 4,
Expand Down Expand Up @@ -920,6 +1041,10 @@ static const struct i2c_device_id max1363_id[] = {
{ "max1362", max1362 },
{ "max1363", max1363 },
{ "max1364", max1364 },
{ "max1036", max1036 },
{ "max1037", max1037 },
{ "max1038", max1038 },
{ "max1039", max1039 },
{ "max1136", max1136 },
{ "max1137", max1137 },
{ "max1138", max1138 },
Expand All @@ -928,6 +1053,12 @@ static const struct i2c_device_id max1363_id[] = {
{ "max1237", max1237 },
{ "max1238", max1238 },
{ "max1239", max1239 },
{ "max11600", max11600 },
{ "max11601", max11601 },
{ "max11602", max11602 },
{ "max11603", max11603 },
{ "max11604", max11604 },
{ "max11605", max11605 },
{ "max11606", max11606 },
{ "max11607", max11607 },
{ "max11608", max11608 },
Expand Down
23 changes: 17 additions & 6 deletions drivers/staging/iio/adc/max1363_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ int max1363_single_channel_from_ring(long mask, struct max1363_state *st)
count++;
mask >>= 1;
}
return ((int)(ring_data[count*2 + 0] & 0x0F) << 8)
+ (int)(ring_data[count*2 + 1]);
if (st->chip_info->bits != 8)
return ((int)(ring_data[count*2 + 0] & 0x0F) << 8)
+ (int)(ring_data[count*2 + 1]);
else
return ring_data[count];

error_free_ring_data:
kfree(ring_data);
Expand Down Expand Up @@ -90,7 +93,10 @@ static int max1363_ring_preenable(struct iio_dev *indio_dev)

numvals = hweight_long(st->current_mode->modemask);
if (indio_dev->ring->access.set_bpd) {
d_size = numvals*2 + sizeof(s64);
if (st->chip_info->bits != 8)
d_size = numvals*2 + sizeof(s64);
else
d_size = numvals + sizeof(s64);
if (d_size % 8)
d_size += 8 - (d_size % 8);
indio_dev->ring->access.set_bpd(indio_dev->ring, d_size);
Expand Down Expand Up @@ -166,7 +172,10 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s)
unsigned long numvals = hweight_long(st->current_mode->modemask);

/* Ensure the timestamp is 8 byte aligned */
d_size = numvals*2 + sizeof(s64);
if (st->chip_info->bits != 8)
d_size = numvals*2 + sizeof(s64);
else
d_size = numvals + sizeof(s64);
if (d_size % sizeof(s64))
d_size += sizeof(s64) - (d_size % sizeof(s64));

Expand All @@ -184,8 +193,10 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s)
rxbuf = kmalloc(d_size, GFP_KERNEL);
if (rxbuf == NULL)
return;

b_sent = i2c_master_recv(st->client, rxbuf, numvals*2);
if (st->chip_info->bits != 8)
b_sent = i2c_master_recv(st->client, rxbuf, numvals*2);
else
b_sent = i2c_master_recv(st->client, rxbuf, numvals);
if (b_sent < 0)
goto done;

Expand Down

0 comments on commit 3bf877c

Please sign in to comment.