| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * LTC2632 Digital to analog convertors spi driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2017 Maxime Roussin-Bélanger |
|---|
| 5 | 6 | * expanded by Silvan Murer <silvan.murer@gmail.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * Licensed under the GPL-2. |
|---|
| 8 | 7 | */ |
|---|
| 9 | 8 | |
|---|
| 10 | 9 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 13 | 12 | #include <linux/iio/iio.h> |
|---|
| 14 | 13 | #include <linux/regulator/consumer.h> |
|---|
| 15 | 14 | |
|---|
| 16 | | -#define LTC2632_DAC_CHANNELS 2 |
|---|
| 17 | | - |
|---|
| 18 | | -#define LTC2632_ADDR_DAC0 0x0 |
|---|
| 19 | | -#define LTC2632_ADDR_DAC1 0x1 |
|---|
| 15 | +#include <asm/unaligned.h> |
|---|
| 20 | 16 | |
|---|
| 21 | 17 | #define LTC2632_CMD_WRITE_INPUT_N 0x0 |
|---|
| 22 | 18 | #define LTC2632_CMD_UPDATE_DAC_N 0x1 |
|---|
| .. | .. |
|---|
| 30 | 26 | /** |
|---|
| 31 | 27 | * struct ltc2632_chip_info - chip specific information |
|---|
| 32 | 28 | * @channels: channel spec for the DAC |
|---|
| 29 | + * @num_channels: DAC channel count of the chip |
|---|
| 33 | 30 | * @vref_mv: internal reference voltage |
|---|
| 34 | 31 | */ |
|---|
| 35 | 32 | struct ltc2632_chip_info { |
|---|
| 36 | 33 | const struct iio_chan_spec *channels; |
|---|
| 34 | + const size_t num_channels; |
|---|
| 37 | 35 | const int vref_mv; |
|---|
| 38 | 36 | }; |
|---|
| 39 | 37 | |
|---|
| 40 | 38 | /** |
|---|
| 41 | 39 | * struct ltc2632_state - driver instance specific data |
|---|
| 42 | 40 | * @spi_dev: pointer to the spi_device struct |
|---|
| 43 | | - * @powerdown_cache_mask used to show current channel powerdown state |
|---|
| 44 | | - * @vref_mv used reference voltage (internal or external) |
|---|
| 45 | | - * @vref_reg regulator for the reference voltage |
|---|
| 41 | + * @powerdown_cache_mask: used to show current channel powerdown state |
|---|
| 42 | + * @vref_mv: used reference voltage (internal or external) |
|---|
| 43 | + * @vref_reg: regulator for the reference voltage |
|---|
| 46 | 44 | */ |
|---|
| 47 | 45 | struct ltc2632_state { |
|---|
| 48 | 46 | struct spi_device *spi_dev; |
|---|
| .. | .. |
|---|
| 58 | 56 | ID_LTC2632H12, |
|---|
| 59 | 57 | ID_LTC2632H10, |
|---|
| 60 | 58 | ID_LTC2632H8, |
|---|
| 59 | + ID_LTC2634L12, |
|---|
| 60 | + ID_LTC2634L10, |
|---|
| 61 | + ID_LTC2634L8, |
|---|
| 62 | + ID_LTC2634H12, |
|---|
| 63 | + ID_LTC2634H10, |
|---|
| 64 | + ID_LTC2634H8, |
|---|
| 65 | + ID_LTC2636L12, |
|---|
| 66 | + ID_LTC2636L10, |
|---|
| 67 | + ID_LTC2636L8, |
|---|
| 68 | + ID_LTC2636H12, |
|---|
| 69 | + ID_LTC2636H10, |
|---|
| 70 | + ID_LTC2636H8, |
|---|
| 61 | 71 | }; |
|---|
| 62 | 72 | |
|---|
| 63 | 73 | static int ltc2632_spi_write(struct spi_device *spi, |
|---|
| .. | .. |
|---|
| 74 | 84 | * 10-, 8-bit input code followed by 4, 6, or 8 don't care bits. |
|---|
| 75 | 85 | */ |
|---|
| 76 | 86 | data = (cmd << 20) | (addr << 16) | (val << shift); |
|---|
| 77 | | - msg[0] = data >> 16; |
|---|
| 78 | | - msg[1] = data >> 8; |
|---|
| 79 | | - msg[2] = data; |
|---|
| 87 | + put_unaligned_be24(data, &msg[0]); |
|---|
| 80 | 88 | |
|---|
| 81 | 89 | return spi_write(spi, msg, sizeof(msg)); |
|---|
| 82 | 90 | } |
|---|
| .. | .. |
|---|
| 191 | 199 | const struct iio_chan_spec _name ## _channels[] = { \ |
|---|
| 192 | 200 | LTC2632_CHANNEL(0, _bits), \ |
|---|
| 193 | 201 | LTC2632_CHANNEL(1, _bits), \ |
|---|
| 202 | + LTC2632_CHANNEL(2, _bits), \ |
|---|
| 203 | + LTC2632_CHANNEL(3, _bits), \ |
|---|
| 204 | + LTC2632_CHANNEL(4, _bits), \ |
|---|
| 205 | + LTC2632_CHANNEL(5, _bits), \ |
|---|
| 206 | + LTC2632_CHANNEL(6, _bits), \ |
|---|
| 207 | + LTC2632_CHANNEL(7, _bits), \ |
|---|
| 194 | 208 | } |
|---|
| 195 | 209 | |
|---|
| 196 | | -static DECLARE_LTC2632_CHANNELS(ltc2632l12, 12); |
|---|
| 197 | | -static DECLARE_LTC2632_CHANNELS(ltc2632l10, 10); |
|---|
| 198 | | -static DECLARE_LTC2632_CHANNELS(ltc2632l8, 8); |
|---|
| 199 | | - |
|---|
| 200 | | -static DECLARE_LTC2632_CHANNELS(ltc2632h12, 12); |
|---|
| 201 | | -static DECLARE_LTC2632_CHANNELS(ltc2632h10, 10); |
|---|
| 202 | | -static DECLARE_LTC2632_CHANNELS(ltc2632h8, 8); |
|---|
| 210 | +static DECLARE_LTC2632_CHANNELS(ltc2632x12, 12); |
|---|
| 211 | +static DECLARE_LTC2632_CHANNELS(ltc2632x10, 10); |
|---|
| 212 | +static DECLARE_LTC2632_CHANNELS(ltc2632x8, 8); |
|---|
| 203 | 213 | |
|---|
| 204 | 214 | static const struct ltc2632_chip_info ltc2632_chip_info_tbl[] = { |
|---|
| 205 | 215 | [ID_LTC2632L12] = { |
|---|
| 206 | | - .channels = ltc2632l12_channels, |
|---|
| 216 | + .channels = ltc2632x12_channels, |
|---|
| 217 | + .num_channels = 2, |
|---|
| 207 | 218 | .vref_mv = 2500, |
|---|
| 208 | 219 | }, |
|---|
| 209 | 220 | [ID_LTC2632L10] = { |
|---|
| 210 | | - .channels = ltc2632l10_channels, |
|---|
| 221 | + .channels = ltc2632x10_channels, |
|---|
| 222 | + .num_channels = 2, |
|---|
| 211 | 223 | .vref_mv = 2500, |
|---|
| 212 | 224 | }, |
|---|
| 213 | 225 | [ID_LTC2632L8] = { |
|---|
| 214 | | - .channels = ltc2632l8_channels, |
|---|
| 226 | + .channels = ltc2632x8_channels, |
|---|
| 227 | + .num_channels = 2, |
|---|
| 215 | 228 | .vref_mv = 2500, |
|---|
| 216 | 229 | }, |
|---|
| 217 | 230 | [ID_LTC2632H12] = { |
|---|
| 218 | | - .channels = ltc2632h12_channels, |
|---|
| 231 | + .channels = ltc2632x12_channels, |
|---|
| 232 | + .num_channels = 2, |
|---|
| 219 | 233 | .vref_mv = 4096, |
|---|
| 220 | 234 | }, |
|---|
| 221 | 235 | [ID_LTC2632H10] = { |
|---|
| 222 | | - .channels = ltc2632h10_channels, |
|---|
| 236 | + .channels = ltc2632x10_channels, |
|---|
| 237 | + .num_channels = 2, |
|---|
| 223 | 238 | .vref_mv = 4096, |
|---|
| 224 | 239 | }, |
|---|
| 225 | 240 | [ID_LTC2632H8] = { |
|---|
| 226 | | - .channels = ltc2632h8_channels, |
|---|
| 241 | + .channels = ltc2632x8_channels, |
|---|
| 242 | + .num_channels = 2, |
|---|
| 243 | + .vref_mv = 4096, |
|---|
| 244 | + }, |
|---|
| 245 | + [ID_LTC2634L12] = { |
|---|
| 246 | + .channels = ltc2632x12_channels, |
|---|
| 247 | + .num_channels = 4, |
|---|
| 248 | + .vref_mv = 2500, |
|---|
| 249 | + }, |
|---|
| 250 | + [ID_LTC2634L10] = { |
|---|
| 251 | + .channels = ltc2632x10_channels, |
|---|
| 252 | + .num_channels = 4, |
|---|
| 253 | + .vref_mv = 2500, |
|---|
| 254 | + }, |
|---|
| 255 | + [ID_LTC2634L8] = { |
|---|
| 256 | + .channels = ltc2632x8_channels, |
|---|
| 257 | + .num_channels = 4, |
|---|
| 258 | + .vref_mv = 2500, |
|---|
| 259 | + }, |
|---|
| 260 | + [ID_LTC2634H12] = { |
|---|
| 261 | + .channels = ltc2632x12_channels, |
|---|
| 262 | + .num_channels = 4, |
|---|
| 263 | + .vref_mv = 4096, |
|---|
| 264 | + }, |
|---|
| 265 | + [ID_LTC2634H10] = { |
|---|
| 266 | + .channels = ltc2632x10_channels, |
|---|
| 267 | + .num_channels = 4, |
|---|
| 268 | + .vref_mv = 4096, |
|---|
| 269 | + }, |
|---|
| 270 | + [ID_LTC2634H8] = { |
|---|
| 271 | + .channels = ltc2632x8_channels, |
|---|
| 272 | + .num_channels = 4, |
|---|
| 273 | + .vref_mv = 4096, |
|---|
| 274 | + }, |
|---|
| 275 | + [ID_LTC2636L12] = { |
|---|
| 276 | + .channels = ltc2632x12_channels, |
|---|
| 277 | + .num_channels = 8, |
|---|
| 278 | + .vref_mv = 2500, |
|---|
| 279 | + }, |
|---|
| 280 | + [ID_LTC2636L10] = { |
|---|
| 281 | + .channels = ltc2632x10_channels, |
|---|
| 282 | + .num_channels = 8, |
|---|
| 283 | + .vref_mv = 2500, |
|---|
| 284 | + }, |
|---|
| 285 | + [ID_LTC2636L8] = { |
|---|
| 286 | + .channels = ltc2632x8_channels, |
|---|
| 287 | + .num_channels = 8, |
|---|
| 288 | + .vref_mv = 2500, |
|---|
| 289 | + }, |
|---|
| 290 | + [ID_LTC2636H12] = { |
|---|
| 291 | + .channels = ltc2632x12_channels, |
|---|
| 292 | + .num_channels = 8, |
|---|
| 293 | + .vref_mv = 4096, |
|---|
| 294 | + }, |
|---|
| 295 | + [ID_LTC2636H10] = { |
|---|
| 296 | + .channels = ltc2632x10_channels, |
|---|
| 297 | + .num_channels = 8, |
|---|
| 298 | + .vref_mv = 4096, |
|---|
| 299 | + }, |
|---|
| 300 | + [ID_LTC2636H8] = { |
|---|
| 301 | + .channels = ltc2632x8_channels, |
|---|
| 302 | + .num_channels = 8, |
|---|
| 227 | 303 | .vref_mv = 4096, |
|---|
| 228 | 304 | }, |
|---|
| 229 | 305 | }; |
|---|
| .. | .. |
|---|
| 286 | 362 | } |
|---|
| 287 | 363 | } |
|---|
| 288 | 364 | |
|---|
| 289 | | - indio_dev->dev.parent = &spi->dev; |
|---|
| 290 | 365 | indio_dev->name = dev_of_node(&spi->dev) ? dev_of_node(&spi->dev)->name |
|---|
| 291 | 366 | : spi_get_device_id(spi)->name; |
|---|
| 292 | 367 | indio_dev->info = <c2632_info; |
|---|
| 293 | 368 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 294 | 369 | indio_dev->channels = chip_info->channels; |
|---|
| 295 | | - indio_dev->num_channels = LTC2632_DAC_CHANNELS; |
|---|
| 370 | + indio_dev->num_channels = chip_info->num_channels; |
|---|
| 296 | 371 | |
|---|
| 297 | 372 | return iio_device_register(indio_dev); |
|---|
| 298 | 373 | } |
|---|
| .. | .. |
|---|
| 317 | 392 | { "ltc2632-h12", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2632H12] }, |
|---|
| 318 | 393 | { "ltc2632-h10", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2632H10] }, |
|---|
| 319 | 394 | { "ltc2632-h8", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2632H8] }, |
|---|
| 395 | + { "ltc2634-l12", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2634L12] }, |
|---|
| 396 | + { "ltc2634-l10", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2634L10] }, |
|---|
| 397 | + { "ltc2634-l8", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2634L8] }, |
|---|
| 398 | + { "ltc2634-h12", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2634H12] }, |
|---|
| 399 | + { "ltc2634-h10", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2634H10] }, |
|---|
| 400 | + { "ltc2634-h8", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2634H8] }, |
|---|
| 401 | + { "ltc2636-l12", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2636L12] }, |
|---|
| 402 | + { "ltc2636-l10", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2636L10] }, |
|---|
| 403 | + { "ltc2636-l8", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2636L8] }, |
|---|
| 404 | + { "ltc2636-h12", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2636H12] }, |
|---|
| 405 | + { "ltc2636-h10", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2636H10] }, |
|---|
| 406 | + { "ltc2636-h8", (kernel_ulong_t)<c2632_chip_info_tbl[ID_LTC2636H8] }, |
|---|
| 320 | 407 | {} |
|---|
| 321 | 408 | }; |
|---|
| 322 | 409 | MODULE_DEVICE_TABLE(spi, ltc2632_id); |
|---|
| .. | .. |
|---|
| 340 | 427 | }, { |
|---|
| 341 | 428 | .compatible = "lltc,ltc2632-h8", |
|---|
| 342 | 429 | .data = <c2632_chip_info_tbl[ID_LTC2632H8] |
|---|
| 430 | + }, { |
|---|
| 431 | + .compatible = "lltc,ltc2634-l12", |
|---|
| 432 | + .data = <c2632_chip_info_tbl[ID_LTC2634L12] |
|---|
| 433 | + }, { |
|---|
| 434 | + .compatible = "lltc,ltc2634-l10", |
|---|
| 435 | + .data = <c2632_chip_info_tbl[ID_LTC2634L10] |
|---|
| 436 | + }, { |
|---|
| 437 | + .compatible = "lltc,ltc2634-l8", |
|---|
| 438 | + .data = <c2632_chip_info_tbl[ID_LTC2634L8] |
|---|
| 439 | + }, { |
|---|
| 440 | + .compatible = "lltc,ltc2634-h12", |
|---|
| 441 | + .data = <c2632_chip_info_tbl[ID_LTC2634H12] |
|---|
| 442 | + }, { |
|---|
| 443 | + .compatible = "lltc,ltc2634-h10", |
|---|
| 444 | + .data = <c2632_chip_info_tbl[ID_LTC2634H10] |
|---|
| 445 | + }, { |
|---|
| 446 | + .compatible = "lltc,ltc2634-h8", |
|---|
| 447 | + .data = <c2632_chip_info_tbl[ID_LTC2634H8] |
|---|
| 448 | + }, { |
|---|
| 449 | + .compatible = "lltc,ltc2636-l12", |
|---|
| 450 | + .data = <c2632_chip_info_tbl[ID_LTC2636L12] |
|---|
| 451 | + }, { |
|---|
| 452 | + .compatible = "lltc,ltc2636-l10", |
|---|
| 453 | + .data = <c2632_chip_info_tbl[ID_LTC2636L10] |
|---|
| 454 | + }, { |
|---|
| 455 | + .compatible = "lltc,ltc2636-l8", |
|---|
| 456 | + .data = <c2632_chip_info_tbl[ID_LTC2636L8] |
|---|
| 457 | + }, { |
|---|
| 458 | + .compatible = "lltc,ltc2636-h12", |
|---|
| 459 | + .data = <c2632_chip_info_tbl[ID_LTC2636H12] |
|---|
| 460 | + }, { |
|---|
| 461 | + .compatible = "lltc,ltc2636-h10", |
|---|
| 462 | + .data = <c2632_chip_info_tbl[ID_LTC2636H10] |
|---|
| 463 | + }, { |
|---|
| 464 | + .compatible = "lltc,ltc2636-h8", |
|---|
| 465 | + .data = <c2632_chip_info_tbl[ID_LTC2636H8] |
|---|
| 343 | 466 | }, |
|---|
| 344 | 467 | {} |
|---|
| 345 | 468 | }; |
|---|