Lines Matching +full:asahi +full:- +full:kasei

1 // SPDX-License-Identifier: GPL-2.0-or-later
140 * This scale factor is axis-dependent, and is derived from 3 calibration
149 * Hadj = H * ( ( ( (ASA-128)*0.5 ) / 128 ) + 1 )
157 * H is in the range of -4096 to 4095. The magnetometer has a range of
158 * +-1229uT. To go from the raw value to uT is:
181 * H is in the range of +-8190. The magnetometer has a range of
182 * +-4912uT. To go from the raw value to uT is:
195 * H is in the range of -32752 to 32752. The magnetometer has a range of
196 * +-4912uT. To go from the raw value to uT is:
205 /* Compatible Asahi Kasei Compass parts */
379 * Per-instance context data for the device.
409 ret = regulator_enable(data->vdd); in ak8975_power_on()
411 dev_warn(&data->client->dev, in ak8975_power_on()
415 ret = regulator_enable(data->vid); in ak8975_power_on()
417 dev_warn(&data->client->dev, in ak8975_power_on()
419 regulator_disable(data->vdd); in ak8975_power_on()
423 gpiod_set_value_cansleep(data->reset_gpiod, 0); in ak8975_power_on()
437 gpiod_set_value_cansleep(data->reset_gpiod, 1); in ak8975_power_off()
439 regulator_disable(data->vid); in ak8975_power_off()
440 regulator_disable(data->vdd); in ak8975_power_off()
465 dev_err(&client->dev, "Error reading WIA\n"); in ak8975_who_i_am()
470 return -ENODEV; in ak8975_who_i_am()
489 dev_err(&client->dev, "Type %d unknown\n", type); in ak8975_who_i_am()
491 return -ENODEV; in ak8975_who_i_am()
502 regval = (data->cntl_cache & ~data->def->ctrl_masks[CNTL_MODE]) | in ak8975_set_mode()
503 data->def->ctrl_modes[mode]; in ak8975_set_mode()
504 ret = i2c_smbus_write_byte_data(data->client, in ak8975_set_mode()
505 data->def->ctrl_regs[CNTL], regval); in ak8975_set_mode()
509 data->cntl_cache = regval; in ak8975_set_mode()
523 set_bit(0, &ak8975->flags); in ak8975_irq_handler()
524 wake_up(&ak8975->data_ready_queue); in ak8975_irq_handler()
534 struct i2c_client *client = data->client; in ak8975_setup_irq()
538 init_waitqueue_head(&data->data_ready_queue); in ak8975_setup_irq()
539 clear_bit(0, &data->flags); in ak8975_setup_irq()
540 if (client->irq) in ak8975_setup_irq()
541 irq = client->irq; in ak8975_setup_irq()
543 irq = gpiod_to_irq(data->eoc_gpiod); in ak8975_setup_irq()
545 rc = devm_request_irq(&client->dev, irq, ak8975_irq_handler, in ak8975_setup_irq()
547 dev_name(&client->dev), data); in ak8975_setup_irq()
549 dev_err(&client->dev, "irq %d request failed: %d\n", irq, rc); in ak8975_setup_irq()
553 data->eoc_irq = irq; in ak8975_setup_irq()
560 * Perform some start-of-day setup, including reading the asa calibration
572 dev_err(&client->dev, "Error in setting fuse access mode\n"); in ak8975_setup()
578 client, data->def->ctrl_regs[ASA_BASE], in ak8975_setup()
579 3, data->asa); in ak8975_setup()
581 dev_err(&client->dev, "Not able to read asa data\n"); in ak8975_setup()
585 /* After reading fuse ROM data set power-down mode */ in ak8975_setup()
588 dev_err(&client->dev, "Error in setting power-down mode\n"); in ak8975_setup()
592 if (data->eoc_gpiod || client->irq > 0) { in ak8975_setup()
595 dev_err(&client->dev, in ak8975_setup()
601 data->raw_to_gauss[0] = data->def->raw_to_gauss(data->asa[0]); in ak8975_setup()
602 data->raw_to_gauss[1] = data->def->raw_to_gauss(data->asa[1]); in ak8975_setup()
603 data->raw_to_gauss[2] = data->def->raw_to_gauss(data->asa[2]); in ak8975_setup()
610 struct i2c_client *client = data->client; in wait_conversion_complete_gpio()
617 if (gpiod_get_value(data->eoc_gpiod)) in wait_conversion_complete_gpio()
619 timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; in wait_conversion_complete_gpio()
622 dev_err(&client->dev, "Conversion timeout happened\n"); in wait_conversion_complete_gpio()
623 return -EINVAL; in wait_conversion_complete_gpio()
626 ret = i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST1]); in wait_conversion_complete_gpio()
628 dev_err(&client->dev, "Error in reading ST1\n"); in wait_conversion_complete_gpio()
635 struct i2c_client *client = data->client; in wait_conversion_complete_polled()
644 data->def->ctrl_regs[ST1]); in wait_conversion_complete_polled()
646 dev_err(&client->dev, "Error in reading ST1\n"); in wait_conversion_complete_polled()
652 timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; in wait_conversion_complete_polled()
655 dev_err(&client->dev, "Conversion timeout happened\n"); in wait_conversion_complete_polled()
656 return -EINVAL; in wait_conversion_complete_polled()
662 /* Returns 0 if the end of conversion interrupt occured or -ETIME otherwise */
667 ret = wait_event_timeout(data->data_ready_queue, in wait_conversion_complete_interrupt()
668 test_bit(0, &data->flags), in wait_conversion_complete_interrupt()
670 clear_bit(0, &data->flags); in wait_conversion_complete_interrupt()
672 return ret > 0 ? 0 : -ETIME; in wait_conversion_complete_interrupt()
682 dev_err(&client->dev, "Error in setting operating mode\n"); in ak8975_start_read_axis()
687 if (data->eoc_irq) in ak8975_start_read_axis()
689 else if (data->eoc_gpiod) in ak8975_start_read_axis()
696 /* This will be executed only for non-interrupt based waiting case */ in ak8975_start_read_axis()
697 if (ret & data->def->ctrl_masks[ST1_DRDY]) { in ak8975_start_read_axis()
699 data->def->ctrl_regs[ST2]); in ak8975_start_read_axis()
701 dev_err(&client->dev, "Error in reading ST2\n"); in ak8975_start_read_axis()
704 if (ret & (data->def->ctrl_masks[ST2_DERR] | in ak8975_start_read_axis()
705 data->def->ctrl_masks[ST2_HOFL])) { in ak8975_start_read_axis()
706 dev_err(&client->dev, "ST2 status error 0x%x\n", ret); in ak8975_start_read_axis()
707 return -EINVAL; in ak8975_start_read_axis()
718 const struct i2c_client *client = data->client; in ak8975_read_axis()
719 const struct ak_def *def = data->def; in ak8975_read_axis()
724 pm_runtime_get_sync(&data->client->dev); in ak8975_read_axis()
726 mutex_lock(&data->lock); in ak8975_read_axis()
733 client, def->data_regs[index], in ak8975_read_axis()
738 mutex_unlock(&data->lock); in ak8975_read_axis()
740 pm_runtime_mark_last_busy(&data->client->dev); in ak8975_read_axis()
741 pm_runtime_put_autosuspend(&data->client->dev); in ak8975_read_axis()
745 *val = clamp_t(s16, buff, -def->range, def->range); in ak8975_read_axis()
749 mutex_unlock(&data->lock); in ak8975_read_axis()
750 dev_err(&client->dev, "Error in reading axis\n"); in ak8975_read_axis()
763 return ak8975_read_axis(indio_dev, chan->address, val); in ak8975_read_raw()
766 *val2 = data->raw_to_gauss[chan->address]; in ak8975_read_raw()
769 return -EINVAL; in ak8975_read_raw()
778 return &data->orientation; in ak8975_get_mount_matrix()
830 const struct i2c_client *client = data->client; in ak8975_fill_buffer()
831 const struct ak_def *def = data->def; in ak8975_fill_buffer()
835 mutex_lock(&data->lock); in ak8975_fill_buffer()
846 def->data_regs[0], in ak8975_fill_buffer()
852 mutex_unlock(&data->lock); in ak8975_fill_buffer()
855 data->scan.channels[0] = clamp_t(s16, le16_to_cpu(fval[0]), -def->range, def->range); in ak8975_fill_buffer()
856 data->scan.channels[1] = clamp_t(s16, le16_to_cpu(fval[1]), -def->range, def->range); in ak8975_fill_buffer()
857 data->scan.channels[2] = clamp_t(s16, le16_to_cpu(fval[2]), -def->range, def->range); in ak8975_fill_buffer()
859 iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, in ak8975_fill_buffer()
865 mutex_unlock(&data->lock); in ak8975_fill_buffer()
866 dev_err(&client->dev, "Error in reading axes block\n"); in ak8975_fill_buffer()
872 struct iio_dev *indio_dev = pf->indio_dev; in ak8975_handle_trigger()
875 iio_trigger_notify_done(indio_dev->trig); in ak8975_handle_trigger()
897 eoc_gpiod = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN); in ak8975_probe()
908 reset_gpiod = devm_gpiod_get_optional(&client->dev, in ak8975_probe()
914 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); in ak8975_probe()
916 return -ENOMEM; in ak8975_probe()
921 data->client = client; in ak8975_probe()
922 data->eoc_gpiod = eoc_gpiod; in ak8975_probe()
923 data->reset_gpiod = reset_gpiod; in ak8975_probe()
924 data->eoc_irq = 0; in ak8975_probe()
926 err = iio_read_mount_matrix(&client->dev, &data->orientation); in ak8975_probe()
931 match = device_get_match_data(&client->dev); in ak8975_probe()
934 name = dev_name(&client->dev); in ak8975_probe()
936 chipset = (enum asahi_compass_chipset)(id->driver_data); in ak8975_probe()
937 name = id->name; in ak8975_probe()
939 return -ENOSYS; in ak8975_probe()
946 dev_err(&client->dev, "AKM device type unsupported: %d\n", in ak8975_probe()
948 return -ENODEV; in ak8975_probe()
951 data->def = &ak_def_array[i]; in ak8975_probe()
954 data->vdd = devm_regulator_get(&client->dev, "vdd"); in ak8975_probe()
955 if (IS_ERR(data->vdd)) in ak8975_probe()
956 return PTR_ERR(data->vdd); in ak8975_probe()
957 data->vid = devm_regulator_get(&client->dev, "vid"); in ak8975_probe()
958 if (IS_ERR(data->vid)) in ak8975_probe()
959 return PTR_ERR(data->vid); in ak8975_probe()
965 err = ak8975_who_i_am(client, data->def->type); in ak8975_probe()
967 dev_err(&client->dev, "Unexpected device\n"); in ak8975_probe()
970 dev_dbg(&client->dev, "Asahi compass chip %s\n", name); in ak8975_probe()
972 /* Perform some basic start-of-day setup of the device. */ in ak8975_probe()
975 dev_err(&client->dev, "%s initialization fails\n", name); in ak8975_probe()
979 mutex_init(&data->lock); in ak8975_probe()
980 indio_dev->channels = ak8975_channels; in ak8975_probe()
981 indio_dev->num_channels = ARRAY_SIZE(ak8975_channels); in ak8975_probe()
982 indio_dev->info = &ak8975_info; in ak8975_probe()
983 indio_dev->available_scan_masks = ak8975_scan_masks; in ak8975_probe()
984 indio_dev->modes = INDIO_DIRECT_MODE; in ak8975_probe()
985 indio_dev->name = name; in ak8975_probe()
990 dev_err(&client->dev, "triggered buffer setup failed\n"); in ak8975_probe()
996 dev_err(&client->dev, "device register failed\n"); in ak8975_probe()
1001 pm_runtime_get_noresume(&client->dev); in ak8975_probe()
1002 pm_runtime_set_active(&client->dev); in ak8975_probe()
1003 pm_runtime_enable(&client->dev); in ak8975_probe()
1008 pm_runtime_set_autosuspend_delay(&client->dev, 50); in ak8975_probe()
1009 pm_runtime_use_autosuspend(&client->dev); in ak8975_probe()
1010 pm_runtime_put(&client->dev); in ak8975_probe()
1026 pm_runtime_get_sync(&client->dev); in ak8975_remove()
1027 pm_runtime_put_noidle(&client->dev); in ak8975_remove()
1028 pm_runtime_disable(&client->dev); in ak8975_remove()
1045 dev_err(&client->dev, "Error in setting power-down mode\n"); in ak8975_runtime_suspend()
1069 dev_err(&client->dev, "Error in setting power-down mode\n"); in ak8975_runtime_resume()
1092 { .compatible = "asahi-kasei,ak8975", },
1094 { .compatible = "asahi-kasei,ak8963", },
1096 { .compatible = "asahi-kasei,ak09911", },
1098 { .compatible = "asahi-kasei,ak09912", },
1100 { .compatible = "asahi-kasei,ak09916", },