hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/i2c/busses/i2c-iop3xx.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* ------------------------------------------------------------------------- */
23 /* i2c-iop3xx.c i2c driver algorithms for Intel XScale IOP3xx & IXP46x */
34 /* ------------------------------------------------------------------------- */
....@@ -23,10 +24,6 @@
2324 *
2425 * - writing to slave address causes latchup on iop331.
2526 * fix: driver refuses to address self.
26
- *
27
- * This program is free software; you can redistribute it and/or modify
28
- * it under the terms of the GNU General Public License as published by
29
- * the Free Software Foundation, version 2.
3027 */
3128
3229 #include <linux/interrupt.h>
....@@ -38,7 +35,7 @@
3835 #include <linux/platform_device.h>
3936 #include <linux/i2c.h>
4037 #include <linux/io.h>
41
-#include <linux/gpio.h>
38
+#include <linux/gpio/consumer.h>
4239
4340 #include "i2c-iop3xx.h"
4441
....@@ -71,17 +68,16 @@
7168
7269 /*
7370 * Every time unit enable is asserted, GPOD needs to be cleared
74
- * on IOP3XX to avoid data corruption on the bus.
71
+ * on IOP3XX to avoid data corruption on the bus. We use the
72
+ * gpiod_set_raw_value() to make sure the 0 hits the hardware
73
+ * GPOD register. These descriptors are only passed along to
74
+ * the device if this is necessary.
7575 */
76
-#if defined(CONFIG_ARCH_IOP32X) || defined(CONFIG_ARCH_IOP33X)
77
- if (iop3xx_adap->id == 0) {
78
- gpio_set_value(7, 0);
79
- gpio_set_value(6, 0);
80
- } else {
81
- gpio_set_value(5, 0);
82
- gpio_set_value(4, 0);
83
- }
84
-#endif
76
+ if (iop3xx_adap->gpio_scl)
77
+ gpiod_set_raw_value(iop3xx_adap->gpio_scl, 0);
78
+ if (iop3xx_adap->gpio_sda)
79
+ gpiod_set_raw_value(iop3xx_adap->gpio_sda, 0);
80
+
8581 /* NB SR bits not same position as CR IE bits :-( */
8682 iop3xx_adap->SR_enabled =
8783 IOP3XX_ISR_ALD | IOP3XX_ISR_BERRD |
....@@ -434,6 +430,21 @@
434430 goto free_adapter;
435431 }
436432
433
+ adapter_data->gpio_scl = devm_gpiod_get_optional(&pdev->dev,
434
+ "scl",
435
+ GPIOD_ASIS);
436
+ if (IS_ERR(adapter_data->gpio_scl)) {
437
+ ret = PTR_ERR(adapter_data->gpio_scl);
438
+ goto free_both;
439
+ }
440
+ adapter_data->gpio_sda = devm_gpiod_get_optional(&pdev->dev,
441
+ "sda",
442
+ GPIOD_ASIS);
443
+ if (IS_ERR(adapter_data->gpio_sda)) {
444
+ ret = PTR_ERR(adapter_data->gpio_sda);
445
+ goto free_both;
446
+ }
447
+
437448 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
438449 if (!res) {
439450 ret = -ENODEV;
....@@ -469,6 +480,7 @@
469480 new_adapter->owner = THIS_MODULE;
470481 new_adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
471482 new_adapter->dev.parent = &pdev->dev;
483
+ new_adapter->dev.of_node = pdev->dev.of_node;
472484 new_adapter->nr = pdev->id;
473485
474486 /*
....@@ -506,12 +518,19 @@
506518 return ret;
507519 }
508520
521
+static const struct of_device_id i2c_iop3xx_match[] = {
522
+ { .compatible = "intel,iop3xx-i2c", },
523
+ { .compatible = "intel,ixp4xx-i2c", },
524
+ {},
525
+};
526
+MODULE_DEVICE_TABLE(of, i2c_iop3xx_match);
509527
510528 static struct platform_driver iop3xx_i2c_driver = {
511529 .probe = iop3xx_i2c_probe,
512530 .remove = iop3xx_i2c_remove,
513531 .driver = {
514532 .name = "IOP3xx-I2C",
533
+ .of_match_table = i2c_iop3xx_match,
515534 },
516535 };
517536