diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-02-09 17:26:51 -0500 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-04-08 00:16:41 -0400 |
commit | e53e6497fc9f071734c1794c3dc08bd5f334fa7f (patch) | |
tree | f5991c0a95b48e363f0bcdc38b6e05dbd13ff5db /drivers/hwmon | |
parent | 2507abb3a7a89fa496769f2a224585e77f5fb195 (diff) |
hwmon: (pmbus/lm25066) Refactor device specific coefficients
Initialize device specific coefficients from table instead of hard-coding it
to simplify adding additional chips.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/pmbus/lm25066.c | 196 |
1 files changed, 118 insertions, 78 deletions
diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c index f9f0c93e4a3d..08267149dc63 100644 --- a/drivers/hwmon/pmbus/lm25066.c +++ b/drivers/hwmon/pmbus/lm25066.c | |||
@@ -44,6 +44,103 @@ enum chips { lm25066, lm5064, lm5066 }; | |||
44 | 44 | ||
45 | #define LM25066_DEV_SETUP_CL (1 << 4) /* Current limit */ | 45 | #define LM25066_DEV_SETUP_CL (1 << 4) /* Current limit */ |
46 | 46 | ||
47 | struct __coeff { | ||
48 | short m, b, R; | ||
49 | }; | ||
50 | |||
51 | #define PSC_CURRENT_IN_L (PSC_NUM_CLASSES) | ||
52 | #define PSC_POWER_L (PSC_NUM_CLASSES + 1) | ||
53 | |||
54 | static struct __coeff lm25066_coeff[3][PSC_NUM_CLASSES + 2] = { | ||
55 | [lm25066] = { | ||
56 | [PSC_VOLTAGE_IN] = { | ||
57 | .m = 22070, | ||
58 | .R = -2, | ||
59 | }, | ||
60 | [PSC_VOLTAGE_OUT] = { | ||
61 | .m = 22070, | ||
62 | .R = -2, | ||
63 | }, | ||
64 | [PSC_CURRENT_IN] = { | ||
65 | .m = 13661, | ||
66 | .R = -2, | ||
67 | }, | ||
68 | [PSC_CURRENT_IN_L] = { | ||
69 | .m = 6852, | ||
70 | .R = -2, | ||
71 | }, | ||
72 | [PSC_POWER] = { | ||
73 | .m = 736, | ||
74 | .R = -2, | ||
75 | }, | ||
76 | [PSC_POWER_L] = { | ||
77 | .m = 369, | ||
78 | .R = -2, | ||
79 | }, | ||
80 | [PSC_TEMPERATURE] = { | ||
81 | .m = 16, | ||
82 | }, | ||
83 | }, | ||
84 | [lm5064] = { | ||
85 | [PSC_VOLTAGE_IN] = { | ||
86 | .m = 4611, | ||
87 | .R = -2, | ||
88 | }, | ||
89 | [PSC_VOLTAGE_OUT] = { | ||
90 | .m = 4621, | ||
91 | .R = -2, | ||
92 | }, | ||
93 | [PSC_CURRENT_IN] = { | ||
94 | .m = 10742, | ||
95 | .R = -2, | ||
96 | }, | ||
97 | [PSC_CURRENT_IN_L] = { | ||
98 | .m = 5456, | ||
99 | .R = -2, | ||
100 | }, | ||
101 | [PSC_POWER] = { | ||
102 | .m = 1204, | ||
103 | .R = -3, | ||
104 | }, | ||
105 | [PSC_POWER_L] = { | ||
106 | .m = 612, | ||
107 | .R = -3, | ||
108 | }, | ||
109 | [PSC_TEMPERATURE] = { | ||
110 | .m = 16, | ||
111 | }, | ||
112 | }, | ||
113 | [lm5066] = { | ||
114 | [PSC_VOLTAGE_IN] = { | ||
115 | .m = 4587, | ||
116 | .R = -2, | ||
117 | }, | ||
118 | [PSC_VOLTAGE_OUT] = { | ||
119 | .m = 4587, | ||
120 | .R = -2, | ||
121 | }, | ||
122 | [PSC_CURRENT_IN] = { | ||
123 | .m = 10753, | ||
124 | .R = -2, | ||
125 | }, | ||
126 | [PSC_CURRENT_IN_L] = { | ||
127 | .m = 5405, | ||
128 | .R = -2, | ||
129 | }, | ||
130 | [PSC_POWER] = { | ||
131 | .m = 1204, | ||
132 | .R = -3, | ||
133 | }, | ||
134 | [PSC_POWER_L] = { | ||
135 | .m = 605, | ||
136 | .R = -3, | ||
137 | }, | ||
138 | [PSC_TEMPERATURE] = { | ||
139 | .m = 16, | ||
140 | }, | ||
141 | }, | ||
142 | }; | ||
143 | |||
47 | struct lm25066_data { | 144 | struct lm25066_data { |
48 | int id; | 145 | int id; |
49 | struct pmbus_driver_info info; | 146 | struct pmbus_driver_info info; |
@@ -162,6 +259,7 @@ static int lm25066_probe(struct i2c_client *client, | |||
162 | int config; | 259 | int config; |
163 | struct lm25066_data *data; | 260 | struct lm25066_data *data; |
164 | struct pmbus_driver_info *info; | 261 | struct pmbus_driver_info *info; |
262 | struct __coeff *coeff; | ||
165 | 263 | ||
166 | if (!i2c_check_functionality(client->adapter, | 264 | if (!i2c_check_functionality(client->adapter, |
167 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) | 265 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) |
@@ -186,9 +284,6 @@ static int lm25066_probe(struct i2c_client *client, | |||
186 | info->format[PSC_TEMPERATURE] = direct; | 284 | info->format[PSC_TEMPERATURE] = direct; |
187 | info->format[PSC_POWER] = direct; | 285 | info->format[PSC_POWER] = direct; |
188 | 286 | ||
189 | info->m[PSC_TEMPERATURE] = 16; | ||
190 | info->b[PSC_TEMPERATURE] = 0; | ||
191 | info->R[PSC_TEMPERATURE] = 0; | ||
192 | 287 | ||
193 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VMON | PMBUS_HAVE_VOUT | 288 | info->func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VMON | PMBUS_HAVE_VOUT |
194 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_PIN | PMBUS_HAVE_IIN | 289 | | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_PIN | PMBUS_HAVE_IIN |
@@ -197,81 +292,26 @@ static int lm25066_probe(struct i2c_client *client, | |||
197 | info->read_word_data = lm25066_read_word_data; | 292 | info->read_word_data = lm25066_read_word_data; |
198 | info->write_word_data = lm25066_write_word_data; | 293 | info->write_word_data = lm25066_write_word_data; |
199 | 294 | ||
200 | switch (id->driver_data) { | 295 | coeff = &lm25066_coeff[data->id][0]; |
201 | case lm25066: | 296 | info->m[PSC_TEMPERATURE] = coeff[PSC_TEMPERATURE].m; |
202 | info->m[PSC_VOLTAGE_IN] = 22070; | 297 | info->b[PSC_TEMPERATURE] = coeff[PSC_TEMPERATURE].b; |
203 | info->b[PSC_VOLTAGE_IN] = 0; | 298 | info->R[PSC_TEMPERATURE] = coeff[PSC_TEMPERATURE].R; |
204 | info->R[PSC_VOLTAGE_IN] = -2; | 299 | info->m[PSC_VOLTAGE_IN] = coeff[PSC_VOLTAGE_IN].m; |
205 | info->m[PSC_VOLTAGE_OUT] = 22070; | 300 | info->b[PSC_VOLTAGE_IN] = coeff[PSC_VOLTAGE_IN].b; |
206 | info->b[PSC_VOLTAGE_OUT] = 0; | 301 | info->R[PSC_VOLTAGE_IN] = coeff[PSC_VOLTAGE_IN].R; |
207 | info->R[PSC_VOLTAGE_OUT] = -2; | 302 | info->m[PSC_VOLTAGE_OUT] = coeff[PSC_VOLTAGE_OUT].m; |
208 | 303 | info->b[PSC_VOLTAGE_OUT] = coeff[PSC_VOLTAGE_OUT].b; | |
209 | if (config & LM25066_DEV_SETUP_CL) { | 304 | info->R[PSC_VOLTAGE_OUT] = coeff[PSC_VOLTAGE_OUT].R; |
210 | info->m[PSC_CURRENT_IN] = 6852; | 305 | info->b[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].b; |
211 | info->b[PSC_CURRENT_IN] = 0; | 306 | info->R[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].R; |
212 | info->R[PSC_CURRENT_IN] = -2; | 307 | info->b[PSC_POWER] = coeff[PSC_POWER].b; |
213 | info->m[PSC_POWER] = 369; | 308 | info->R[PSC_POWER] = coeff[PSC_POWER].R; |
214 | info->b[PSC_POWER] = 0; | 309 | if (config & LM25066_DEV_SETUP_CL) { |
215 | info->R[PSC_POWER] = -2; | 310 | info->m[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN_L].m; |
216 | } else { | 311 | info->m[PSC_POWER] = coeff[PSC_POWER_L].m; |
217 | info->m[PSC_CURRENT_IN] = 13661; | 312 | } else { |
218 | info->b[PSC_CURRENT_IN] = 0; | 313 | info->m[PSC_CURRENT_IN] = coeff[PSC_CURRENT_IN].m; |
219 | info->R[PSC_CURRENT_IN] = -2; | 314 | info->m[PSC_POWER] = coeff[PSC_POWER].m; |
220 | info->m[PSC_POWER] = 736; | ||
221 | info->b[PSC_POWER] = 0; | ||
222 | info->R[PSC_POWER] = -2; | ||
223 | } | ||
224 | break; | ||
225 | case lm5064: | ||
226 | info->m[PSC_VOLTAGE_IN] = 22075; | ||
227 | info->b[PSC_VOLTAGE_IN] = 0; | ||
228 | info->R[PSC_VOLTAGE_IN] = -2; | ||
229 | info->m[PSC_VOLTAGE_OUT] = 22075; | ||
230 | info->b[PSC_VOLTAGE_OUT] = 0; | ||
231 | info->R[PSC_VOLTAGE_OUT] = -2; | ||
232 | |||
233 | if (config & LM25066_DEV_SETUP_CL) { | ||
234 | info->m[PSC_CURRENT_IN] = 6713; | ||
235 | info->b[PSC_CURRENT_IN] = 0; | ||
236 | info->R[PSC_CURRENT_IN] = -2; | ||
237 | info->m[PSC_POWER] = 3619; | ||
238 | info->b[PSC_POWER] = 0; | ||
239 | info->R[PSC_POWER] = -3; | ||
240 | } else { | ||
241 | info->m[PSC_CURRENT_IN] = 13426; | ||
242 | info->b[PSC_CURRENT_IN] = 0; | ||
243 | info->R[PSC_CURRENT_IN] = -2; | ||
244 | info->m[PSC_POWER] = 7238; | ||
245 | info->b[PSC_POWER] = 0; | ||
246 | info->R[PSC_POWER] = -3; | ||
247 | } | ||
248 | break; | ||
249 | case lm5066: | ||
250 | info->m[PSC_VOLTAGE_IN] = 4587; | ||
251 | info->b[PSC_VOLTAGE_IN] = 0; | ||
252 | info->R[PSC_VOLTAGE_IN] = -2; | ||
253 | info->m[PSC_VOLTAGE_OUT] = 4587; | ||
254 | info->b[PSC_VOLTAGE_OUT] = 0; | ||
255 | info->R[PSC_VOLTAGE_OUT] = -2; | ||
256 | |||
257 | if (config & LM25066_DEV_SETUP_CL) { | ||
258 | info->m[PSC_CURRENT_IN] = 10753; | ||
259 | info->b[PSC_CURRENT_IN] = 0; | ||
260 | info->R[PSC_CURRENT_IN] = -2; | ||
261 | info->m[PSC_POWER] = 1204; | ||
262 | info->b[PSC_POWER] = 0; | ||
263 | info->R[PSC_POWER] = -3; | ||
264 | } else { | ||
265 | info->m[PSC_CURRENT_IN] = 5405; | ||
266 | info->b[PSC_CURRENT_IN] = 0; | ||
267 | info->R[PSC_CURRENT_IN] = -2; | ||
268 | info->m[PSC_POWER] = 605; | ||
269 | info->b[PSC_POWER] = 0; | ||
270 | info->R[PSC_POWER] = -3; | ||
271 | } | ||
272 | break; | ||
273 | default: | ||
274 | return -ENODEV; | ||
275 | } | 315 | } |
276 | 316 | ||
277 | return pmbus_do_probe(client, id, info); | 317 | return pmbus_do_probe(client, id, info); |