forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/i2c/busses/i2c-powermac.c
....@@ -1,18 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 i2c Support for Apple SMU Controller
34
45 Copyright (c) 2005 Benjamin Herrenschmidt, IBM Corp.
56 <benh@kernel.crashing.org>
67
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.
168
179 */
1810
....@@ -215,23 +207,23 @@
215207 struct pmac_i2c_bus *bus,
216208 struct device_node *node)
217209 {
218
- const __be32 *prop;
219
- int len;
210
+ u32 prop;
211
+ int ret;
220212
221213 /* 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;
225217
226218 /* 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;
230222
231223 /* Now handle some devices with missing "reg" properties */
232
- if (!strcmp(node->name, "cereal"))
224
+ if (of_node_name_eq(node, "cereal"))
233225 return 0x60;
234
- else if (!strcmp(node->name, "deq"))
226
+ else if (of_node_name_eq(node, "deq"))
235227 return 0x34;
236228
237229 dev_warn(&adap->dev, "No i2c address for %pOF\n", node);
....@@ -248,8 +240,8 @@
248240
249241 strncpy(info.type, type, sizeof(info.type));
250242 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))
253245 dev_err(&adap->dev,
254246 "i2c-powermac: Failure to register missing %s\n",
255247 type);
....@@ -287,14 +279,13 @@
287279 {
288280 char tmp[16];
289281
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
298289 */
299290
300291 /* First try proper modalias */
....@@ -304,7 +295,7 @@
304295 }
305296
306297 /* Now look for known workarounds */
307
- if (!strcmp(node->name, "deq")) {
298
+ if (of_node_name_eq(node, "deq")) {
308299 /* Apple uses address 0x34 for TAS3001 and 0x35 for TAS3004 */
309300 if (addr == 0x34) {
310301 snprintf(type, type_size, "MAC,tas3001");
....@@ -324,14 +315,14 @@
324315 {
325316 struct i2c_client *newdev;
326317 struct device_node *node;
327
- bool found_onyx = 0;
318
+ bool found_onyx = false;
328319
329320 /*
330321 * In some cases we end up with the via-pmu node itself, in this
331322 * case we skip this function completely as the device-tree will
332323 * not contain anything useful.
333324 */
334
- if (!strcmp(adap->dev.of_node->name, "via-pmu"))
325
+ if (of_node_name_eq(adap->dev.of_node, "via-pmu"))
335326 return;
336327
337328 for_each_child_of_node(adap->dev.of_node, node) {
....@@ -367,8 +358,8 @@
367358 info.irq = irq_of_parse_and_map(node, 0);
368359 info.of_node = of_node_get(node);
369360
370
- newdev = i2c_new_device(adap, &info);
371
- if (!newdev) {
361
+ newdev = i2c_new_client_device(adap, &info);
362
+ if (IS_ERR(newdev)) {
372363 dev_err(&adap->dev, "i2c-powermac: Failure to register"
373364 " %pOF\n", node);
374365 of_node_put(node);
....@@ -388,9 +379,8 @@
388379 static int i2c_powermac_probe(struct platform_device *dev)
389380 {
390381 struct pmac_i2c_bus *bus = dev_get_platdata(&dev->dev);
391
- struct device_node *parent = NULL;
382
+ struct device_node *parent;
392383 struct i2c_adapter *adapter;
393
- const char *basename;
394384 int rc;
395385
396386 if (bus == NULL)
....@@ -407,23 +397,25 @@
407397 parent = of_get_parent(pmac_i2c_get_controller(bus));
408398 if (parent == NULL)
409399 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);
411404 break;
412405 case pmac_i2c_bus_pmu:
413
- basename = "pmu";
406
+ snprintf(adapter->name, sizeof(adapter->name), "pmu %d",
407
+ pmac_i2c_get_channel(bus));
414408 break;
415409 case pmac_i2c_bus_smu:
416410 /* This is not what we used to do but I'm fixing drivers at
417411 * the same time as this change
418412 */
419
- basename = "smu";
413
+ snprintf(adapter->name, sizeof(adapter->name), "smu %d",
414
+ pmac_i2c_get_channel(bus));
420415 break;
421416 default:
422417 return -EINVAL;
423418 }
424
- snprintf(adapter->name, sizeof(adapter->name), "%s %d", basename,
425
- pmac_i2c_get_channel(bus));
426
- of_node_put(parent);
427419
428420 platform_set_drvdata(dev, adapter);
429421 adapter->algo = &i2c_powermac_algorithm;