| .. | .. |
|---|
| 34 | 34 | * @value: The value to write to device (up to 4 bytes) |
|---|
| 35 | 35 | * @size: The size of the @value (in bytes) |
|---|
| 36 | 36 | */ |
|---|
| 37 | | -int __adis_write_reg(struct adis *adis, unsigned int reg, |
|---|
| 38 | | - unsigned int value, unsigned int size) |
|---|
| 37 | +int __adis_write_reg(struct adis *adis, unsigned int reg, unsigned int value, |
|---|
| 38 | + unsigned int size) |
|---|
| 39 | 39 | { |
|---|
| 40 | 40 | unsigned int page = reg / ADIS_PAGE_SIZE; |
|---|
| 41 | 41 | int ret, i; |
|---|
| .. | .. |
|---|
| 118 | 118 | ret = spi_sync(adis->spi, &msg); |
|---|
| 119 | 119 | if (ret) { |
|---|
| 120 | 120 | dev_err(&adis->spi->dev, "Failed to write register 0x%02X: %d\n", |
|---|
| 121 | | - reg, ret); |
|---|
| 121 | + reg, ret); |
|---|
| 122 | 122 | } else { |
|---|
| 123 | 123 | adis->current_page = page; |
|---|
| 124 | 124 | } |
|---|
| 125 | 125 | |
|---|
| 126 | 126 | return ret; |
|---|
| 127 | 127 | } |
|---|
| 128 | | -EXPORT_SYMBOL_GPL(__adis_write_reg); |
|---|
| 128 | +EXPORT_SYMBOL_NS_GPL(__adis_write_reg, IIO_ADISLIB); |
|---|
| 129 | 129 | |
|---|
| 130 | 130 | /** |
|---|
| 131 | 131 | * __adis_read_reg() - read N bytes from register (unlocked version) |
|---|
| .. | .. |
|---|
| 134 | 134 | * @val: The value read back from the device |
|---|
| 135 | 135 | * @size: The size of the @val buffer |
|---|
| 136 | 136 | */ |
|---|
| 137 | | -int __adis_read_reg(struct adis *adis, unsigned int reg, |
|---|
| 138 | | - unsigned int *val, unsigned int size) |
|---|
| 137 | +int __adis_read_reg(struct adis *adis, unsigned int reg, unsigned int *val, |
|---|
| 138 | + unsigned int size) |
|---|
| 139 | 139 | { |
|---|
| 140 | 140 | unsigned int page = reg / ADIS_PAGE_SIZE; |
|---|
| 141 | 141 | struct spi_message msg; |
|---|
| .. | .. |
|---|
| 205 | 205 | ret = spi_sync(adis->spi, &msg); |
|---|
| 206 | 206 | if (ret) { |
|---|
| 207 | 207 | dev_err(&adis->spi->dev, "Failed to read register 0x%02X: %d\n", |
|---|
| 208 | | - reg, ret); |
|---|
| 208 | + reg, ret); |
|---|
| 209 | 209 | return ret; |
|---|
| 210 | | - } else { |
|---|
| 211 | | - adis->current_page = page; |
|---|
| 212 | 210 | } |
|---|
| 211 | + |
|---|
| 212 | + adis->current_page = page; |
|---|
| 213 | 213 | |
|---|
| 214 | 214 | switch (size) { |
|---|
| 215 | 215 | case 4: |
|---|
| .. | .. |
|---|
| 222 | 222 | |
|---|
| 223 | 223 | return ret; |
|---|
| 224 | 224 | } |
|---|
| 225 | | -EXPORT_SYMBOL_GPL(__adis_read_reg); |
|---|
| 225 | +EXPORT_SYMBOL_NS_GPL(__adis_read_reg, IIO_ADISLIB); |
|---|
| 226 | 226 | /** |
|---|
| 227 | 227 | * __adis_update_bits_base() - ADIS Update bits function - Unlocked version |
|---|
| 228 | 228 | * @adis: The adis device |
|---|
| .. | .. |
|---|
| 247 | 247 | |
|---|
| 248 | 248 | return __adis_write_reg(adis, reg, __val, size); |
|---|
| 249 | 249 | } |
|---|
| 250 | | -EXPORT_SYMBOL_GPL(__adis_update_bits_base); |
|---|
| 250 | +EXPORT_SYMBOL_NS_GPL(__adis_update_bits_base, IIO_ADISLIB); |
|---|
| 251 | 251 | |
|---|
| 252 | 252 | #ifdef CONFIG_DEBUG_FS |
|---|
| 253 | 253 | |
|---|
| 254 | | -int adis_debugfs_reg_access(struct iio_dev *indio_dev, |
|---|
| 255 | | - unsigned int reg, unsigned int writeval, unsigned int *readval) |
|---|
| 254 | +int adis_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int reg, |
|---|
| 255 | + unsigned int writeval, unsigned int *readval) |
|---|
| 256 | 256 | { |
|---|
| 257 | 257 | struct adis *adis = iio_device_get_drvdata(indio_dev); |
|---|
| 258 | 258 | |
|---|
| 259 | 259 | if (readval) { |
|---|
| 260 | | - uint16_t val16; |
|---|
| 260 | + u16 val16; |
|---|
| 261 | 261 | int ret; |
|---|
| 262 | 262 | |
|---|
| 263 | 263 | ret = adis_read_reg_16(adis, reg, &val16); |
|---|
| .. | .. |
|---|
| 265 | 265 | *readval = val16; |
|---|
| 266 | 266 | |
|---|
| 267 | 267 | return ret; |
|---|
| 268 | | - } else { |
|---|
| 269 | | - return adis_write_reg_16(adis, reg, writeval); |
|---|
| 270 | 268 | } |
|---|
| 269 | + |
|---|
| 270 | + return adis_write_reg_16(adis, reg, writeval); |
|---|
| 271 | 271 | } |
|---|
| 272 | | -EXPORT_SYMBOL(adis_debugfs_reg_access); |
|---|
| 272 | +EXPORT_SYMBOL_NS(adis_debugfs_reg_access, IIO_ADISLIB); |
|---|
| 273 | 273 | |
|---|
| 274 | 274 | #endif |
|---|
| 275 | 275 | |
|---|
| 276 | 276 | /** |
|---|
| 277 | | - * adis_enable_irq() - Enable or disable data ready IRQ |
|---|
| 277 | + * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked) |
|---|
| 278 | 278 | * @adis: The adis device |
|---|
| 279 | 279 | * @enable: Whether to enable the IRQ |
|---|
| 280 | 280 | * |
|---|
| 281 | 281 | * Returns 0 on success, negative error code otherwise |
|---|
| 282 | 282 | */ |
|---|
| 283 | | -int adis_enable_irq(struct adis *adis, bool enable) |
|---|
| 283 | +int __adis_enable_irq(struct adis *adis, bool enable) |
|---|
| 284 | 284 | { |
|---|
| 285 | | - int ret = 0; |
|---|
| 286 | | - uint16_t msc; |
|---|
| 285 | + int ret; |
|---|
| 286 | + u16 msc; |
|---|
| 287 | 287 | |
|---|
| 288 | | - mutex_lock(&adis->state_lock); |
|---|
| 288 | + if (adis->data->enable_irq) |
|---|
| 289 | + return adis->data->enable_irq(adis, enable); |
|---|
| 289 | 290 | |
|---|
| 290 | | - if (adis->data->enable_irq) { |
|---|
| 291 | | - ret = adis->data->enable_irq(adis, enable); |
|---|
| 292 | | - goto out_unlock; |
|---|
| 291 | + if (adis->data->unmasked_drdy) { |
|---|
| 292 | + if (enable) |
|---|
| 293 | + enable_irq(adis->spi->irq); |
|---|
| 294 | + else |
|---|
| 295 | + disable_irq(adis->spi->irq); |
|---|
| 296 | + |
|---|
| 297 | + return 0; |
|---|
| 293 | 298 | } |
|---|
| 294 | 299 | |
|---|
| 295 | 300 | ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc); |
|---|
| 296 | 301 | if (ret) |
|---|
| 297 | | - goto out_unlock; |
|---|
| 302 | + return ret; |
|---|
| 298 | 303 | |
|---|
| 299 | 304 | msc |= ADIS_MSC_CTRL_DATA_RDY_POL_HIGH; |
|---|
| 300 | 305 | msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2; |
|---|
| .. | .. |
|---|
| 303 | 308 | else |
|---|
| 304 | 309 | msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN; |
|---|
| 305 | 310 | |
|---|
| 306 | | - ret = __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc); |
|---|
| 307 | | - |
|---|
| 308 | | -out_unlock: |
|---|
| 309 | | - mutex_unlock(&adis->state_lock); |
|---|
| 310 | | - return ret; |
|---|
| 311 | + return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc); |
|---|
| 311 | 312 | } |
|---|
| 312 | | -EXPORT_SYMBOL(adis_enable_irq); |
|---|
| 313 | +EXPORT_SYMBOL_NS(__adis_enable_irq, IIO_ADISLIB); |
|---|
| 313 | 314 | |
|---|
| 314 | 315 | /** |
|---|
| 315 | 316 | * __adis_check_status() - Check the device for error conditions (unlocked) |
|---|
| .. | .. |
|---|
| 319 | 320 | */ |
|---|
| 320 | 321 | int __adis_check_status(struct adis *adis) |
|---|
| 321 | 322 | { |
|---|
| 322 | | - uint16_t status; |
|---|
| 323 | + u16 status; |
|---|
| 323 | 324 | int ret; |
|---|
| 324 | 325 | int i; |
|---|
| 325 | 326 | |
|---|
| .. | .. |
|---|
| 341 | 342 | |
|---|
| 342 | 343 | return -EIO; |
|---|
| 343 | 344 | } |
|---|
| 344 | | -EXPORT_SYMBOL_GPL(__adis_check_status); |
|---|
| 345 | +EXPORT_SYMBOL_NS_GPL(__adis_check_status, IIO_ADISLIB); |
|---|
| 345 | 346 | |
|---|
| 346 | 347 | /** |
|---|
| 347 | 348 | * __adis_reset() - Reset the device (unlocked version) |
|---|
| .. | .. |
|---|
| 355 | 356 | const struct adis_timeout *timeouts = adis->data->timeouts; |
|---|
| 356 | 357 | |
|---|
| 357 | 358 | ret = __adis_write_reg_8(adis, adis->data->glob_cmd_reg, |
|---|
| 358 | | - ADIS_GLOB_CMD_SW_RESET); |
|---|
| 359 | + ADIS_GLOB_CMD_SW_RESET); |
|---|
| 359 | 360 | if (ret) { |
|---|
| 360 | 361 | dev_err(&adis->spi->dev, "Failed to reset device: %d\n", ret); |
|---|
| 361 | 362 | return ret; |
|---|
| .. | .. |
|---|
| 365 | 366 | |
|---|
| 366 | 367 | return 0; |
|---|
| 367 | 368 | } |
|---|
| 368 | | -EXPORT_SYMBOL_GPL(__adis_reset); |
|---|
| 369 | +EXPORT_SYMBOL_NS_GPL(__adis_reset, IIO_ADIS_LIB); |
|---|
| 369 | 370 | |
|---|
| 370 | 371 | static int adis_self_test(struct adis *adis) |
|---|
| 371 | 372 | { |
|---|
| .. | .. |
|---|
| 411 | 412 | { |
|---|
| 412 | 413 | const struct adis_timeout *timeouts = adis->data->timeouts; |
|---|
| 413 | 414 | struct gpio_desc *gpio; |
|---|
| 414 | | - uint16_t prod_id; |
|---|
| 415 | + u16 prod_id; |
|---|
| 415 | 416 | int ret; |
|---|
| 416 | 417 | |
|---|
| 417 | 418 | /* check if the device has rst pin low */ |
|---|
| .. | .. |
|---|
| 420 | 421 | return PTR_ERR(gpio); |
|---|
| 421 | 422 | |
|---|
| 422 | 423 | if (gpio) { |
|---|
| 423 | | - msleep(10); |
|---|
| 424 | + usleep_range(10, 12); |
|---|
| 424 | 425 | /* bring device out of reset */ |
|---|
| 425 | 426 | gpiod_set_value_cansleep(gpio, 0); |
|---|
| 426 | 427 | msleep(timeouts->reset_ms); |
|---|
| .. | .. |
|---|
| 434 | 435 | if (ret) |
|---|
| 435 | 436 | return ret; |
|---|
| 436 | 437 | |
|---|
| 437 | | - adis_enable_irq(adis, false); |
|---|
| 438 | + /* |
|---|
| 439 | + * don't bother calling this if we can't unmask the IRQ as in this case |
|---|
| 440 | + * the IRQ is most likely not yet requested and we will request it |
|---|
| 441 | + * with 'IRQF_NO_AUTOEN' anyways. |
|---|
| 442 | + */ |
|---|
| 443 | + if (!adis->data->unmasked_drdy) |
|---|
| 444 | + __adis_enable_irq(adis, false); |
|---|
| 438 | 445 | |
|---|
| 439 | 446 | if (!adis->data->prod_id_reg) |
|---|
| 440 | 447 | return 0; |
|---|
| .. | .. |
|---|
| 450 | 457 | |
|---|
| 451 | 458 | return 0; |
|---|
| 452 | 459 | } |
|---|
| 453 | | -EXPORT_SYMBOL_GPL(__adis_initial_startup); |
|---|
| 460 | +EXPORT_SYMBOL_NS_GPL(__adis_initial_startup, IIO_ADISLIB); |
|---|
| 454 | 461 | |
|---|
| 455 | 462 | /** |
|---|
| 456 | 463 | * adis_single_conversion() - Performs a single sample conversion |
|---|
| .. | .. |
|---|
| 468 | 475 | * a error bit in the channels raw value set error_mask to 0. |
|---|
| 469 | 476 | */ |
|---|
| 470 | 477 | int adis_single_conversion(struct iio_dev *indio_dev, |
|---|
| 471 | | - const struct iio_chan_spec *chan, unsigned int error_mask, int *val) |
|---|
| 478 | + const struct iio_chan_spec *chan, |
|---|
| 479 | + unsigned int error_mask, int *val) |
|---|
| 472 | 480 | { |
|---|
| 473 | 481 | struct adis *adis = iio_device_get_drvdata(indio_dev); |
|---|
| 474 | 482 | unsigned int uval; |
|---|
| .. | .. |
|---|
| 477 | 485 | mutex_lock(&adis->state_lock); |
|---|
| 478 | 486 | |
|---|
| 479 | 487 | ret = __adis_read_reg(adis, chan->address, &uval, |
|---|
| 480 | | - chan->scan_type.storagebits / 8); |
|---|
| 488 | + chan->scan_type.storagebits / 8); |
|---|
| 481 | 489 | if (ret) |
|---|
| 482 | 490 | goto err_unlock; |
|---|
| 483 | 491 | |
|---|
| .. | .. |
|---|
| 497 | 505 | mutex_unlock(&adis->state_lock); |
|---|
| 498 | 506 | return ret; |
|---|
| 499 | 507 | } |
|---|
| 500 | | -EXPORT_SYMBOL_GPL(adis_single_conversion); |
|---|
| 508 | +EXPORT_SYMBOL_NS_GPL(adis_single_conversion, IIO_ADISLIB); |
|---|
| 501 | 509 | |
|---|
| 502 | 510 | /** |
|---|
| 503 | 511 | * adis_init() - Initialize adis device structure |
|---|
| .. | .. |
|---|
| 512 | 520 | * called. |
|---|
| 513 | 521 | */ |
|---|
| 514 | 522 | int adis_init(struct adis *adis, struct iio_dev *indio_dev, |
|---|
| 515 | | - struct spi_device *spi, const struct adis_data *data) |
|---|
| 523 | + struct spi_device *spi, const struct adis_data *data) |
|---|
| 516 | 524 | { |
|---|
| 517 | 525 | if (!data || !data->timeouts) { |
|---|
| 518 | 526 | dev_err(&spi->dev, "No config data or timeouts not defined!\n"); |
|---|
| .. | .. |
|---|
| 534 | 542 | |
|---|
| 535 | 543 | return 0; |
|---|
| 536 | 544 | } |
|---|
| 537 | | -EXPORT_SYMBOL_GPL(adis_init); |
|---|
| 545 | +EXPORT_SYMBOL_NS_GPL(adis_init, IIO_ADISLIB); |
|---|
| 538 | 546 | |
|---|
| 539 | 547 | MODULE_LICENSE("GPL"); |
|---|
| 540 | 548 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
|---|