#include <asm/unaligned.h>
 
-/* This register map covers YAS530 and YAS532 but differs in YAS 537 and YAS539 */
+/* Commonly used registers */
 #define YAS5XX_DEVICE_ID               0x80
-#define YAS5XX_ACTUATE_INIT_COIL       0x81
-#define YAS5XX_MEASURE                 0x82
-#define YAS5XX_CONFIG                  0x83
-#define YAS5XX_MEASURE_INTERVAL                0x84
-#define YAS5XX_OFFSET_X                        0x85 /* [-31 .. 31] */
-#define YAS5XX_OFFSET_Y1               0x86 /* [-31 .. 31] */
-#define YAS5XX_OFFSET_Y2               0x87 /* [-31 .. 31] */
-#define YAS5XX_TEST1                   0x88
-#define YAS5XX_TEST2                   0x89
-#define YAS5XX_CAL                     0x90
 #define YAS5XX_MEASURE_DATA            0xB0
 
+/* These registers are used by YAS530, YAS532 and YAS533 */
+#define YAS530_ACTUATE_INIT_COIL       0x81
+#define YAS530_MEASURE                 0x82
+#define YAS530_CONFIG                  0x83
+#define YAS530_MEASURE_INTERVAL                0x84
+#define YAS530_OFFSET_X                        0x85 /* [-31 .. 31] */
+#define YAS530_OFFSET_Y1               0x86 /* [-31 .. 31] */
+#define YAS530_OFFSET_Y2               0x87 /* [-31 .. 31] */
+#define YAS530_TEST1                   0x88
+#define YAS530_TEST2                   0x89
+#define YAS530_CAL                     0x90
+
 /* Bits in the YAS5xx config register */
 #define YAS5XX_CONFIG_INTON            BIT(0) /* Interrupt on? */
 #define YAS5XX_CONFIG_INTHACT          BIT(1) /* Interrupt active high? */
 }
 
 /**
- * yas5xx_measure() - Make a measure from the hardware
+ * yas530_measure() - Make a measure from the hardware
  * @yas5xx: The device state
  * @t: the raw temperature measurement
  * @x: the raw x axis measurement
  * @y1: the y1 axis measurement
  * @y2: the y2 axis measurement
  * @return: 0 on success or error code
+ *
+ * Used by YAS530, YAS532 and YAS533.
  */
-static int yas5xx_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2)
+static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2)
 {
        unsigned int busy;
        u8 data[8];
        u16 val;
 
        mutex_lock(&yas5xx->lock);
-       ret = regmap_write(yas5xx->map, YAS5XX_MEASURE, YAS5XX_MEASURE_START);
+       ret = regmap_write(yas5xx->map, YAS530_MEASURE, YAS5XX_MEASURE_START);
        if (ret < 0)
                goto out_unlock;
 
        return ret;
 }
 
-static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis)
+/* Used by YAS530, YAS532 and YAS533 */
+static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis)
 {
        struct yas5xx_calibration *c = &yas5xx->calibration;
        static const s32 yas532ac_coef[] = {
 }
 
 /**
- * yas5xx_get_measure() - Measure a sample of all axis and process
+ * yas530_get_measure() - Measure a sample of all axis and process
  * @yas5xx: The device state
  * @to: Temperature out
  * @xo: X axis out
  * @yo: Y axis out
  * @zo: Z axis out
  * @return: 0 on success or error code
+ *
+ * Used by YAS530, YAS532 and YAS533.
  */
-static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo)
+static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo)
 {
        struct yas5xx_calibration *c = &yas5xx->calibration;
        u16 t_ref, t, x, y1, y2;
        int ret;
 
        /* We first get raw data that needs to be translated to [x,y,z] */
-       ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2);
+       ret = yas530_measure(yas5xx, &t, &x, &y1, &y2);
        if (ret)
                return ret;
 
        /* Do some linearization if available */
-       sx = yas5xx_linearize(yas5xx, x, 0);
-       sy1 = yas5xx_linearize(yas5xx, y1, 1);
-       sy2 = yas5xx_linearize(yas5xx, y2, 2);
+       sx = yas530_linearize(yas5xx, x, 0);
+       sy1 = yas530_linearize(yas5xx, y1, 1);
+       sy2 = yas530_linearize(yas5xx, y2, 2);
 
        /* Set the temperature reference value (unit: counts) */
        switch (yas5xx->devid) {
        case IIO_CHAN_INFO_PROCESSED:
        case IIO_CHAN_INFO_RAW:
                pm_runtime_get_sync(yas5xx->dev);
-               ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z);
+               ret = yas530_get_measure(yas5xx, &t, &x, &y, &z);
                pm_runtime_mark_last_busy(yas5xx->dev);
                pm_runtime_put_autosuspend(yas5xx->dev);
                if (ret)
        int ret;
 
        pm_runtime_get_sync(yas5xx->dev);
