Merge remote-tracking branch 'regulator/topic/qcom-spmi' into regulator-next
authorMark Brown <broonie@kernel.org>
Fri, 10 Nov 2017 21:33:22 +0000 (21:33 +0000)
committerMark Brown <broonie@kernel.org>
Fri, 10 Nov 2017 21:33:22 +0000 (21:33 +0000)
1  2 
drivers/regulator/qcom_spmi-regulator.c

index c372b244f3dac03ea771929c1b9aeb5e87fbffb1,9f8eb5dd2a4eba445e0c90b939e9d4f850fcd66a..0241ada47d04bce724e3baebfa7a88dd520cca90
@@@ -593,20 -593,13 +593,20 @@@ static int spmi_sw_selector_to_hw(struc
                                  u8 *voltage_sel)
  {
        const struct spmi_voltage_range *range, *end;
 +      unsigned offset;
  
        range = vreg->set_points->range;
        end = range + vreg->set_points->count;
  
        for (; range < end; range++) {
                if (selector < range->n_voltages) {
 -                      *voltage_sel = selector;
 +                      /*
 +                       * hardware selectors between set point min and real
 +                       * min are invalid so we ignore them
 +                       */
 +                      offset = range->set_point_min_uV - range->min_uV;
 +                      offset /= range->step_uV;
 +                      *voltage_sel = selector + offset;
                        *range_sel = range->range_sel;
                        return 0;
                }
  static int spmi_hw_selector_to_sw(struct spmi_regulator *vreg, u8 hw_sel,
                                  const struct spmi_voltage_range *range)
  {
 -      int sw_sel = hw_sel;
 +      unsigned sw_sel = 0;
 +      unsigned offset, max_hw_sel;
        const struct spmi_voltage_range *r = vreg->set_points->range;
 -
 -      while (r != range) {
 +      const struct spmi_voltage_range *end = r + vreg->set_points->count;
 +
 +      for (; r < end; r++) {
 +              if (r == range && range->n_voltages) {
 +                      /*
 +                       * hardware selectors between set point min and real
 +                       * min and between set point max and real max are
 +                       * invalid so we return an error if they're
 +                       * programmed into the hardware
 +                       */
 +                      offset = range->set_point_min_uV - range->min_uV;
 +                      offset /= range->step_uV;
 +                      if (hw_sel < offset)
 +                              return -EINVAL;
 +
 +                      max_hw_sel = range->set_point_max_uV - range->min_uV;
 +                      max_hw_sel /= range->step_uV;
 +                      if (hw_sel > max_hw_sel)
 +                              return -EINVAL;
 +
 +                      return sw_sel + hw_sel - offset;
 +              }
                sw_sel += r->n_voltages;
 -              r++;
        }
  
 -      return sw_sel;
 +      return -EINVAL;
  }
  
  static const struct spmi_voltage_range *
@@@ -1646,11 -1619,20 +1646,20 @@@ static const struct spmi_regulator_dat
        { }
  };
  
+ static const struct spmi_regulator_data pmi8994_regulators[] = {
+       { "s1", 0x1400, "vdd_s1", },
+       { "s2", 0x1700, "vdd_s2", },
+       { "s3", 0x1a00, "vdd_s3", },
+       { "l1", 0x4000, "vdd_l1", },
+         { }
+ };
  static const struct of_device_id qcom_spmi_regulator_match[] = {
        { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators },
        { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators },
        { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators },
        { .compatible = "qcom,pm8994-regulators", .data = &pm8994_regulators },
+       { .compatible = "qcom,pmi8994-regulators", .data = &pmi8994_regulators },
        { }
  };
  MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match);