Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: magnetometer: yas530: Rename functions and registers

This is a preparation for adding the YAS537 variant.

Functions that are used only by YAS530, YAS532 and YAS533 are renamed from
yas5xx to yas530. Same for the registers.

To avoid part listing in function and registers names, the name of the first
variant is used. Where appropriate, comments were added that these functions
are used by more than one variant.

Functions that will be used by all variants including YAS537 remain in the
naming scheme yas5xx. Or YAS5XX for registers, respectively.

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/344d3b2f5e050eab79ce9962c24781486774d9fb.1660337264.git.jahau@rocketmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jakob Hauser and committed by
Jonathan Cameron
6e3bfa97 0ca09faa

+70 -56
+70 -56
drivers/iio/magnetometer/yamaha-yas530.c
··· 40 40 41 41 #include <asm/unaligned.h> 42 42 43 - /* This register map covers YAS530 and YAS532 but differs in YAS 537 and YAS539 */ 43 + /* Commonly used registers */ 44 44 #define YAS5XX_DEVICE_ID 0x80 45 - #define YAS5XX_ACTUATE_INIT_COIL 0x81 46 - #define YAS5XX_MEASURE 0x82 47 - #define YAS5XX_CONFIG 0x83 48 - #define YAS5XX_MEASURE_INTERVAL 0x84 49 - #define YAS5XX_OFFSET_X 0x85 /* [-31 .. 31] */ 50 - #define YAS5XX_OFFSET_Y1 0x86 /* [-31 .. 31] */ 51 - #define YAS5XX_OFFSET_Y2 0x87 /* [-31 .. 31] */ 52 - #define YAS5XX_TEST1 0x88 53 - #define YAS5XX_TEST2 0x89 54 - #define YAS5XX_CAL 0x90 55 45 #define YAS5XX_MEASURE_DATA 0xB0 46 + 47 + /* These registers are used by YAS530, YAS532 and YAS533 */ 48 + #define YAS530_ACTUATE_INIT_COIL 0x81 49 + #define YAS530_MEASURE 0x82 50 + #define YAS530_CONFIG 0x83 51 + #define YAS530_MEASURE_INTERVAL 0x84 52 + #define YAS530_OFFSET_X 0x85 /* [-31 .. 31] */ 53 + #define YAS530_OFFSET_Y1 0x86 /* [-31 .. 31] */ 54 + #define YAS530_OFFSET_Y2 0x87 /* [-31 .. 31] */ 55 + #define YAS530_TEST1 0x88 56 + #define YAS530_TEST2 0x89 57 + #define YAS530_CAL 0x90 56 58 57 59 /* Bits in the YAS5xx config register */ 58 60 #define YAS5XX_CONFIG_INTON BIT(0) /* Interrupt on? */ ··· 184 182 } 185 183 186 184 /** 187 - * yas5xx_measure() - Make a measure from the hardware 185 + * yas530_measure() - Make a measure from the hardware 188 186 * @yas5xx: The device state 189 187 * @t: the raw temperature measurement 190 188 * @x: the raw x axis measurement 191 189 * @y1: the y1 axis measurement 192 190 * @y2: the y2 axis measurement 193 191 * @return: 0 on success or error code 192 + * 193 + * Used by YAS530, YAS532 and YAS533. 194 194 */ 195 - static int yas5xx_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) 195 + static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2) 196 196 { 197 197 unsigned int busy; 198 198 u8 data[8]; ··· 202 198 u16 val; 203 199 204 200 mutex_lock(&yas5xx->lock); 205 - ret = regmap_write(yas5xx->map, YAS5XX_MEASURE, YAS5XX_MEASURE_START); 201 + ret = regmap_write(yas5xx->map, YAS530_MEASURE, YAS5XX_MEASURE_START); 206 202 if (ret < 0) 207 203 goto out_unlock; 208 204 ··· 268 264 return ret; 269 265 } 270 266 271 - static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis) 267 + /* Used by YAS530, YAS532 and YAS533 */ 268 + static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) 272 269 { 273 270 struct yas5xx_calibration *c = &yas5xx->calibration; 274 271 static const s32 yas532ac_coef[] = { ··· 311 306 } 312 307 313 308 /** 314 - * yas5xx_get_measure() - Measure a sample of all axis and process 309 + * yas530_get_measure() - Measure a sample of all axis and process 315 310 * @yas5xx: The device state 316 311 * @to: Temperature out 317 312 * @xo: X axis out 318 313 * @yo: Y axis out 319 314 * @zo: Z axis out 320 315 * @return: 0 on success or error code 316 + * 317 + * Used by YAS530, YAS532 and YAS533. 321 318 */ 322 - static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) 319 + static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo) 323 320 { 324 321 struct yas5xx_calibration *c = &yas5xx->calibration; 325 322 u16 t_ref, t, x, y1, y2; ··· 330 323 int ret; 331 324 332 325 /* We first get raw data that needs to be translated to [x,y,z] */ 333 - ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2); 326 + ret = yas530_measure(yas5xx, &t, &x, &y1, &y2); 334 327 if (ret) 335 328 return ret; 336 329 337 330 /* Do some linearization if available */ 338 - sx = yas5xx_linearize(yas5xx, x, 0); 339 - sy1 = yas5xx_linearize(yas5xx, y1, 1); 340 - sy2 = yas5xx_linearize(yas5xx, y2, 2); 331 + sx = yas530_linearize(yas5xx, x, 0); 332 + sy1 = yas530_linearize(yas5xx, y1, 1); 333 + sy2 = yas530_linearize(yas5xx, y2, 2); 341 334 342 335 /* Set the temperature reference value (unit: counts) */ 343 336 switch (yas5xx->devid) { ··· 453 446 case IIO_CHAN_INFO_PROCESSED: 454 447 case IIO_CHAN_INFO_RAW: 455 448 pm_runtime_get_sync(yas5xx->dev); 456 - ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z); 449 + ret = yas530_get_measure(yas5xx, &t, &x, &y, &z); 457 450 pm_runtime_mark_last_busy(yas5xx->dev); 458 451 pm_runtime_put_autosuspend(yas5xx->dev); 459 452 if (ret) ··· 512 505 int ret; 513 506 514 507 pm_runtime_get_sync(yas5xx->dev); 515 - ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z); 508 + ret = yas530_get_measure(yas5xx, &t, &x, &y, &z); 516 509 pm_runtime_mark_last_busy(yas5xx->dev); 517 510 pm_runtime_put_autosuspend(yas5xx->dev); 518 511 if (ret) { ··· 598 591 599 592 static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg) 600 593 { 601 - return reg == YAS5XX_ACTUATE_INIT_COIL || 602 - reg == YAS5XX_MEASURE || 594 + return reg == YAS530_ACTUATE_INIT_COIL || 595 + reg == YAS530_MEASURE || 603 596 (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8); 604 597 } 605 598 ··· 612 605 }; 613 606 614 607 /** 615 - * yas53x_extract_calibration() - extracts the a2-a9 and k calibration 608 + * yas530_extract_calibration() - extracts the a2-a9 and k calibration 616 609 * @data: the bitfield to use 617 610 * @c: the calibration to populate 611 + * 612 + * Used by YAS530, YAS532 and YAS533. 618 613 */ 619 - static void yas53x_extract_calibration(u8 *data, struct yas5xx_calibration *c) 614 + static void yas530_extract_calibration(u8 *data, struct yas5xx_calibration *c) 620 615 { 621 616 u64 val = get_unaligned_be64(data); 622 617 ··· 656 647 int ret; 657 648 658 649 /* Dummy read, first read is ALWAYS wrong */ 659 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 650 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 660 651 if (ret) 661 652 return ret; 662 653 663 654 /* Actual calibration readout */ 664 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 655 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 665 656 if (ret) 666 657 return ret; 667 658 dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); ··· 673 664 c->Cx = data[0] * 6 - 768; 674 665 c->Cy1 = data[1] * 6 - 768; 675 666 c->Cy2 = data[2] * 6 - 768; 676 - yas53x_extract_calibration(&data[3], c); 667 + yas530_extract_calibration(&data[3], c); 677 668 678 669 /* 679 670 * Extract linearization: ··· 704 695 int ret; 705 696 706 697 /* Dummy read, first read is ALWAYS wrong */ 707 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 698 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 708 699 if (ret) 709 700 return ret; 710 701 /* Actual calibration readout */ 711 - ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data)); 702 + ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); 712 703 if (ret) 713 704 return ret; 714 705 dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data); ··· 727 718 c->Cx = data[0] * 10 - 1280; 728 719 c->Cy1 = data[1] * 10 - 1280; 729 720 c->Cy2 = data[2] * 10 - 1280; 730 - yas53x_extract_calibration(&data[3], c); 721 + yas530_extract_calibration(&data[3], c); 731 722 /* 732 723 * Extract linearization: 733 724 * Linearization layout in the 32 bits at byte 10: ··· 750 741 return 0; 751 742 } 752 743 753 - static void yas5xx_dump_calibration(struct yas5xx *yas5xx) 744 + /* Used by YAS530, YAS532 and YAS533 */ 745 + static void yas530_dump_calibration(struct yas5xx *yas5xx) 754 746 { 755 747 struct yas5xx_calibration *c = &yas5xx->calibration; 756 748 ··· 774 764 dev_dbg(yas5xx->dev, "dck = %d\n", c->dck); 775 765 } 776 766 777 - static int yas5xx_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) 767 + /* Used by YAS530, YAS532 and YAS533 */ 768 + static int yas530_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2) 778 769 { 779 770 int ret; 780 771 781 - ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_X, ox); 772 + ret = regmap_write(yas5xx->map, YAS530_OFFSET_X, ox); 782 773 if (ret) 783 774 return ret; 784 - ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_Y1, oy1); 775 + ret = regmap_write(yas5xx->map, YAS530_OFFSET_Y1, oy1); 785 776 if (ret) 786 777 return ret; 787 - return regmap_write(yas5xx->map, YAS5XX_OFFSET_Y2, oy2); 778 + return regmap_write(yas5xx->map, YAS530_OFFSET_Y2, oy2); 788 779 } 789 780 790 - static s8 yas5xx_adjust_offset(s8 old, int bit, u16 center, u16 measure) 781 + /* Used by YAS530, YAS532 and YAS533 */ 782 + static s8 yas530_adjust_offset(s8 old, int bit, u16 center, u16 measure) 791 783 { 792 784 if (measure > center) 793 785 return old + BIT(bit); ··· 798 786 return old; 799 787 } 800 788 801 - static int yas5xx_meaure_offsets(struct yas5xx *yas5xx) 789 + /* Used by YAS530, YAS532 and YAS533 */ 790 + static int yas530_measure_offsets(struct yas5xx *yas5xx) 802 791 { 803 792 int ret; 804 793 u16 center; ··· 808 795 int i; 809 796 810 797 /* Actuate the init coil and measure offsets */ 811 - ret = regmap_write(yas5xx->map, YAS5XX_ACTUATE_INIT_COIL, 0); 798 + ret = regmap_write(yas5xx->map, YAS530_ACTUATE_INIT_COIL, 0); 812 799 if (ret) 813 800 return ret; 814 801 ··· 842 829 oy2 = 0; 843 830 844 831 for (i = 4; i >= 0; i--) { 845 - ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2); 832 + ret = yas530_set_offsets(yas5xx, ox, oy1, oy2); 846 833 if (ret) 847 834 return ret; 848 835 849 - ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2); 836 + ret = yas530_measure(yas5xx, &t, &x, &y1, &y2); 850 837 if (ret) 851 838 return ret; 852 839 dev_dbg(yas5xx->dev, "measurement %d: x=%d, y1=%d, y2=%d\n", 853 840 5-i, x, y1, y2); 854 841 855 - ox = yas5xx_adjust_offset(ox, i, center, x); 856 - oy1 = yas5xx_adjust_offset(oy1, i, center, y1); 857 - oy2 = yas5xx_adjust_offset(oy2, i, center, y2); 842 + ox = yas530_adjust_offset(ox, i, center, x); 843 + oy1 = yas530_adjust_offset(oy1, i, center, y1); 844 + oy2 = yas530_adjust_offset(oy2, i, center, y2); 858 845 } 859 846 860 847 /* Needed for calibration algorithm */ 861 848 yas5xx->hard_offsets[0] = ox; 862 849 yas5xx->hard_offsets[1] = oy1; 863 850 yas5xx->hard_offsets[2] = oy2; 864 - ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2); 851 + ret = yas530_set_offsets(yas5xx, ox, oy1, oy2); 865 852 if (ret) 866 853 return ret; 867 854 ··· 870 857 return 0; 871 858 } 872 859 873 - static int yas5xx_power_on(struct yas5xx *yas5xx) 860 + /* Used by YAS530, YAS532 and YAS533 */ 861 + static int yas530_power_on(struct yas5xx *yas5xx) 874 862 { 875 863 unsigned int val; 876 864 int ret; 877 865 878 866 /* Zero the test registers */ 879 - ret = regmap_write(yas5xx->map, YAS5XX_TEST1, 0); 867 + ret = regmap_write(yas5xx->map, YAS530_TEST1, 0); 880 868 if (ret) 881 869 return ret; 882 - ret = regmap_write(yas5xx->map, YAS5XX_TEST2, 0); 870 + ret = regmap_write(yas5xx->map, YAS530_TEST2, 0); 883 871 if (ret) 884 872 return ret; 885 873 886 874 /* Set up for no interrupts, calibrated clock divider */ 887 875 val = FIELD_PREP(YAS5XX_CONFIG_CCK_MASK, yas5xx->calibration.dck); 888 - ret = regmap_write(yas5xx->map, YAS5XX_CONFIG, val); 876 + ret = regmap_write(yas5xx->map, YAS530_CONFIG, val); 889 877 if (ret) 890 878 return ret; 891 879 892 880 /* Measure interval 0 (back-to-back?) */ 893 - return regmap_write(yas5xx->map, YAS5XX_MEASURE_INTERVAL, 0); 881 + return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); 894 882 } 895 883 896 884 static int yas5xx_probe(struct i2c_client *i2c, ··· 973 959 goto assert_reset; 974 960 } 975 961 976 - yas5xx_dump_calibration(yas5xx); 977 - ret = yas5xx_power_on(yas5xx); 962 + yas530_dump_calibration(yas5xx); 963 + ret = yas530_power_on(yas5xx); 978 964 if (ret) 979 965 goto assert_reset; 980 - ret = yas5xx_meaure_offsets(yas5xx); 966 + ret = yas530_measure_offsets(yas5xx); 981 967 if (ret) 982 968 goto assert_reset; 983 969 ··· 1076 1062 usleep_range(31000, 40000); 1077 1063 gpiod_set_value_cansleep(yas5xx->reset, 0); 1078 1064 1079 - ret = yas5xx_power_on(yas5xx); 1065 + ret = yas530_power_on(yas5xx); 1080 1066 if (ret) { 1081 1067 dev_err(dev, "cannot power on\n"); 1082 1068 goto out_reset;