Commit 0d2cff8b673daf13c2bb1b6b87cb25d45bc77995

Authored by Mark Brown

Merge remote-tracking branch 'regulator/topic/max1586' into regulator-next

Showing 1 changed file Side-by-side Diff

drivers/regulator/max1586.c
... ... @@ -44,6 +44,9 @@
44 44 unsigned int min_uV;
45 45 unsigned int max_uV;
46 46  
  47 + unsigned int v3_curr_sel;
  48 + unsigned int v6_curr_sel;
  49 +
47 50 struct regulator_dev *rdev[0];
48 51 };
49 52  
50 53  
51 54  
52 55  
53 56  
54 57  
55 58  
... ... @@ -63,31 +66,60 @@
63 66 * R24 and R25=100kOhm as described in the data sheet.
64 67 * The gain is approximately: 1 + R24/R25 + R24/185.5kOhm
65 68 */
  69 +static int max1586_v3_get_voltage_sel(struct regulator_dev *rdev)
  70 +{
  71 + struct max1586_data *max1586 = rdev_get_drvdata(rdev);
  72 +
  73 + return max1586->v3_curr_sel;
  74 +}
  75 +
66 76 static int max1586_v3_set_voltage_sel(struct regulator_dev *rdev,
67 77 unsigned selector)
68 78 {
69 79 struct max1586_data *max1586 = rdev_get_drvdata(rdev);
70 80 struct i2c_client *client = max1586->client;
  81 + int ret;
71 82 u8 v3_prog;
72 83  
73 84 dev_dbg(&client->dev, "changing voltage v3 to %dmv\n",
74 85 regulator_list_voltage_linear(rdev, selector) / 1000);
75 86  
76 87 v3_prog = I2C_V3_SELECT | (u8) selector;
77   - return i2c_smbus_write_byte(client, v3_prog);
  88 + ret = i2c_smbus_write_byte(client, v3_prog);
  89 + if (ret)
  90 + return ret;
  91 +
  92 + max1586->v3_curr_sel = selector;
  93 +
  94 + return 0;
78 95 }
79 96  
  97 +static int max1586_v6_get_voltage_sel(struct regulator_dev *rdev)
  98 +{
  99 + struct max1586_data *max1586 = rdev_get_drvdata(rdev);
  100 +
  101 + return max1586->v6_curr_sel;
  102 +}
  103 +
80 104 static int max1586_v6_set_voltage_sel(struct regulator_dev *rdev,
81 105 unsigned int selector)
82 106 {
83   - struct i2c_client *client = rdev_get_drvdata(rdev);
  107 + struct max1586_data *max1586 = rdev_get_drvdata(rdev);
  108 + struct i2c_client *client = max1586->client;
84 109 u8 v6_prog;
  110 + int ret;
85 111  
86 112 dev_dbg(&client->dev, "changing voltage v6 to %dmv\n",
87 113 rdev->desc->volt_table[selector] / 1000);
88 114  
89 115 v6_prog = I2C_V6_SELECT | (u8) selector;
90   - return i2c_smbus_write_byte(client, v6_prog);
  116 + ret = i2c_smbus_write_byte(client, v6_prog);
  117 + if (ret)
  118 + return ret;
  119 +
  120 + max1586->v6_curr_sel = selector;
  121 +
  122 + return 0;
91 123 }
92 124  
93 125 /*
94 126  
... ... @@ -95,12 +127,14 @@
95 127 * the set up value.
96 128 */
97 129 static struct regulator_ops max1586_v3_ops = {
  130 + .get_voltage_sel = max1586_v3_get_voltage_sel,
98 131 .set_voltage_sel = max1586_v3_set_voltage_sel,
99 132 .list_voltage = regulator_list_voltage_linear,
100 133 .map_voltage = regulator_map_voltage_linear,
101 134 };
102 135  
103 136 static struct regulator_ops max1586_v6_ops = {
  137 + .get_voltage_sel = max1586_v6_get_voltage_sel,
104 138 .set_voltage_sel = max1586_v6_set_voltage_sel,
105 139 .list_voltage = regulator_list_voltage_table,
106 140 };
... ... @@ -147,6 +181,10 @@
147 181  
148 182 max1586->min_uV = MAX1586_V3_MIN_UV / 1000 * pdata->v3_gain / 1000;
149 183 max1586->max_uV = MAX1586_V3_MAX_UV / 1000 * pdata->v3_gain / 1000;
  184 +
  185 + /* Set curr_sel to default voltage on power-up */
  186 + max1586->v3_curr_sel = 24; /* 1.3V */
  187 + max1586->v6_curr_sel = 0;
150 188  
151 189 rdev = max1586->rdev;
152 190 for (i = 0; i < pdata->num_subdevs && i <= MAX1586_V6; i++) {