.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | i2c Support for Apple SMU Controller |
---|
3 | 4 | |
---|
4 | 5 | Copyright (c) 2005 Benjamin Herrenschmidt, IBM Corp. |
---|
5 | 6 | <benh@kernel.crashing.org> |
---|
6 | 7 | |
---|
7 | | - This program is free software; you can redistribute it and/or modify |
---|
8 | | - it under the terms of the GNU General Public License as published by |
---|
9 | | - the Free Software Foundation; either version 2 of the License, or |
---|
10 | | - (at your option) any later version. |
---|
11 | | - |
---|
12 | | - This program is distributed in the hope that it will be useful, |
---|
13 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - GNU General Public License for more details. |
---|
16 | 8 | |
---|
17 | 9 | */ |
---|
18 | 10 | |
---|
.. | .. |
---|
215 | 207 | struct pmac_i2c_bus *bus, |
---|
216 | 208 | struct device_node *node) |
---|
217 | 209 | { |
---|
218 | | - const __be32 *prop; |
---|
219 | | - int len; |
---|
| 210 | + u32 prop; |
---|
| 211 | + int ret; |
---|
220 | 212 | |
---|
221 | 213 | /* First check for valid "reg" */ |
---|
222 | | - prop = of_get_property(node, "reg", &len); |
---|
223 | | - if (prop && (len >= sizeof(int))) |
---|
224 | | - return (be32_to_cpup(prop) & 0xff) >> 1; |
---|
| 214 | + ret = of_property_read_u32(node, "reg", &prop); |
---|
| 215 | + if (ret == 0) |
---|
| 216 | + return (prop & 0xff) >> 1; |
---|
225 | 217 | |
---|
226 | 218 | /* Then check old-style "i2c-address" */ |
---|
227 | | - prop = of_get_property(node, "i2c-address", &len); |
---|
228 | | - if (prop && (len >= sizeof(int))) |
---|
229 | | - return (be32_to_cpup(prop) & 0xff) >> 1; |
---|
| 219 | + ret = of_property_read_u32(node, "i2c-address", &prop); |
---|
| 220 | + if (ret == 0) |
---|
| 221 | + return (prop & 0xff) >> 1; |
---|
230 | 222 | |
---|
231 | 223 | /* Now handle some devices with missing "reg" properties */ |
---|
232 | | - if (!strcmp(node->name, "cereal")) |
---|
| 224 | + if (of_node_name_eq(node, "cereal")) |
---|
233 | 225 | return 0x60; |
---|
234 | | - else if (!strcmp(node->name, "deq")) |
---|
| 226 | + else if (of_node_name_eq(node, "deq")) |
---|
235 | 227 | return 0x34; |
---|
236 | 228 | |
---|
237 | 229 | dev_warn(&adap->dev, "No i2c address for %pOF\n", node); |
---|
.. | .. |
---|
248 | 240 | |
---|
249 | 241 | strncpy(info.type, type, sizeof(info.type)); |
---|
250 | 242 | info.addr = addr; |
---|
251 | | - newdev = i2c_new_device(adap, &info); |
---|
252 | | - if (!newdev) |
---|
| 243 | + newdev = i2c_new_client_device(adap, &info); |
---|
| 244 | + if (IS_ERR(newdev)) |
---|
253 | 245 | dev_err(&adap->dev, |
---|
254 | 246 | "i2c-powermac: Failure to register missing %s\n", |
---|
255 | 247 | type); |
---|
.. | .. |
---|
287 | 279 | { |
---|
288 | 280 | char tmp[16]; |
---|
289 | 281 | |
---|
290 | | - /* Note: we to _NOT_ want the standard |
---|
291 | | - * i2c drivers to match with any of our powermac stuff |
---|
292 | | - * unless they have been specifically modified to handle |
---|
293 | | - * it on a case by case basis. For example, for thermal |
---|
294 | | - * control, things like lm75 etc... shall match with their |
---|
295 | | - * corresponding windfarm drivers, _NOT_ the generic ones, |
---|
296 | | - * so we force a prefix of AAPL, onto the modalias to |
---|
297 | | - * make that happen |
---|
| 282 | + /* |
---|
| 283 | + * Note: we do _NOT_ want the standard i2c drivers to match with any of |
---|
| 284 | + * our powermac stuff unless they have been specifically modified to |
---|
| 285 | + * handle it on a case by case basis. For example, for thermal control, |
---|
| 286 | + * things like lm75 etc... shall match with their corresponding |
---|
| 287 | + * windfarm drivers, _NOT_ the generic ones, so we force a prefix of |
---|
| 288 | + * 'MAC', onto the modalias to make that happen |
---|
298 | 289 | */ |
---|
299 | 290 | |
---|
300 | 291 | /* First try proper modalias */ |
---|
.. | .. |
---|
304 | 295 | } |
---|
305 | 296 | |
---|
306 | 297 | /* Now look for known workarounds */ |
---|
307 | | - if (!strcmp(node->name, "deq")) { |
---|
| 298 | + if (of_node_name_eq(node, "deq")) { |
---|
308 | 299 | /* Apple uses address 0x34 for TAS3001 and 0x35 for TAS3004 */ |
---|
309 | 300 | if (addr == 0x34) { |
---|
310 | 301 | snprintf(type, type_size, "MAC,tas3001"); |
---|
.. | .. |
---|
324 | 315 | { |
---|
325 | 316 | struct i2c_client *newdev; |
---|
326 | 317 | struct device_node *node; |
---|
327 | | - bool found_onyx = 0; |
---|
| 318 | + bool found_onyx = false; |
---|
328 | 319 | |
---|
329 | 320 | /* |
---|
330 | 321 | * In some cases we end up with the via-pmu node itself, in this |
---|
331 | 322 | * case we skip this function completely as the device-tree will |
---|
332 | 323 | * not contain anything useful. |
---|
333 | 324 | */ |
---|
334 | | - if (!strcmp(adap->dev.of_node->name, "via-pmu")) |
---|
| 325 | + if (of_node_name_eq(adap->dev.of_node, "via-pmu")) |
---|
335 | 326 | return; |
---|
336 | 327 | |
---|
337 | 328 | for_each_child_of_node(adap->dev.of_node, node) { |
---|
.. | .. |
---|
367 | 358 | info.irq = irq_of_parse_and_map(node, 0); |
---|
368 | 359 | info.of_node = of_node_get(node); |
---|
369 | 360 | |
---|
370 | | - newdev = i2c_new_device(adap, &info); |
---|
371 | | - if (!newdev) { |
---|
| 361 | + newdev = i2c_new_client_device(adap, &info); |
---|
| 362 | + if (IS_ERR(newdev)) { |
---|
372 | 363 | dev_err(&adap->dev, "i2c-powermac: Failure to register" |
---|
373 | 364 | " %pOF\n", node); |
---|
374 | 365 | of_node_put(node); |
---|
.. | .. |
---|
388 | 379 | static int i2c_powermac_probe(struct platform_device *dev) |
---|
389 | 380 | { |
---|
390 | 381 | struct pmac_i2c_bus *bus = dev_get_platdata(&dev->dev); |
---|
391 | | - struct device_node *parent = NULL; |
---|
| 382 | + struct device_node *parent; |
---|
392 | 383 | struct i2c_adapter *adapter; |
---|
393 | | - const char *basename; |
---|
394 | 384 | int rc; |
---|
395 | 385 | |
---|
396 | 386 | if (bus == NULL) |
---|
.. | .. |
---|
407 | 397 | parent = of_get_parent(pmac_i2c_get_controller(bus)); |
---|
408 | 398 | if (parent == NULL) |
---|
409 | 399 | return -EINVAL; |
---|
410 | | - basename = parent->name; |
---|
| 400 | + snprintf(adapter->name, sizeof(adapter->name), "%pOFn %d", |
---|
| 401 | + parent, |
---|
| 402 | + pmac_i2c_get_channel(bus)); |
---|
| 403 | + of_node_put(parent); |
---|
411 | 404 | break; |
---|
412 | 405 | case pmac_i2c_bus_pmu: |
---|
413 | | - basename = "pmu"; |
---|
| 406 | + snprintf(adapter->name, sizeof(adapter->name), "pmu %d", |
---|
| 407 | + pmac_i2c_get_channel(bus)); |
---|
414 | 408 | break; |
---|
415 | 409 | case pmac_i2c_bus_smu: |
---|
416 | 410 | /* This is not what we used to do but I'm fixing drivers at |
---|
417 | 411 | * the same time as this change |
---|
418 | 412 | */ |
---|
419 | | - basename = "smu"; |
---|
| 413 | + snprintf(adapter->name, sizeof(adapter->name), "smu %d", |
---|
| 414 | + pmac_i2c_get_channel(bus)); |
---|
420 | 415 | break; |
---|
421 | 416 | default: |
---|
422 | 417 | return -EINVAL; |
---|
423 | 418 | } |
---|
424 | | - snprintf(adapter->name, sizeof(adapter->name), "%s %d", basename, |
---|
425 | | - pmac_i2c_get_channel(bus)); |
---|
426 | | - of_node_put(parent); |
---|
427 | 419 | |
---|
428 | 420 | platform_set_drvdata(dev, adapter); |
---|
429 | 421 | adapter->algo = &i2c_powermac_algorithm; |
---|