-       ret = yas5xx_get_measure(yas5xx, &t, &x, &y, &z);
+       ret = yas530_get_measure(yas5xx, &t, &x, &y, &z);
        pm_runtime_mark_last_busy(yas5xx->dev);
        pm_runtime_put_autosuspend(yas5xx->dev);
        if (ret) {
 
 static bool yas5xx_volatile_reg(struct device *dev, unsigned int reg)
 {
-       return reg == YAS5XX_ACTUATE_INIT_COIL ||
-               reg == YAS5XX_MEASURE ||
+       return reg == YAS530_ACTUATE_INIT_COIL ||
+               reg == YAS530_MEASURE ||
                (reg >= YAS5XX_MEASURE_DATA && reg < YAS5XX_MEASURE_DATA + 8);
 }
 
 };
 
 /**
- * yas53x_extract_calibration() - extracts the a2-a9 and k calibration
+ * yas530_extract_calibration() - extracts the a2-a9 and k calibration
  * @data: the bitfield to use
  * @c: the calibration to populate
+ *
+ * Used by YAS530, YAS532 and YAS533.
  */
-static void yas53x_extract_calibration(u8 *data, struct yas5xx_calibration *c)
+static void yas530_extract_calibration(u8 *data, struct yas5xx_calibration *c)
 {
        u64 val = get_unaligned_be64(data);
 
        int ret;
 
        /* Dummy read, first read is ALWAYS wrong */
-       ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data));
+       ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
        if (ret)
                return ret;
 
        /* Actual calibration readout */
-       ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data));
+       ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
        if (ret)
                return ret;
        dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data);
        c->Cx = data[0] * 6 - 768;
        c->Cy1 = data[1] * 6 - 768;
        c->Cy2 = data[2] * 6 - 768;
-       yas53x_extract_calibration(&data[3], c);
+       yas530_extract_calibration(&data[3], c);
 
        /*
         * Extract linearization:
        int ret;
 
        /* Dummy read, first read is ALWAYS wrong */
-       ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data));
+       ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
        if (ret)
                return ret;
        /* Actual calibration readout */
-       ret = regmap_bulk_read(yas5xx->map, YAS5XX_CAL, data, sizeof(data));
+       ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
        if (ret)
                return ret;
        dev_dbg(yas5xx->dev, "calibration data: %*ph\n", 14, data);
        c->Cx = data[0] * 10 - 1280;
        c->Cy1 = data[1] * 10 - 1280;
        c->Cy2 = data[2] * 10 - 1280;
-       yas53x_extract_calibration(&data[3], c);
+       yas530_extract_calibration(&data[3], c);
        /*
         * Extract linearization:
         * Linearization layout in the 32 bits at byte 10:
        return 0;
 }
 
-static void yas5xx_dump_calibration(struct yas5xx *yas5xx)
+/* Used by YAS530, YAS532 and YAS533 */
+static void yas530_dump_calibration(struct yas5xx *yas5xx)
 {
        struct yas5xx_calibration *c = &yas5xx->calibration;
 
        dev_dbg(yas5xx->dev, "dck = %d\n", c->dck);
 }
 
-static int yas5xx_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2)
+/* Used by YAS530, YAS532 and YAS533 */
+static int yas530_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2)
 {
        int ret;
 
-       ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_X, ox);
+       ret = regmap_write(yas5xx->map, YAS530_OFFSET_X, ox);
        if (ret)
                return ret;
-       ret = regmap_write(yas5xx->map, YAS5XX_OFFSET_Y1, oy1);
+       ret = regmap_write(yas5xx->map, YAS530_OFFSET_Y1, oy1);
        if (ret)
                return ret;
-       return regmap_write(yas5xx->map, YAS5XX_OFFSET_Y2, oy2);
+       return regmap_write(yas5xx->map, YAS530_OFFSET_Y2, oy2);
 }
 
