hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/i2c/busses/i2c-s3c2410.c
....@@ -1,19 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* linux/drivers/i2c/busses/i2c-s3c2410.c
23 *
34 * Copyright (C) 2004,2005,2009 Simtec Electronics
45 * Ben Dooks <ben@simtec.co.uk>
56 *
67 * S3C2410 I2C Controller
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
178 */
189
1910 #include <linux/kernel.h>
....@@ -33,7 +24,7 @@
3324 #include <linux/slab.h>
3425 #include <linux/io.h>
3526 #include <linux/of.h>
36
-#include <linux/of_gpio.h>
27
+#include <linux/gpio/consumer.h>
3728 #include <linux/pinctrl/consumer.h>
3829 #include <linux/mfd/syscon.h>
3930 #include <linux/regmap.h>
....@@ -104,7 +95,6 @@
10495 struct s3c24xx_i2c {
10596 wait_queue_head_t wait;
10697 kernel_ulong_t quirks;
107
- unsigned int suspended:1;
10898
10999 struct i2c_msg *msg;
110100 unsigned int msg_num;
....@@ -123,7 +113,7 @@
123113 struct i2c_adapter adap;
124114
125115 struct s3c2410_platform_i2c *pdata;
126
- int gpios[2];
116
+ struct gpio_desc *gpios[2];
127117 struct pinctrl *pctrl;
128118 #if defined(CONFIG_ARM_S3C24XX_CPUFREQ)
129119 struct notifier_block freq_transition;
....@@ -445,7 +435,7 @@
445435 * fall through to the write state, as we will need to
446436 * send a byte as well
447437 */
448
-
438
+ fallthrough;
449439 case STATE_WRITE:
450440 /*
451441 * we are writing data to the device... check for the
....@@ -706,9 +696,6 @@
706696 unsigned long timeout;
707697 int ret;
708698
709
- if (i2c->suspended)
710
- return -EIO;
711
-
712699 ret = s3c24xx_i2c_set_master(i2c);
713700 if (ret != 0) {
714701 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret);
....@@ -850,11 +837,11 @@
850837 int freq;
851838
852839 i2c->clkrate = clkin;
853
- clkin /= 1000; /* clkin now in KHz */
840
+ clkin /= 1000; /* clkin now in KHz */
854841
855842 dev_dbg(i2c->dev, "pdata desired frequency %lu\n", pdata->frequency);
856843
857
- target_frequency = pdata->frequency ? pdata->frequency : 100000;
844
+ target_frequency = pdata->frequency ?: I2C_MAX_STANDARD_MODE_FREQ;
858845
859846 target_frequency /= 1000; /* Target frequency now in KHz */
860847
....@@ -963,52 +950,26 @@
963950 #ifdef CONFIG_OF
964951 static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
965952 {
966
- int idx, gpio, ret;
953
+ int i;
967954
968955 if (i2c->quirks & QUIRK_NO_GPIO)
969956 return 0;
970957
971
- for (idx = 0; idx < 2; idx++) {
972
- gpio = of_get_gpio(i2c->dev->of_node, idx);
973
- if (!gpio_is_valid(gpio)) {
974
- dev_err(i2c->dev, "invalid gpio[%d]: %d\n", idx, gpio);
975
- goto free_gpio;
976
- }
977
- i2c->gpios[idx] = gpio;
978
-
979
- ret = gpio_request(gpio, "i2c-bus");
980
- if (ret) {
981
- dev_err(i2c->dev, "gpio [%d] request failed (%d)\n",
982
- gpio, ret);
983
- goto free_gpio;
958
+ for (i = 0; i < 2; i++) {
959
+ i2c->gpios[i] = devm_gpiod_get_index(i2c->dev, NULL,
960
+ i, GPIOD_ASIS);
961
+ if (IS_ERR(i2c->gpios[i])) {
962
+ dev_err(i2c->dev, "i2c gpio invalid at index %d\n", i);
963
+ return -EINVAL;
984964 }
985965 }
986966 return 0;
987
-
988
-free_gpio:
989
- while (--idx >= 0)
990
- gpio_free(i2c->gpios[idx]);
991
- return -EINVAL;
992967 }
993968
994
-static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
995
-{
996
- unsigned int idx;
997
-
998
- if (i2c->quirks & QUIRK_NO_GPIO)
999
- return;
1000
-
1001
- for (idx = 0; idx < 2; idx++)
1002
- gpio_free(i2c->gpios[idx]);
1003
-}
1004969 #else
1005970 static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
1006971 {
1007972 return 0;
1008
-}
1009
-
1010
-static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
1011
-{
1012973 }
1013974 #endif
1014975
....@@ -1238,9 +1199,6 @@
12381199
12391200 i2c_del_adapter(&i2c->adap);
12401201
1241
- if (pdev->dev.of_node && IS_ERR(i2c->pctrl))
1242
- s3c24xx_i2c_dt_gpio_free(i2c);
1243
-
12441202 return 0;
12451203 }
12461204
....@@ -1249,7 +1207,7 @@
12491207 {
12501208 struct s3c24xx_i2c *i2c = dev_get_drvdata(dev);
12511209
1252
- i2c->suspended = 1;
1210
+ i2c_mark_adapter_suspended(&i2c->adap);
12531211
12541212 if (!IS_ERR(i2c->sysreg))
12551213 regmap_read(i2c->sysreg, EXYNOS5_SYS_I2C_CFG, &i2c->sys_i2c_cfg);
....@@ -1270,7 +1228,7 @@
12701228 return ret;
12711229 s3c24xx_i2c_init(i2c);
12721230 clk_disable(i2c->clk);
1273
- i2c->suspended = 0;
1231
+ i2c_mark_adapter_resumed(&i2c->adap);
12741232
12751233 return 0;
12761234 }
....@@ -1311,5 +1269,5 @@
13111269 module_exit(i2c_adap_s3c_exit);
13121270
13131271 MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
1314
-MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1272
+MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
13151273 MODULE_LICENSE("GPL");