| .. | .. |
|---|
| 1 | 1 | /* |
|---|
| 2 | 2 | * TI ADC MFD driver |
|---|
| 3 | 3 | * |
|---|
| 4 | | - * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ |
|---|
| 4 | + * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com/ |
|---|
| 5 | 5 | * |
|---|
| 6 | 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | 7 | * modify it under the terms of the GNU General Public License as |
|---|
| .. | .. |
|---|
| 142 | 142 | stepconfig |= STEPCONFIG_MODE_SWCNT; |
|---|
| 143 | 143 | |
|---|
| 144 | 144 | tiadc_writel(adc_dev, REG_STEPCONFIG(steps), |
|---|
| 145 | | - stepconfig | STEPCONFIG_INP(chan)); |
|---|
| 145 | + stepconfig | STEPCONFIG_INP(chan) | |
|---|
| 146 | + STEPCONFIG_INM_ADCREFM | |
|---|
| 147 | + STEPCONFIG_RFP_VREFP | |
|---|
| 148 | + STEPCONFIG_RFM_VREFN); |
|---|
| 146 | 149 | |
|---|
| 147 | 150 | if (adc_dev->open_delay[i] > STEPDELAY_OPEN_MASK) { |
|---|
| 148 | 151 | dev_warn(dev, "chan %d open delay truncating to 0x3FFFF\n", |
|---|
| .. | .. |
|---|
| 291 | 294 | static int tiadc_buffer_preenable(struct iio_dev *indio_dev) |
|---|
| 292 | 295 | { |
|---|
| 293 | 296 | struct tiadc_device *adc_dev = iio_priv(indio_dev); |
|---|
| 294 | | - int i, fifo1count, read; |
|---|
| 297 | + int i, fifo1count; |
|---|
| 295 | 298 | |
|---|
| 296 | 299 | tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES | |
|---|
| 297 | 300 | IRQENB_FIFO1OVRRUN | |
|---|
| .. | .. |
|---|
| 300 | 303 | /* Flush FIFO. Needed in corner cases in simultaneous tsc/adc use */ |
|---|
| 301 | 304 | fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); |
|---|
| 302 | 305 | for (i = 0; i < fifo1count; i++) |
|---|
| 303 | | - read = tiadc_readl(adc_dev, REG_FIFO1); |
|---|
| 306 | + tiadc_readl(adc_dev, REG_FIFO1); |
|---|
| 304 | 307 | |
|---|
| 305 | 308 | return 0; |
|---|
| 306 | 309 | } |
|---|
| .. | .. |
|---|
| 340 | 343 | { |
|---|
| 341 | 344 | struct tiadc_device *adc_dev = iio_priv(indio_dev); |
|---|
| 342 | 345 | struct tiadc_dma *dma = &adc_dev->dma; |
|---|
| 343 | | - int fifo1count, i, read; |
|---|
| 346 | + int fifo1count, i; |
|---|
| 344 | 347 | |
|---|
| 345 | 348 | tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES | |
|---|
| 346 | 349 | IRQENB_FIFO1OVRRUN | IRQENB_FIFO1UNDRFLW)); |
|---|
| .. | .. |
|---|
| 355 | 358 | /* Flush FIFO of leftover data in the time it takes to disable adc */ |
|---|
| 356 | 359 | fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT); |
|---|
| 357 | 360 | for (i = 0; i < fifo1count; i++) |
|---|
| 358 | | - read = tiadc_readl(adc_dev, REG_FIFO1); |
|---|
| 361 | + tiadc_readl(adc_dev, REG_FIFO1); |
|---|
| 359 | 362 | |
|---|
| 360 | 363 | return 0; |
|---|
| 361 | 364 | } |
|---|
| .. | .. |
|---|
| 374 | 377 | .postdisable = &tiadc_buffer_postdisable, |
|---|
| 375 | 378 | }; |
|---|
| 376 | 379 | |
|---|
| 377 | | -static int tiadc_iio_buffered_hardware_setup(struct iio_dev *indio_dev, |
|---|
| 380 | +static int tiadc_iio_buffered_hardware_setup(struct device *dev, |
|---|
| 381 | + struct iio_dev *indio_dev, |
|---|
| 378 | 382 | irqreturn_t (*pollfunc_bh)(int irq, void *p), |
|---|
| 379 | 383 | irqreturn_t (*pollfunc_th)(int irq, void *p), |
|---|
| 380 | 384 | int irq, |
|---|
| .. | .. |
|---|
| 384 | 388 | struct iio_buffer *buffer; |
|---|
| 385 | 389 | int ret; |
|---|
| 386 | 390 | |
|---|
| 387 | | - buffer = iio_kfifo_allocate(); |
|---|
| 391 | + buffer = devm_iio_kfifo_allocate(dev); |
|---|
| 388 | 392 | if (!buffer) |
|---|
| 389 | 393 | return -ENOMEM; |
|---|
| 390 | 394 | |
|---|
| 391 | 395 | iio_device_attach_buffer(indio_dev, buffer); |
|---|
| 392 | 396 | |
|---|
| 393 | | - ret = request_threaded_irq(irq, pollfunc_th, pollfunc_bh, |
|---|
| 397 | + ret = devm_request_threaded_irq(dev, irq, pollfunc_th, pollfunc_bh, |
|---|
| 394 | 398 | flags, indio_dev->name, indio_dev); |
|---|
| 395 | 399 | if (ret) |
|---|
| 396 | | - goto error_kfifo_free; |
|---|
| 400 | + return ret; |
|---|
| 397 | 401 | |
|---|
| 398 | 402 | indio_dev->setup_ops = setup_ops; |
|---|
| 399 | 403 | indio_dev->modes |= INDIO_BUFFER_SOFTWARE; |
|---|
| 400 | 404 | |
|---|
| 401 | 405 | return 0; |
|---|
| 402 | | - |
|---|
| 403 | | -error_kfifo_free: |
|---|
| 404 | | - iio_kfifo_free(indio_dev->buffer); |
|---|
| 405 | | - return ret; |
|---|
| 406 | 406 | } |
|---|
| 407 | | - |
|---|
| 408 | | -static void tiadc_iio_buffered_hardware_remove(struct iio_dev *indio_dev) |
|---|
| 409 | | -{ |
|---|
| 410 | | - struct tiadc_device *adc_dev = iio_priv(indio_dev); |
|---|
| 411 | | - |
|---|
| 412 | | - free_irq(adc_dev->mfd_tscadc->irq, indio_dev); |
|---|
| 413 | | - iio_kfifo_free(indio_dev->buffer); |
|---|
| 414 | | -} |
|---|
| 415 | | - |
|---|
| 416 | 407 | |
|---|
| 417 | 408 | static const char * const chan_name_ain[] = { |
|---|
| 418 | 409 | "AIN0", |
|---|
| .. | .. |
|---|
| 425 | 416 | "AIN7", |
|---|
| 426 | 417 | }; |
|---|
| 427 | 418 | |
|---|
| 428 | | -static int tiadc_channel_init(struct iio_dev *indio_dev, int channels) |
|---|
| 419 | +static int tiadc_channel_init(struct device *dev, struct iio_dev *indio_dev, |
|---|
| 420 | + int channels) |
|---|
| 429 | 421 | { |
|---|
| 430 | 422 | struct tiadc_device *adc_dev = iio_priv(indio_dev); |
|---|
| 431 | 423 | struct iio_chan_spec *chan_array; |
|---|
| .. | .. |
|---|
| 433 | 425 | int i; |
|---|
| 434 | 426 | |
|---|
| 435 | 427 | indio_dev->num_channels = channels; |
|---|
| 436 | | - chan_array = kcalloc(channels, sizeof(*chan_array), GFP_KERNEL); |
|---|
| 428 | + chan_array = devm_kcalloc(dev, channels, sizeof(*chan_array), |
|---|
| 429 | + GFP_KERNEL); |
|---|
| 437 | 430 | if (chan_array == NULL) |
|---|
| 438 | 431 | return -ENOMEM; |
|---|
| 439 | 432 | |
|---|
| .. | .. |
|---|
| 454 | 447 | indio_dev->channels = chan_array; |
|---|
| 455 | 448 | |
|---|
| 456 | 449 | return 0; |
|---|
| 457 | | -} |
|---|
| 458 | | - |
|---|
| 459 | | -static void tiadc_channels_remove(struct iio_dev *indio_dev) |
|---|
| 460 | | -{ |
|---|
| 461 | | - kfree(indio_dev->channels); |
|---|
| 462 | 450 | } |
|---|
| 463 | 451 | |
|---|
| 464 | 452 | static int tiadc_read_raw(struct iio_dev *indio_dev, |
|---|
| .. | .. |
|---|
| 623 | 611 | adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev); |
|---|
| 624 | 612 | tiadc_parse_dt(pdev, adc_dev); |
|---|
| 625 | 613 | |
|---|
| 626 | | - indio_dev->dev.parent = &pdev->dev; |
|---|
| 627 | 614 | indio_dev->name = dev_name(&pdev->dev); |
|---|
| 628 | 615 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 629 | 616 | indio_dev->info = &tiadc_info; |
|---|
| .. | .. |
|---|
| 632 | 619 | tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD); |
|---|
| 633 | 620 | mutex_init(&adc_dev->fifo1_lock); |
|---|
| 634 | 621 | |
|---|
| 635 | | - err = tiadc_channel_init(indio_dev, adc_dev->channels); |
|---|
| 622 | + err = tiadc_channel_init(&pdev->dev, indio_dev, adc_dev->channels); |
|---|
| 636 | 623 | if (err < 0) |
|---|
| 637 | 624 | return err; |
|---|
| 638 | 625 | |
|---|
| 639 | | - err = tiadc_iio_buffered_hardware_setup(indio_dev, |
|---|
| 626 | + err = tiadc_iio_buffered_hardware_setup(&pdev->dev, indio_dev, |
|---|
| 640 | 627 | &tiadc_worker_h, |
|---|
| 641 | 628 | &tiadc_irq_h, |
|---|
| 642 | 629 | adc_dev->mfd_tscadc->irq, |
|---|
| .. | .. |
|---|
| 661 | 648 | err_dma: |
|---|
| 662 | 649 | iio_device_unregister(indio_dev); |
|---|
| 663 | 650 | err_buffer_unregister: |
|---|
| 664 | | - tiadc_iio_buffered_hardware_remove(indio_dev); |
|---|
| 665 | 651 | err_free_channels: |
|---|
| 666 | | - tiadc_channels_remove(indio_dev); |
|---|
| 667 | 652 | return err; |
|---|
| 668 | 653 | } |
|---|
| 669 | 654 | |
|---|
| .. | .. |
|---|
| 680 | 665 | dma_release_channel(dma->chan); |
|---|
| 681 | 666 | } |
|---|
| 682 | 667 | iio_device_unregister(indio_dev); |
|---|
| 683 | | - tiadc_iio_buffered_hardware_remove(indio_dev); |
|---|
| 684 | | - tiadc_channels_remove(indio_dev); |
|---|
| 685 | 668 | |
|---|
| 686 | 669 | step_en = get_adc_step_mask(adc_dev); |
|---|
| 687 | 670 | am335x_tsc_se_clr(adc_dev->mfd_tscadc, step_en); |
|---|
| .. | .. |
|---|
| 693 | 676 | { |
|---|
| 694 | 677 | struct iio_dev *indio_dev = dev_get_drvdata(dev); |
|---|
| 695 | 678 | struct tiadc_device *adc_dev = iio_priv(indio_dev); |
|---|
| 696 | | - struct ti_tscadc_dev *tscadc_dev; |
|---|
| 697 | 679 | unsigned int idle; |
|---|
| 698 | 680 | |
|---|
| 699 | | - tscadc_dev = ti_tscadc_dev_get(to_platform_device(dev)); |
|---|
| 700 | | - if (!device_may_wakeup(tscadc_dev->dev)) { |
|---|
| 701 | | - idle = tiadc_readl(adc_dev, REG_CTRL); |
|---|
| 702 | | - idle &= ~(CNTRLREG_TSCSSENB); |
|---|
| 703 | | - tiadc_writel(adc_dev, REG_CTRL, (idle | |
|---|
| 704 | | - CNTRLREG_POWERDOWN)); |
|---|
| 705 | | - } |
|---|
| 681 | + idle = tiadc_readl(adc_dev, REG_CTRL); |
|---|
| 682 | + idle &= ~(CNTRLREG_TSCSSENB); |
|---|
| 683 | + tiadc_writel(adc_dev, REG_CTRL, (idle | |
|---|
| 684 | + CNTRLREG_POWERDOWN)); |
|---|
| 706 | 685 | |
|---|
| 707 | 686 | return 0; |
|---|
| 708 | 687 | } |
|---|