-static s8 yas5xx_adjust_offset(s8 old, int bit, u16 center, u16 measure)
+/* Used by YAS530, YAS532 and YAS533 */
+static s8 yas530_adjust_offset(s8 old, int bit, u16 center, u16 measure)
 {
        if (measure > center)
                return old + BIT(bit);
        return old;
 }
 
-static int yas5xx_meaure_offsets(struct yas5xx *yas5xx)
+/* Used by YAS530, YAS532 and YAS533 */
+static int yas530_measure_offsets(struct yas5xx *yas5xx)
 {
        int ret;
        u16 center;
        int i;
 
        /* Actuate the init coil and measure offsets */
-       ret = regmap_write(yas5xx->map, YAS5XX_ACTUATE_INIT_COIL, 0);
+       ret = regmap_write(yas5xx->map, YAS530_ACTUATE_INIT_COIL, 0);
        if (ret)
                return ret;
 
        oy2 = 0;
 
        for (i = 4; i >= 0; i--) {
-               ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2);
+               ret = yas530_set_offsets(yas5xx, ox, oy1, oy2);
                if (ret)
                        return ret;
 
-               ret = yas5xx_measure(yas5xx, &t, &x, &y1, &y2);
+               ret = yas530_measure(yas5xx, &t, &x, &y1, &y2);
                if (ret)
                        return ret;
                dev_dbg(yas5xx->dev, "measurement %d: x=%d, y1=%d, y2=%d\n",
                        5-i, x, y1, y2);
 
-               ox = yas5xx_adjust_offset(ox, i, center, x);
-               oy1 = yas5xx_adjust_offset(oy1, i, center, y1);
-               oy2 = yas5xx_adjust_offset(oy2, i, center, y2);
+               ox = yas530_adjust_offset(ox, i, center, x);
+               oy1 = yas530_adjust_offset(oy1, i, center, y1);
+               oy2 = yas530_adjust_offset(oy2, i, center, y2);
        }
 
        /* Needed for calibration algorithm */
        yas5xx->hard_offsets[0] = ox;
        yas5xx->hard_offsets[1] = oy1;
        yas5xx->hard_offsets[2] = oy2;
-       ret = yas5xx_set_offsets(yas5xx, ox, oy1, oy2);
+       ret = yas530_set_offsets(yas5xx, ox, oy1, oy2);
        if (ret)
                return ret;
 
        return 0;
 }
 
-static int yas5xx_power_on(struct yas5xx *yas5xx)
+/* Used by YAS530, YAS532 and YAS533 */
+static int yas530_power_on(struct yas5xx *yas5xx)
 {
        unsigned int val;
        int ret;
 
        /* Zero the test registers */
-       ret = regmap_write(yas5xx->map, YAS5XX_TEST1, 0);
+       ret = regmap_write(yas5xx->map, YAS530_TEST1, 0);
        if (ret)
                return ret;
-       ret = regmap_write(yas5xx->map, YAS5XX_TEST2, 0);
+       ret = regmap_write(yas5xx->map, YAS530_TEST2, 0);
        if (ret)
                return ret;
 
        /* Set up for no interrupts, calibrated clock divider */
        val = FIELD_PREP(YAS5XX_CONFIG_CCK_MASK, yas5xx->calibration.dck);
-       ret = regmap_write(yas5xx->map, YAS5XX_CONFIG, val);
+       ret = regmap_write(yas5xx->map, YAS530_CONFIG, val);
        if (ret)
                return ret;
 
        /* Measure interval 0 (back-to-back?)  */
-       return regmap_write(yas5xx->map, YAS5XX_MEASURE_INTERVAL, 0);
+       return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0);
 }
 
 static int yas5xx_probe(struct i2c_client *i2c,
                goto assert_reset;
        }
 
-       yas5xx_dump_calibration(yas5xx);
-       ret = yas5xx_power_on(yas5xx);
+       yas530_dump_calibration(yas5xx);
+       ret = yas530_power_on(yas5xx);
        if (ret)
                goto assert_reset;
-       ret = yas5xx_meaure_offsets(yas5xx);
+       ret = yas530_measure_offsets(yas5xx);
        if (ret)
                goto assert_reset;
 
        usleep_range(31000, 40000);
        gpiod_set_value_cansleep(yas5xx->reset, 0);
 
-       ret = yas5xx_power_on(yas5xx);
+       ret = yas530_power_on(yas5xx);
        if (ret) {
                dev_err(dev, "cannot power on\n");
                goto out_reset;