Lines Matching +full:resistance +full:- +full:temp +full:- +full:table
3 * TWL4030 MADC module driver-This driver monitors the real time
7 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
8 * J Keerthy <j-keerthy@ti.com>
10 * Based on twl4030-madc.c
28 * 02110-1301 USA
132 * struct twl4030_madc_request - madc request packet for channel conversion
167 * struct twl4030_madc_data - a container for madc info
172 * @use_second_irq: IRQ selection (main or co-processor)
196 req.method = madc->use_second_irq ? TWL4030_MADC_SW2 : TWL4030_MADC_SW1; in twl4030_madc_read()
198 req.channels = BIT(chan->channel); in twl4030_madc_read()
208 *val = req.rbuf[chan->channel]; in twl4030_madc_read()
274 /* Conversion table from -3 to 55 degrees Celcius */
316 * twl4030_madc_channel_raw_read() - Function to read a particular channel value
332 dev_err(madc->dev, "unable to read register 0x%X\n", reg); in twl4030_madc_channel_raw_read()
346 int temp, curr, volt, res, ret; in twl4030battery_temperature() local
356 /* Getting and calculating the thermistor resistance in ohms */ in twl4030battery_temperature()
359 for (temp = 58; temp >= 0; temp--) { in twl4030battery_temperature()
360 int actual = twl4030_therm_tbl[temp]; in twl4030battery_temperature()
361 if ((actual - res) >= 0) in twl4030battery_temperature()
365 return temp + 1; in twl4030battery_temperature()
385 * @madc - pointer to twl4030_madc_data struct
386 * @reg_base - Base address of the first channel
387 * @Channels - 16 bit bitmap. If the bit is set, channel's value is read
388 * @buf - The channel values are stored here. if read fails error
389 * @raw - Return raw values without conversion
406 dev_err(madc->dev, "Unable to read register 0x%X\n", in twl4030_madc_read_channels()
418 dev_err(madc->dev, "err reading current\n"); in twl4030_madc_read_channels()
422 buf[i] = buf[i] - 750; in twl4030_madc_read_channels()
428 dev_err(madc->dev, "err reading temperature\n"); in twl4030_madc_read_channels()
431 buf[i] -= 3; in twl4030_madc_read_channels()
438 * conv_result = decimal value of 10-bit conversion in twl4030_madc_read_channels()
440 * step size = 1.5 / (2 ^ 10 -1) in twl4030_madc_read_channels()
456 * @madc - pointer to twl4030_madc_data struct
457 * @id - irq number to be disabled
467 ret = twl_i2c_read_u8(TWL4030_MODULE_MADC, &val, madc->imr); in twl4030_madc_disable_irq()
469 dev_err(madc->dev, "unable to read imr register 0x%X\n", in twl4030_madc_disable_irq()
470 madc->imr); in twl4030_madc_disable_irq()
474 ret = twl_i2c_write_u8(TWL4030_MODULE_MADC, val, madc->imr); in twl4030_madc_disable_irq()
476 dev_err(madc->dev, in twl4030_madc_disable_irq()
477 "unable to write imr register 0x%X\n", madc->imr); in twl4030_madc_disable_irq()
492 mutex_lock(&madc->lock); in twl4030_madc_threaded_irq_handler()
493 ret = twl_i2c_read_u8(TWL4030_MODULE_MADC, &isr_val, madc->isr); in twl4030_madc_threaded_irq_handler()
495 dev_err(madc->dev, "unable to read isr register 0x%X\n", in twl4030_madc_threaded_irq_handler()
496 madc->isr); in twl4030_madc_threaded_irq_handler()
499 ret = twl_i2c_read_u8(TWL4030_MODULE_MADC, &imr_val, madc->imr); in twl4030_madc_threaded_irq_handler()
501 dev_err(madc->dev, "unable to read imr register 0x%X\n", in twl4030_madc_threaded_irq_handler()
502 madc->imr); in twl4030_madc_threaded_irq_handler()
511 dev_dbg(madc->dev, "Disable interrupt failed %d\n", i); in twl4030_madc_threaded_irq_handler()
512 madc->requests[i].result_pending = 1; in twl4030_madc_threaded_irq_handler()
515 r = &madc->requests[i]; in twl4030_madc_threaded_irq_handler()
517 if (!r->result_pending) in twl4030_madc_threaded_irq_handler()
519 method = &twl4030_conversion_methods[r->method]; in twl4030_madc_threaded_irq_handler()
521 len = twl4030_madc_read_channels(madc, method->rbase, in twl4030_madc_threaded_irq_handler()
522 r->channels, r->rbuf, r->raw); in twl4030_madc_threaded_irq_handler()
524 r->result_pending = 0; in twl4030_madc_threaded_irq_handler()
525 r->active = 0; in twl4030_madc_threaded_irq_handler()
527 mutex_unlock(&madc->lock); in twl4030_madc_threaded_irq_handler()
537 r = &madc->requests[i]; in twl4030_madc_threaded_irq_handler()
538 if (r->active == 0) in twl4030_madc_threaded_irq_handler()
540 method = &twl4030_conversion_methods[r->method]; in twl4030_madc_threaded_irq_handler()
542 len = twl4030_madc_read_channels(madc, method->rbase, in twl4030_madc_threaded_irq_handler()
543 r->channels, r->rbuf, r->raw); in twl4030_madc_threaded_irq_handler()
545 r->result_pending = 0; in twl4030_madc_threaded_irq_handler()
546 r->active = 0; in twl4030_madc_threaded_irq_handler()
548 mutex_unlock(&madc->lock); in twl4030_madc_threaded_irq_handler()
556 * @madc - pointer to twl4030_madc_data struct
557 * @conv_method - can be TWL4030_MADC_RT, TWL4030_MADC_SW2, TWL4030_MADC_SW1
568 return -ENOTSUPP; in twl4030_madc_start_conversion()
572 method->ctrl); in twl4030_madc_start_conversion()
574 dev_err(madc->dev, "unable to write ctrl register 0x%X\n", in twl4030_madc_start_conversion()
575 method->ctrl); in twl4030_madc_start_conversion()
584 * @madc - pointer to twl4030_madc_data struct
585 * @timeout_ms - timeout value in milliseconds
586 * @status_reg - ctrl register
602 dev_err(madc->dev, in twl4030_madc_wait_conversion_ready()
611 dev_err(madc->dev, "conversion timeout!\n"); in twl4030_madc_wait_conversion_ready()
613 return -EAGAIN; in twl4030_madc_wait_conversion_ready()
619 * req->rbuf will be filled with read values of channels based on the
630 return -EINVAL; in twl4030_madc_conversion()
632 mutex_lock(&twl4030_madc->lock); in twl4030_madc_conversion()
633 if (req->method < TWL4030_MADC_RT || req->method > TWL4030_MADC_SW2) { in twl4030_madc_conversion()
634 ret = -EINVAL; in twl4030_madc_conversion()
638 if (twl4030_madc->requests[req->method].active) { in twl4030_madc_conversion()
639 ret = -EBUSY; in twl4030_madc_conversion()
642 method = &twl4030_conversion_methods[req->method]; in twl4030_madc_conversion()
644 ret = twl_i2c_write_u16(TWL4030_MODULE_MADC, req->channels, method->sel); in twl4030_madc_conversion()
646 dev_err(twl4030_madc->dev, in twl4030_madc_conversion()
647 "unable to write sel register 0x%X\n", method->sel); in twl4030_madc_conversion()
651 if (req->do_avg) { in twl4030_madc_conversion()
652 ret = twl_i2c_write_u16(TWL4030_MODULE_MADC, req->channels, in twl4030_madc_conversion()
653 method->avg); in twl4030_madc_conversion()
655 dev_err(twl4030_madc->dev, in twl4030_madc_conversion()
657 method->avg); in twl4030_madc_conversion()
662 if (req->method == TWL4030_MADC_RT) { in twl4030_madc_conversion()
663 ret = -EINVAL; in twl4030_madc_conversion()
666 ret = twl4030_madc_start_conversion(twl4030_madc, req->method); in twl4030_madc_conversion()
669 twl4030_madc->requests[req->method].active = 1; in twl4030_madc_conversion()
671 ret = twl4030_madc_wait_conversion_ready(twl4030_madc, 5, method->ctrl); in twl4030_madc_conversion()
673 twl4030_madc->requests[req->method].active = 0; in twl4030_madc_conversion()
676 ret = twl4030_madc_read_channels(twl4030_madc, method->rbase, in twl4030_madc_conversion()
677 req->channels, req->rbuf, req->raw); in twl4030_madc_conversion()
678 twl4030_madc->requests[req->method].active = 0; in twl4030_madc_conversion()
681 mutex_unlock(&twl4030_madc->lock); in twl4030_madc_conversion()
687 * twl4030_madc_set_current_generator() - setup bias current
691 * 0 - Enables bias current for main battery type reading
692 * 1 - Enables bias current for main battery temperature sensing
708 dev_err(madc->dev, "unable to read BCICTL1 reg 0x%X", in twl4030_madc_set_current_generator()
722 dev_err(madc->dev, "unable to write BCICTL1 reg 0x%X\n", in twl4030_madc_set_current_generator()
732 * @madc - pointer to twl4030_madc_data struct
733 * @on - Enable or disable MADC software power on bit.
744 dev_err(madc->dev, "unable to read madc ctrl1 reg 0x%X\n", in twl4030_madc_set_power()
754 dev_err(madc->dev, "unable to write madc ctrl1 reg 0x%X\n", in twl4030_madc_set_power()
768 struct twl4030_madc_platform_data *pdata = dev_get_platdata(&pdev->dev); in twl4030_madc_probe()
769 struct device_node *np = pdev->dev.of_node; in twl4030_madc_probe()
775 dev_err(&pdev->dev, "neither platform data nor Device Tree node available\n"); in twl4030_madc_probe()
776 return -EINVAL; in twl4030_madc_probe()
779 iio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*madc)); in twl4030_madc_probe()
781 dev_err(&pdev->dev, "failed allocating iio device\n"); in twl4030_madc_probe()
782 return -ENOMEM; in twl4030_madc_probe()
786 madc->dev = &pdev->dev; in twl4030_madc_probe()
788 iio_dev->name = dev_name(&pdev->dev); in twl4030_madc_probe()
789 iio_dev->dev.parent = &pdev->dev; in twl4030_madc_probe()
790 iio_dev->dev.of_node = pdev->dev.of_node; in twl4030_madc_probe()
791 iio_dev->info = &twl4030_madc_iio_info; in twl4030_madc_probe()
792 iio_dev->modes = INDIO_DIRECT_MODE; in twl4030_madc_probe()
793 iio_dev->channels = twl4030_madc_iio_channels; in twl4030_madc_probe()
794 iio_dev->num_channels = ARRAY_SIZE(twl4030_madc_iio_channels); in twl4030_madc_probe()
802 madc->use_second_irq = (pdata->irq_line != 1); in twl4030_madc_probe()
804 madc->use_second_irq = of_property_read_bool(np, in twl4030_madc_probe()
805 "ti,system-uses-second-madc-irq"); in twl4030_madc_probe()
807 madc->imr = madc->use_second_irq ? TWL4030_MADC_IMR2 : in twl4030_madc_probe()
809 madc->isr = madc->use_second_irq ? TWL4030_MADC_ISR2 : in twl4030_madc_probe()
822 dev_err(&pdev->dev, "unable to read reg BCI CTL1 0x%X\n", in twl4030_madc_probe()
830 dev_err(&pdev->dev, "unable to write reg BCI Ctl1 0x%X\n", in twl4030_madc_probe()
838 dev_err(&pdev->dev, "unable to read reg GPBR1 0x%X\n", in twl4030_madc_probe()
845 dev_info(&pdev->dev, "clk disabled, enabling\n"); in twl4030_madc_probe()
850 dev_err(&pdev->dev, "unable to write reg GPBR1 0x%X\n", in twl4030_madc_probe()
857 mutex_init(&madc->lock); in twl4030_madc_probe()
860 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in twl4030_madc_probe()
865 dev_err(&pdev->dev, "could not request irq\n"); in twl4030_madc_probe()
874 dev_err(&pdev->dev, "unable to read reg CARKIT_ANA_CTRL 0x%X\n", in twl4030_madc_probe()
882 dev_err(&pdev->dev, "unable to write reg CARKIT_ANA_CTRL 0x%X\n", in twl4030_madc_probe()
888 madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1"); in twl4030_madc_probe()
889 if (IS_ERR(madc->usb3v1)) { in twl4030_madc_probe()
890 ret = -ENODEV; in twl4030_madc_probe()
894 ret = regulator_enable(madc->usb3v1); in twl4030_madc_probe()
896 dev_err(madc->dev, "could not enable 3v1 bias regulator\n"); in twl4030_madc_probe()
902 dev_err(&pdev->dev, "could not register iio device\n"); in twl4030_madc_probe()
909 regulator_disable(madc->usb3v1); in twl4030_madc_probe()
927 regulator_disable(madc->usb3v1); in twl4030_madc_remove()
934 { .compatible = "ti,twl4030-madc", },