Lines Matching +full:vid +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-or-later
141 * This scale factor is axis-dependent, and is derived from 3 calibration
150 * Hadj = H * ( ( ( (ASA-128)*0.5 ) / 128 ) + 1 )
158 * H is in the range of -4096 to 4095. The magnetometer has a range of
159 * +-1229uT. To go from the raw value to uT is:
182 * H is in the range of +-8190. The magnetometer has a range of
183 * +-4912uT. To go from the raw value to uT is:
196 * H is in the range of -32752 to 32752. The magnetometer has a range of
197 * +-4912uT. To go from the raw value to uT is:
408 * Per-instance context data for the device.
424 struct regulator *vid; member
438 ret = regulator_enable(data->vdd); in ak8975_power_on()
440 dev_warn(&data->client->dev, in ak8975_power_on()
441 "Failed to enable specified Vdd supply\n"); in ak8975_power_on()
444 ret = regulator_enable(data->vid); in ak8975_power_on()
446 dev_warn(&data->client->dev, in ak8975_power_on()
447 "Failed to enable specified Vid supply\n"); in ak8975_power_on()
448 regulator_disable(data->vdd); in ak8975_power_on()
452 gpiod_set_value_cansleep(data->reset_gpiod, 0); in ak8975_power_on()
455 * According to the datasheet the power supply rise time is 200us in ak8975_power_on()
466 gpiod_set_value_cansleep(data->reset_gpiod, 1); in ak8975_power_off()
468 regulator_disable(data->vid); in ak8975_power_off()
469 regulator_disable(data->vdd); in ak8975_power_off()
495 dev_err(&client->dev, "Error reading WIA\n"); in ak8975_who_i_am()
500 return -ENODEV; in ak8975_who_i_am()
524 dev_info(&client->dev, "Device ID %x is unknown.\n", wia_val[1]); in ak8975_who_i_am()
540 regval = (data->cntl_cache & ~data->def->ctrl_masks[CNTL_MODE]) | in ak8975_set_mode()
541 data->def->ctrl_modes[mode]; in ak8975_set_mode()
542 ret = i2c_smbus_write_byte_data(data->client, in ak8975_set_mode()
543 data->def->ctrl_regs[CNTL], regval); in ak8975_set_mode()
547 data->cntl_cache = regval; in ak8975_set_mode()
561 set_bit(0, &ak8975->flags); in ak8975_irq_handler()
562 wake_up(&ak8975->data_ready_queue); in ak8975_irq_handler()
572 struct i2c_client *client = data->client; in ak8975_setup_irq()
576 init_waitqueue_head(&data->data_ready_queue); in ak8975_setup_irq()
577 clear_bit(0, &data->flags); in ak8975_setup_irq()
578 if (client->irq) in ak8975_setup_irq()
579 irq = client->irq; in ak8975_setup_irq()
581 irq = gpiod_to_irq(data->eoc_gpiod); in ak8975_setup_irq()
583 rc = devm_request_irq(&client->dev, irq, ak8975_irq_handler, in ak8975_setup_irq()
585 dev_name(&client->dev), data); in ak8975_setup_irq()
587 dev_err(&client->dev, "irq %d request failed: %d\n", irq, rc); in ak8975_setup_irq()
591 data->eoc_irq = irq; in ak8975_setup_irq()
598 * Perform some start-of-day setup, including reading the asa calibration
610 dev_err(&client->dev, "Error in setting fuse access mode\n"); in ak8975_setup()
616 client, data->def->ctrl_regs[ASA_BASE], in ak8975_setup()
617 3, data->asa); in ak8975_setup()
619 dev_err(&client->dev, "Not able to read asa data\n"); in ak8975_setup()
623 /* After reading fuse ROM data set power-down mode */ in ak8975_setup()
626 dev_err(&client->dev, "Error in setting power-down mode\n"); in ak8975_setup()
630 if (data->eoc_gpiod || client->irq > 0) { in ak8975_setup()
633 dev_err(&client->dev, in ak8975_setup()
639 data->raw_to_gauss[0] = data->def->raw_to_gauss(data->asa[0]); in ak8975_setup()
640 data->raw_to_gauss[1] = data->def->raw_to_gauss(data->asa[1]); in ak8975_setup()
641 data->raw_to_gauss[2] = data->def->raw_to_gauss(data->asa[2]); in ak8975_setup()
648 struct i2c_client *client = data->client; in wait_conversion_complete_gpio()
655 if (gpiod_get_value(data->eoc_gpiod)) in wait_conversion_complete_gpio()
657 timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; in wait_conversion_complete_gpio()
660 dev_err(&client->dev, "Conversion timeout happened\n"); in wait_conversion_complete_gpio()
661 return -EINVAL; in wait_conversion_complete_gpio()
664 ret = i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST1]); in wait_conversion_complete_gpio()
666 dev_err(&client->dev, "Error in reading ST1\n"); in wait_conversion_complete_gpio()
673 struct i2c_client *client = data->client; in wait_conversion_complete_polled()
682 data->def->ctrl_regs[ST1]); in wait_conversion_complete_polled()
684 dev_err(&client->dev, "Error in reading ST1\n"); in wait_conversion_complete_polled()
690 timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; in wait_conversion_complete_polled()
693 dev_err(&client->dev, "Conversion timeout happened\n"); in wait_conversion_complete_polled()
694 return -EINVAL; in wait_conversion_complete_polled()
700 /* Returns 0 if the end of conversion interrupt occured or -ETIME otherwise */
705 ret = wait_event_timeout(data->data_ready_queue, in wait_conversion_complete_interrupt()
706 test_bit(0, &data->flags), in wait_conversion_complete_interrupt()
708 clear_bit(0, &data->flags); in wait_conversion_complete_interrupt()
710 return ret > 0 ? 0 : -ETIME; in wait_conversion_complete_interrupt()
720 dev_err(&client->dev, "Error in setting operating mode\n"); in ak8975_start_read_axis()
725 if (data->eoc_irq) in ak8975_start_read_axis()
727 else if (data->eoc_gpiod) in ak8975_start_read_axis()
735 return !data->def->ctrl_regs[ST1_DRDY]; in ak8975_start_read_axis()
742 const struct i2c_client *client = data->client; in ak8975_read_axis()
743 const struct ak_def *def = data->def; in ak8975_read_axis()
748 pm_runtime_get_sync(&data->client->dev); in ak8975_read_axis()
750 mutex_lock(&data->lock); in ak8975_read_axis()
757 client, def->data_regs[index], in ak8975_read_axis()
763 ret = i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST2]); in ak8975_read_axis()
765 dev_err(&client->dev, "Error in reading ST2\n"); in ak8975_read_axis()
769 if (ret & (data->def->ctrl_masks[ST2_DERR] | in ak8975_read_axis()
770 data->def->ctrl_masks[ST2_HOFL])) { in ak8975_read_axis()
771 dev_err(&client->dev, "ST2 status error 0x%x\n", ret); in ak8975_read_axis()
772 ret = -EINVAL; in ak8975_read_axis()
776 mutex_unlock(&data->lock); in ak8975_read_axis()
778 pm_runtime_mark_last_busy(&data->client->dev); in ak8975_read_axis()
779 pm_runtime_put_autosuspend(&data->client->dev); in ak8975_read_axis()
783 *val = clamp_t(s16, buff, -def->range, def->range); in ak8975_read_axis()
787 mutex_unlock(&data->lock); in ak8975_read_axis()
788 dev_err(&client->dev, "Error in reading axis\n"); in ak8975_read_axis()
801 return ak8975_read_axis(indio_dev, chan->address, val); in ak8975_read_raw()
804 *val2 = data->raw_to_gauss[chan->address]; in ak8975_read_raw()
807 return -EINVAL; in ak8975_read_raw()
816 return &data->orientation; in ak8975_get_mount_matrix()
856 const struct i2c_client *client = data->client; in ak8975_fill_buffer()
857 const struct ak_def *def = data->def; in ak8975_fill_buffer()
861 mutex_lock(&data->lock); in ak8975_fill_buffer()
872 def->data_regs[0], in ak8975_fill_buffer()
878 mutex_unlock(&data->lock); in ak8975_fill_buffer()
881 data->scan.channels[0] = clamp_t(s16, le16_to_cpu(fval[0]), -def->range, def->range); in ak8975_fill_buffer()
882 data->scan.channels[1] = clamp_t(s16, le16_to_cpu(fval[1]), -def->range, def->range); in ak8975_fill_buffer()
883 data->scan.channels[2] = clamp_t(s16, le16_to_cpu(fval[2]), -def->range, def->range); in ak8975_fill_buffer()
885 iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, in ak8975_fill_buffer()
891 mutex_unlock(&data->lock); in ak8975_fill_buffer()
892 dev_err(&client->dev, "Error in reading axes block\n"); in ak8975_fill_buffer()
898 struct iio_dev *indio_dev = pf->indio_dev; in ak8975_handle_trigger()
901 iio_trigger_notify_done(indio_dev->trig); in ak8975_handle_trigger()
920 eoc_gpiod = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN); in ak8975_probe()
931 reset_gpiod = devm_gpiod_get_optional(&client->dev, in ak8975_probe()
937 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in ak8975_probe()
939 return -ENOMEM; in ak8975_probe()
944 data->client = client; in ak8975_probe()
945 data->eoc_gpiod = eoc_gpiod; in ak8975_probe()
946 data->reset_gpiod = reset_gpiod; in ak8975_probe()
947 data->eoc_irq = 0; in ak8975_probe()
949 err = iio_read_mount_matrix(&client->dev, &data->orientation); in ak8975_probe()
954 data->def = i2c_get_match_data(client); in ak8975_probe()
955 if (!data->def) in ak8975_probe()
956 return -ENODEV; in ak8975_probe()
959 if (dev_fwnode(&client->dev)) in ak8975_probe()
960 name = dev_name(&client->dev); in ak8975_probe()
962 name = id->name; in ak8975_probe()
965 data->vdd = devm_regulator_get(&client->dev, "vdd"); in ak8975_probe()
966 if (IS_ERR(data->vdd)) in ak8975_probe()
967 return PTR_ERR(data->vdd); in ak8975_probe()
968 data->vid = devm_regulator_get(&client->dev, "vid"); in ak8975_probe()
969 if (IS_ERR(data->vid)) in ak8975_probe()
970 return PTR_ERR(data->vid); in ak8975_probe()
976 err = ak8975_who_i_am(client, data->def->type); in ak8975_probe()
978 dev_err(&client->dev, "Unexpected device\n"); in ak8975_probe()
981 dev_dbg(&client->dev, "Asahi compass chip %s\n", name); in ak8975_probe()
983 /* Perform some basic start-of-day setup of the device. */ in ak8975_probe()
986 dev_err(&client->dev, "%s initialization fails\n", name); in ak8975_probe()
990 mutex_init(&data->lock); in ak8975_probe()
991 indio_dev->channels = ak8975_channels; in ak8975_probe()
992 indio_dev->num_channels = ARRAY_SIZE(ak8975_channels); in ak8975_probe()
993 indio_dev->info = &ak8975_info; in ak8975_probe()
994 indio_dev->available_scan_masks = ak8975_scan_masks; in ak8975_probe()
995 indio_dev->modes = INDIO_DIRECT_MODE; in ak8975_probe()
996 indio_dev->name = name; in ak8975_probe()
1001 dev_err(&client->dev, "triggered buffer setup failed\n"); in ak8975_probe()
1007 dev_err(&client->dev, "device register failed\n"); in ak8975_probe()
1012 pm_runtime_get_noresume(&client->dev); in ak8975_probe()
1013 pm_runtime_set_active(&client->dev); in ak8975_probe()
1014 pm_runtime_enable(&client->dev); in ak8975_probe()
1019 pm_runtime_set_autosuspend_delay(&client->dev, 50); in ak8975_probe()
1020 pm_runtime_use_autosuspend(&client->dev); in ak8975_probe()
1021 pm_runtime_put(&client->dev); in ak8975_probe()
1037 pm_runtime_get_sync(&client->dev); in ak8975_remove()
1038 pm_runtime_put_noidle(&client->dev); in ak8975_remove()
1039 pm_runtime_disable(&client->dev); in ak8975_remove()
1056 dev_err(&client->dev, "Error in setting power-down mode\n"); in ak8975_runtime_suspend()
1080 dev_err(&client->dev, "Error in setting power-down mode\n"); in ak8975_runtime_resume()
1115 { .compatible = "asahi-kasei,ak8975", .data = &ak_def_array[AK8975] },
1117 { .compatible = "asahi-kasei,ak8963", .data = &ak_def_array[AK8963] },
1119 { .compatible = "asahi-kasei,ak09911", .data = &ak_def_array[AK09911] },
1121 { .compatible = "asahi-kasei,ak09912", .data = &ak_def_array[AK09912] },
1123 { .compatible = "asahi-kasei,ak09916", .data = &ak_def_array[AK09916] },
1124 { .compatible = "asahi-kasei,ak09918", .data = &ak_def_array[AK09918] },