struct regmap *regmap16;
 };
 
+static struct ti_eqep_cnt *ti_eqep_count_from_counter(struct counter_device *counter)
+{
+       return container_of(counter, struct ti_eqep_cnt, counter);
+}
+
 static int ti_eqep_count_read(struct counter_device *counter,
                              struct counter_count *count, u64 *val)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
        u32 cnt;
 
        regmap_read(priv->regmap32, QPOSCNT, &cnt);
 static int ti_eqep_count_write(struct counter_device *counter,
                               struct counter_count *count, u64 val)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
        u32 max;
 
        regmap_read(priv->regmap32, QPOSMAX, &max);
                                 struct counter_count *count,
                                 enum counter_function *function)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
        u32 qdecctl;
 
        regmap_read(priv->regmap16, QDECCTL, &qdecctl);
                                  struct counter_count *count,
                                  enum counter_function function)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
        enum ti_eqep_count_func qsrc;
 
        switch (function) {
                               struct counter_synapse *synapse,
                               enum counter_synapse_action *action)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
        enum counter_function function;
        u32 qdecctl;
        int err;
                                         struct counter_count *count,
                                         u64 *ceiling)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
        u32 qposmax;
 
        regmap_read(priv->regmap32, QPOSMAX, &qposmax);
                                          struct counter_count *count,
                                          u64 ceiling)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
 
        if (ceiling != (u32)ceiling)
                return -ERANGE;
 static int ti_eqep_position_enable_read(struct counter_device *counter,
                                        struct counter_count *count, u8 *enable)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
        u32 qepctl;
 
        regmap_read(priv->regmap16, QEPCTL, &qepctl);
 static int ti_eqep_position_enable_write(struct counter_device *counter,
                                         struct counter_count *count, u8 enable)
 {
-       struct ti_eqep_cnt *priv = counter->priv;
+       struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter);
 
        regmap_write_bits(priv->regmap16, QEPCTL, QEPCTL_PHEN, enable ? -1 : 0);