forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/i2c/busses/i2c-rk3x.c
....@@ -1,18 +1,17 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for I2C adapter in Rockchip RK3xxx SoC
34 *
45 * Max Schwarz <max.schwarz@online.de>
56 * based on the patches by Rockchip Inc.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118
9
+#include <linux/acpi.h>
1210 #include <linux/kernel.h>
1311 #include <linux/module.h>
1412 #include <linux/i2c.h>
1513 #include <linux/interrupt.h>
14
+#include <linux/iopoll.h>
1615 #include <linux/errno.h>
1716 #include <linux/err.h>
1817 #include <linux/platform_device.h>
....@@ -27,6 +26,7 @@
2726 #include <linux/math64.h>
2827 #include <linux/reboot.h>
2928 #include <linux/delay.h>
29
+#include <linux/soc/rockchip/rockchip_thunderboot_service.h>
3030
3131
3232 /* Register Map */
....@@ -39,6 +39,7 @@
3939 #define REG_IEN 0x18 /* interrupt enable */
4040 #define REG_IPD 0x1c /* interrupt pending */
4141 #define REG_FCNT 0x20 /* finished count */
42
+#define REG_CON1 0x228 /* control register1 */
4243
4344 /* Data buffer offsets */
4445 #define TXBUFFER_BASE 0x100
....@@ -66,6 +67,15 @@
6667 #define REG_CON_STA_CFG(cfg) ((cfg) << 12)
6768 #define REG_CON_STO_CFG(cfg) ((cfg) << 14)
6869
70
+enum {
71
+ RK_I2C_VERSION0 = 0,
72
+ RK_I2C_VERSION1,
73
+ RK_I2C_VERSION5 = 5,
74
+};
75
+
76
+#define REG_CON_VERSION GENMASK_ULL(24, 16)
77
+#define REG_CON_VERSION_SHIFT 16
78
+
6979 /* REG_MRXADDR bits */
7080 #define REG_MRXADDR_VALID(x) BIT(24 + (x)) /* [x*8+7:x*8] of MRX[R]ADDR valid */
7181
....@@ -81,6 +91,10 @@
8191
8292 /* Disable i2c all irqs */
8393 #define IEN_ALL_DISABLE 0
94
+
95
+#define REG_CON1_AUTO_STOP BIT(0)
96
+#define REG_CON1_TRANSFER_AUTO_STOP BIT(1)
97
+#define REG_CON1_NACK_AUTO_STOP BIT(2)
8498
8599 /* Constants */
86100 #define WAIT_TIMEOUT 1000 /* ms */
....@@ -197,6 +211,7 @@
197211 * @error: error code for i2c transfer
198212 * @i2c_restart_nb: make sure the i2c transfer to be finished
199213 * @system_restarting: true if system is restarting
214
+ * @tb_cl: client for rockchip thunder boot service
200215 */
201216 struct rk3x_i2c {
202217 struct i2c_adapter adap;
....@@ -208,6 +223,7 @@
208223 struct clk *clk;
209224 struct clk *pclk;
210225 struct notifier_block clk_rate_nb;
226
+ bool autostop_supported;
211227
212228 /* Settings */
213229 struct i2c_timings t;
....@@ -231,10 +247,12 @@
231247
232248 struct notifier_block i2c_restart_nb;
233249 bool system_restarting;
250
+ struct rk_tb_client tb_cl;
251
+ int irq;
234252 };
235253
236
-static int rk3x_i2c_fill_transmit_buf(struct rk3x_i2c *i2c, bool sended);
237254 static void rk3x_i2c_prepare_read(struct rk3x_i2c *i2c);
255
+static int rk3x_i2c_fill_transmit_buf(struct rk3x_i2c *i2c, bool sended);
238256
239257 static inline void rk3x_i2c_wake_up(struct rk3x_i2c *i2c)
240258 {
....@@ -271,23 +289,62 @@
271289 i2c_writel(i2c, val, REG_CON);
272290 }
273291
292
+static bool rk3x_i2c_auto_stop(struct rk3x_i2c *i2c)
293
+{
294
+ unsigned int len, con1 = 0;
295
+
296
+ if (!i2c->autostop_supported)
297
+ return false;
298
+
299
+ if (!(i2c->msg->flags & I2C_M_IGNORE_NAK))
300
+ con1 = REG_CON1_NACK_AUTO_STOP | REG_CON1_AUTO_STOP;
301
+
302
+ if (!i2c->is_last_msg)
303
+ goto out;
304
+
305
+ len = i2c->msg->len - i2c->processed;
306
+
307
+ if (len > 32)
308
+ goto out;
309
+
310
+ i2c->state = STATE_STOP;
311
+
312
+ con1 |= REG_CON1_TRANSFER_AUTO_STOP | REG_CON1_AUTO_STOP;
313
+ i2c_writel(i2c, con1, REG_CON1);
314
+ if (con1 & REG_CON1_NACK_AUTO_STOP)
315
+ i2c_writel(i2c, REG_INT_STOP, REG_IEN);
316
+ else
317
+ i2c_writel(i2c, REG_INT_STOP | REG_INT_NAKRCV, REG_IEN);
318
+
319
+ return true;
320
+
321
+out:
322
+ i2c_writel(i2c, con1, REG_CON1);
323
+ return false;
324
+}
325
+
274326 /**
275327 * Generate a START condition, which triggers a REG_INT_START interrupt.
276328 */
277329 static void rk3x_i2c_start(struct rk3x_i2c *i2c)
278330 {
279331 u32 val = i2c_readl(i2c, REG_CON) & REG_CON_TUNING_MASK;
332
+ bool auto_stop = rk3x_i2c_auto_stop(i2c);
280333 int length = 0;
281334
282335 /* enable appropriate interrupts */
283336 if (i2c->mode == REG_CON_MOD_TX) {
284
- i2c_writel(i2c, REG_INT_MBTF | REG_INT_NAKRCV, REG_IEN);
285
- i2c->state = STATE_WRITE;
337
+ if (!auto_stop) {
338
+ i2c_writel(i2c, REG_INT_MBTF | REG_INT_NAKRCV, REG_IEN);
339
+ i2c->state = STATE_WRITE;
340
+ }
286341 length = rk3x_i2c_fill_transmit_buf(i2c, false);
287342 } else {
288343 /* in any other case, we are going to be reading. */
289
- i2c_writel(i2c, REG_INT_MBRF | REG_INT_NAKRCV, REG_IEN);
290
- i2c->state = STATE_READ;
344
+ if (!auto_stop) {
345
+ i2c_writel(i2c, REG_INT_MBRF | REG_INT_NAKRCV, REG_IEN);
346
+ i2c->state = STATE_READ;
347
+ }
291348 }
292349
293350 /* enable adapter with correct mode, send START condition */
....@@ -424,7 +481,7 @@
424481 {
425482 if (!(ipd & REG_INT_MBTF)) {
426483 rk3x_i2c_stop(i2c, -EIO);
427
- dev_err(i2c->dev, "unexpected irq in WRITE: 0x%x\n", ipd);
484
+ dev_warn_ratelimited(i2c->dev, "unexpected irq in WRITE: 0x%x\n", ipd);
428485 rk3x_i2c_clean_ipd(i2c);
429486 return;
430487 }
....@@ -432,6 +489,7 @@
432489 /* ack interrupt */
433490 i2c_writel(i2c, REG_INT_MBTF, REG_IPD);
434491
492
+ rk3x_i2c_auto_stop(i2c);
435493 /* are we finished? */
436494 if (i2c->processed == i2c->msg->len)
437495 rk3x_i2c_stop(i2c, i2c->error);
....@@ -439,19 +497,12 @@
439497 rk3x_i2c_fill_transmit_buf(i2c, true);
440498 }
441499
442
-static void rk3x_i2c_handle_read(struct rk3x_i2c *i2c, unsigned int ipd)
500
+static void rk3x_i2c_read(struct rk3x_i2c *i2c)
443501 {
444502 unsigned int i;
445503 unsigned int len = i2c->msg->len - i2c->processed;
446
- u32 uninitialized_var(val);
504
+ u32 val;
447505 u8 byte;
448
-
449
- /* we only care for MBRF here. */
450
- if (!(ipd & REG_INT_MBRF))
451
- return;
452
-
453
- /* ack interrupt (read also produces a spurious START flag, clear it too) */
454
- i2c_writel(i2c, REG_INT_MBRF | REG_INT_START, REG_IPD);
455506
456507 /* Can only handle a maximum of 32 bytes at a time */
457508 if (len > 32)
....@@ -465,7 +516,21 @@
465516 byte = (val >> ((i % 4) * 8)) & 0xff;
466517 i2c->msg->buf[i2c->processed++] = byte;
467518 }
519
+}
468520
521
+static void rk3x_i2c_handle_read(struct rk3x_i2c *i2c, unsigned int ipd)
522
+{
523
+ /* we only care for MBRF here. */
524
+ if (!(ipd & REG_INT_MBRF))
525
+ return;
526
+
527
+ /* ack interrupt (read also produces a spurious START flag, clear it too) */
528
+ i2c_writel(i2c, REG_INT_MBRF | REG_INT_START, REG_IPD);
529
+
530
+ /* read the data from receive buffer */
531
+ rk3x_i2c_read(i2c);
532
+
533
+ rk3x_i2c_auto_stop(i2c);
469534 /* are we finished? */
470535 if (i2c->processed == i2c->msg->len)
471536 rk3x_i2c_stop(i2c, i2c->error);
....@@ -479,9 +544,19 @@
479544
480545 if (!(ipd & REG_INT_STOP)) {
481546 rk3x_i2c_stop(i2c, -EIO);
482
- dev_err(i2c->dev, "unexpected irq in STOP: 0x%x\n", ipd);
547
+ dev_warn_ratelimited(i2c->dev, "unexpected irq in STOP: 0x%x\n", ipd);
483548 rk3x_i2c_clean_ipd(i2c);
484549 return;
550
+ }
551
+
552
+ if (i2c->autostop_supported && !i2c->error) {
553
+ if (i2c->mode != REG_CON_MOD_TX && i2c->msg) {
554
+ if ((i2c->msg->len - i2c->processed) > 0)
555
+ rk3x_i2c_read(i2c);
556
+ }
557
+
558
+ i2c->processed = 0;
559
+ i2c->msg = NULL;
485560 }
486561
487562 /* ack interrupt */
....@@ -490,6 +565,8 @@
490565 /* disable STOP bit */
491566 con = i2c_readl(i2c, REG_CON);
492567 con &= ~REG_CON_STOP;
568
+ if (i2c->autostop_supported)
569
+ con &= ~REG_CON_START;
493570 i2c_writel(i2c, con, REG_CON);
494571
495572 i2c->busy = false;
....@@ -531,8 +608,13 @@
531608 ipd &= ~REG_INT_NAKRCV;
532609
533610 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
534
- rk3x_i2c_stop(i2c, -ENXIO);
535
- goto out;
611
+ if (i2c->autostop_supported) {
612
+ i2c->error = -ENXIO;
613
+ i2c->state = STATE_STOP;
614
+ } else {
615
+ rk3x_i2c_stop(i2c, -ENXIO);
616
+ goto out;
617
+ }
536618 }
537619 }
538620
....@@ -568,9 +650,9 @@
568650 */
569651 static const struct i2c_spec_values *rk3x_i2c_get_spec(unsigned int speed)
570652 {
571
- if (speed <= 100000)
653
+ if (speed <= I2C_MAX_STANDARD_MODE_FREQ)
572654 return &standard_mode_spec;
573
- else if (speed <= 400000)
655
+ else if (speed <= I2C_MAX_FAST_MODE_FREQ)
574656 return &fast_mode_spec;
575657 else
576658 return &fast_mode_plus_spec;
....@@ -607,8 +689,8 @@
607689 int ret = 0;
608690
609691 /* Only support standard-mode and fast-mode */
610
- if (WARN_ON(t->bus_freq_hz > 400000))
611
- t->bus_freq_hz = 400000;
692
+ if (WARN_ON(t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ))
693
+ t->bus_freq_hz = I2C_MAX_FAST_MODE_FREQ;
612694
613695 /* prevent scl_rate_khz from becoming 0 */
614696 if (WARN_ON(t->bus_freq_hz < 1000))
....@@ -787,8 +869,8 @@
787869 int ret = 0;
788870
789871 /* Support standard-mode, fast-mode and fast-mode plus */
790
- if (WARN_ON(t->bus_freq_hz > 1000000))
791
- t->bus_freq_hz = 1000000;
872
+ if (WARN_ON(t->bus_freq_hz > I2C_MAX_FAST_MODE_PLUS_FREQ))
873
+ t->bus_freq_hz = I2C_MAX_FAST_MODE_PLUS_FREQ;
792874
793875 /* prevent scl_rate_khz from becoming 0 */
794876 if (WARN_ON(t->bus_freq_hz < 1000))
....@@ -1064,12 +1146,27 @@
10641146 i2c->error = 0;
10651147
10661148 rk3x_i2c_clean_ipd(i2c);
1149
+ if (i2c->autostop_supported)
1150
+ i2c_writel(i2c, 0, REG_CON1);
10671151
10681152 return ret;
10691153 }
10701154
1071
-static int rk3x_i2c_xfer(struct i2c_adapter *adap,
1072
- struct i2c_msg *msgs, int num)
1155
+static int rk3x_i2c_wait_xfer_poll(struct rk3x_i2c *i2c, unsigned long xfer_time)
1156
+{
1157
+ ktime_t timeout = ktime_add_ms(ktime_get(), xfer_time);
1158
+
1159
+ while (READ_ONCE(i2c->busy) &&
1160
+ ktime_compare(ktime_get(), timeout) < 0) {
1161
+ udelay(5);
1162
+ rk3x_i2c_irq(0, i2c);
1163
+ }
1164
+
1165
+ return !i2c->busy;
1166
+}
1167
+
1168
+static int rk3x_i2c_xfer_common(struct i2c_adapter *adap,
1169
+ struct i2c_msg *msgs, int num, bool polling)
10731170 {
10741171 struct rk3x_i2c *i2c = (struct rk3x_i2c *)adap->algo_data;
10751172 unsigned long timeout, flags;
....@@ -1092,12 +1189,26 @@
10921189 * rk3x_i2c_setup()).
10931190 */
10941191 for (i = 0; i < num; i += ret) {
1095
- ret = rk3x_i2c_setup(i2c, msgs + i, num - i);
1192
+ unsigned long xfer_time = 100;
1193
+ int len;
10961194
1195
+ ret = rk3x_i2c_setup(i2c, msgs + i, num - i);
10971196 if (ret < 0) {
10981197 dev_err(i2c->dev, "rk3x_i2c_setup() failed\n");
10991198 break;
11001199 }
1200
+
1201
+ /*
1202
+ * Transfer time in mSec = Total bits / transfer rate + interval time
1203
+ * Total bits = 9 bits per byte (including ACK bit) + Start & stop bits
1204
+ */
1205
+ if (ret == 2)
1206
+ len = msgs[i + 1].len;
1207
+ else
1208
+ len = msgs[i].len;
1209
+ xfer_time += len / 64;
1210
+ xfer_time += DIV_ROUND_CLOSEST(((len * 9) + 2) * MSEC_PER_SEC,
1211
+ i2c->t.bus_freq_hz);
11011212
11021213 if (i + ret >= num)
11031214 i2c->is_last_msg = true;
....@@ -1106,8 +1217,12 @@
11061217
11071218 spin_unlock_irqrestore(&i2c->lock, flags);
11081219
1109
- timeout = wait_event_timeout(i2c->wait, !i2c->busy,
1110
- msecs_to_jiffies(WAIT_TIMEOUT));
1220
+ if (!polling) {
1221
+ timeout = wait_event_timeout(i2c->wait, !i2c->busy,
1222
+ msecs_to_jiffies(xfer_time));
1223
+ } else {
1224
+ timeout = rk3x_i2c_wait_xfer_poll(i2c, xfer_time);
1225
+ }
11111226
11121227 spin_lock_irqsave(&i2c->lock, flags);
11131228
....@@ -1144,6 +1259,18 @@
11441259 return ret < 0 ? ret : num;
11451260 }
11461261
1262
+static int rk3x_i2c_xfer(struct i2c_adapter *adap,
1263
+ struct i2c_msg *msgs, int num)
1264
+{
1265
+ return rk3x_i2c_xfer_common(adap, msgs, num, false);
1266
+}
1267
+
1268
+static int rk3x_i2c_xfer_polling(struct i2c_adapter *adap,
1269
+ struct i2c_msg *msgs, int num)
1270
+{
1271
+ return rk3x_i2c_xfer_common(adap, msgs, num, true);
1272
+}
1273
+
11471274 static int rk3x_i2c_restart_notify(struct notifier_block *this,
11481275 unsigned long mode, void *cmd)
11491276 {
....@@ -1177,6 +1304,57 @@
11771304
11781305 return NOTIFY_DONE;
11791306 }
1307
+
1308
+static unsigned int rk3x_i2c_get_version(struct rk3x_i2c *i2c)
1309
+{
1310
+ unsigned int version;
1311
+
1312
+ clk_enable(i2c->pclk);
1313
+ version = i2c_readl(i2c, REG_CON) & REG_CON_VERSION;
1314
+ clk_disable(i2c->pclk);
1315
+ version >>= REG_CON_VERSION_SHIFT;
1316
+
1317
+ return version;
1318
+}
1319
+
1320
+static int rk3x_i2c_of_get_bus_id(struct device *dev, struct rk3x_i2c *priv)
1321
+{
1322
+ int bus_id = -1;
1323
+
1324
+ if (IS_ENABLED(CONFIG_OF) && dev->of_node)
1325
+ bus_id = of_alias_get_id(dev->of_node, "i2c");
1326
+
1327
+ return bus_id;
1328
+}
1329
+
1330
+#ifdef CONFIG_ACPI
1331
+static int rk3x_i2c_acpi_get_bus_id(struct device *dev, struct rk3x_i2c *priv)
1332
+{
1333
+ struct acpi_device *adev;
1334
+ unsigned long bus_id = -1;
1335
+ const char *uid;
1336
+ int ret;
1337
+
1338
+ adev = ACPI_COMPANION(dev);
1339
+ if (!adev)
1340
+ return -ENXIO;
1341
+
1342
+ uid = acpi_device_uid(adev);
1343
+ if (!uid || !(*uid)) {
1344
+ dev_err(dev, "Cannot retrieve UID\n");
1345
+ return -ENODEV;
1346
+ }
1347
+
1348
+ ret = kstrtoul(uid, 0, &bus_id);
1349
+
1350
+ return !ret ? bus_id : -ERANGE;
1351
+}
1352
+#else
1353
+static int rk3x_i2c_acpi_get_bus_id(struct device *dev, struct rk3x_i2c *priv)
1354
+{
1355
+ return -ENOENT;
1356
+}
1357
+#endif /* CONFIG_ACPI */
11801358
11811359 static __maybe_unused int rk3x_i2c_suspend_noirq(struct device *dev)
11821360 {
....@@ -1217,6 +1395,7 @@
12171395
12181396 static const struct i2c_algorithm rk3x_i2c_algorithm = {
12191397 .master_xfer = rk3x_i2c_xfer,
1398
+ .master_xfer_atomic = rk3x_i2c_xfer_polling,
12201399 .functionality = rk3x_i2c_func,
12211400 };
12221401
....@@ -1288,12 +1467,37 @@
12881467 };
12891468 MODULE_DEVICE_TABLE(of, rk3x_i2c_match);
12901469
1470
+static void rk3x_i2c_tb_cb(void *data)
1471
+{
1472
+ unsigned long clk_rate;
1473
+ int ret;
1474
+ struct rk3x_i2c *i2c = (struct rk3x_i2c *)data;
1475
+
1476
+ if (i2c->clk) {
1477
+ i2c->clk_rate_nb.notifier_call = rk3x_i2c_clk_notifier_cb;
1478
+ ret = clk_notifier_register(i2c->clk, &i2c->clk_rate_nb);
1479
+ if (ret != 0) {
1480
+ dev_err(i2c->dev, "Unable to register clock notifier\n");
1481
+ clk_unprepare(i2c->pclk);
1482
+ clk_unprepare(i2c->clk);
1483
+ return;
1484
+ }
1485
+ }
1486
+
1487
+ clk_rate = clk_get_rate(i2c->clk);
1488
+ if (!clk_rate)
1489
+ device_property_read_u32(i2c->dev, "i2c,clk-rate", (u32 *)&clk_rate);
1490
+
1491
+ rk3x_i2c_adapt_div(i2c, clk_rate);
1492
+
1493
+ enable_irq(i2c->irq);
1494
+}
1495
+
12911496 static int rk3x_i2c_probe(struct platform_device *pdev)
12921497 {
1498
+ struct fwnode_handle *fw = dev_fwnode(&pdev->dev);
12931499 struct device_node *np = pdev->dev.of_node;
1294
- const struct of_device_id *match;
12951500 struct rk3x_i2c *i2c;
1296
- struct resource *mem;
12971501 int ret = 0;
12981502 u32 value;
12991503 int irq;
....@@ -1303,8 +1507,16 @@
13031507 if (!i2c)
13041508 return -ENOMEM;
13051509
1306
- match = of_match_node(rk3x_i2c_match, np);
1307
- i2c->soc_data = match->data;
1510
+ i2c->soc_data = (struct rk3x_i2c_soc_data *)device_get_match_data(&pdev->dev);
1511
+
1512
+ ret = rk3x_i2c_acpi_get_bus_id(&pdev->dev, i2c);
1513
+ if (ret < 0) {
1514
+ ret = rk3x_i2c_of_get_bus_id(&pdev->dev, i2c);
1515
+ if (ret < 0)
1516
+ return ret;
1517
+ }
1518
+
1519
+ i2c->adap.nr = ret;
13081520
13091521 /* use common interface to get I2C timing properties */
13101522 i2c_parse_fw_timings(&pdev->dev, &i2c->t, true);
....@@ -1313,9 +1525,10 @@
13131525 i2c->adap.owner = THIS_MODULE;
13141526 i2c->adap.algo = &rk3x_i2c_algorithm;
13151527 i2c->adap.retries = 3;
1316
- i2c->adap.dev.of_node = np;
1528
+ i2c->adap.dev.of_node = pdev->dev.of_node;
13171529 i2c->adap.algo_data = i2c;
13181530 i2c->adap.dev.parent = &pdev->dev;
1531
+ i2c->adap.dev.fwnode = fw;
13191532
13201533 i2c->dev = &pdev->dev;
13211534
....@@ -1330,8 +1543,7 @@
13301543 return ret;
13311544 }
13321545
1333
- mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1334
- i2c->regs = devm_ioremap_resource(&pdev->dev, mem);
1546
+ i2c->regs = devm_platform_ioremap_resource(pdev, 0);
13351547 if (IS_ERR(i2c->regs))
13361548 return PTR_ERR(i2c->regs);
13371549
....@@ -1344,14 +1556,7 @@
13441556
13451557 grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf");
13461558 if (!IS_ERR(grf)) {
1347
- int bus_nr;
1348
-
1349
- /* Try to set the I2C adapter number from dt */
1350
- bus_nr = of_alias_get_id(np, "i2c");
1351
- if (bus_nr < 0) {
1352
- dev_err(&pdev->dev, "rk3x-i2c needs i2cX alias");
1353
- return -EINVAL;
1354
- }
1559
+ int bus_nr = i2c->adap.nr;
13551560
13561561 if (i2c->soc_data == &rv1108_soc_data && bus_nr == 2)
13571562 /* rv1108 i2c2 set grf offset-0x408, bit-10 */
....@@ -1376,9 +1581,15 @@
13761581
13771582 /* IRQ setup */
13781583 irq = platform_get_irq(pdev, 0);
1379
- if (irq < 0) {
1380
- dev_err(&pdev->dev, "cannot find rk3x IRQ\n");
1584
+ if (irq < 0)
13811585 return irq;
1586
+ i2c->irq = irq;
1587
+
1588
+ if (IS_ENABLED(CONFIG_ROCKCHIP_THUNDER_BOOT_SERVICE) &&
1589
+ device_property_read_bool(&pdev->dev, "rockchip,amp-shared")) {
1590
+ i2c->tb_cl.data = i2c;
1591
+ i2c->tb_cl.cb = rk3x_i2c_tb_cb;
1592
+ irq_set_status_flags(irq, IRQ_NOAUTOEN);
13821593 }
13831594
13841595 ret = devm_request_irq(&pdev->dev, irq, rk3x_i2c_irq,
....@@ -1390,26 +1601,23 @@
13901601
13911602 platform_set_drvdata(pdev, i2c);
13921603
1393
- if (i2c->soc_data->calc_timings == rk3x_i2c_v0_calc_timings) {
1394
- /* Only one clock to use for bus clock and peripheral clock */
1395
- i2c->clk = devm_clk_get(&pdev->dev, NULL);
1396
- i2c->pclk = i2c->clk;
1397
- } else {
1398
- i2c->clk = devm_clk_get(&pdev->dev, "i2c");
1399
- i2c->pclk = devm_clk_get(&pdev->dev, "pclk");
1400
- }
1604
+ if (!has_acpi_companion(&pdev->dev)) {
1605
+ if (i2c->soc_data->calc_timings == rk3x_i2c_v0_calc_timings) {
1606
+ /* Only one clock to use for bus clock and peripheral clock */
1607
+ i2c->clk = devm_clk_get(&pdev->dev, NULL);
1608
+ i2c->pclk = i2c->clk;
1609
+ } else {
1610
+ i2c->clk = devm_clk_get(&pdev->dev, "i2c");
1611
+ i2c->pclk = devm_clk_get(&pdev->dev, "pclk");
1612
+ }
14011613
1402
- if (IS_ERR(i2c->clk)) {
1403
- ret = PTR_ERR(i2c->clk);
1404
- if (ret != -EPROBE_DEFER)
1405
- dev_err(&pdev->dev, "Can't get bus clk: %d\n", ret);
1406
- return ret;
1407
- }
1408
- if (IS_ERR(i2c->pclk)) {
1409
- ret = PTR_ERR(i2c->pclk);
1410
- if (ret != -EPROBE_DEFER)
1411
- dev_err(&pdev->dev, "Can't get periph clk: %d\n", ret);
1412
- return ret;
1614
+ if (IS_ERR(i2c->clk))
1615
+ return dev_err_probe(&pdev->dev, PTR_ERR(i2c->clk),
1616
+ "Can't get bus clk\n");
1617
+
1618
+ if (IS_ERR(i2c->pclk))
1619
+ return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
1620
+ "Can't get periph clk\n");
14131621 }
14141622
14151623 ret = clk_prepare(i2c->clk);
....@@ -1423,17 +1631,29 @@
14231631 goto err_clk;
14241632 }
14251633
1426
- i2c->clk_rate_nb.notifier_call = rk3x_i2c_clk_notifier_cb;
1427
- ret = clk_notifier_register(i2c->clk, &i2c->clk_rate_nb);
1428
- if (ret != 0) {
1429
- dev_err(&pdev->dev, "Unable to register clock notifier\n");
1430
- goto err_pclk;
1634
+ if (IS_ENABLED(CONFIG_ROCKCHIP_THUNDER_BOOT_SERVICE) && i2c->tb_cl.cb) {
1635
+ rk_tb_client_register_cb(&i2c->tb_cl);
1636
+ } else {
1637
+ if (i2c->clk) {
1638
+ i2c->clk_rate_nb.notifier_call = rk3x_i2c_clk_notifier_cb;
1639
+ ret = clk_notifier_register(i2c->clk, &i2c->clk_rate_nb);
1640
+ if (ret != 0) {
1641
+ dev_err(&pdev->dev, "Unable to register clock notifier\n");
1642
+ goto err_pclk;
1643
+ }
1644
+ }
1645
+
1646
+ clk_rate = clk_get_rate(i2c->clk);
1647
+ if (!clk_rate)
1648
+ device_property_read_u32(&pdev->dev, "i2c,clk-rate", (u32 *)&clk_rate);
1649
+
1650
+ rk3x_i2c_adapt_div(i2c, clk_rate);
14311651 }
14321652
1433
- clk_rate = clk_get_rate(i2c->clk);
1434
- rk3x_i2c_adapt_div(i2c, clk_rate);
1653
+ if (rk3x_i2c_get_version(i2c) >= RK_I2C_VERSION5)
1654
+ i2c->autostop_supported = true;
14351655
1436
- ret = i2c_add_adapter(&i2c->adap);
1656
+ ret = i2c_add_numbered_adapter(&i2c->adap);
14371657 if (ret < 0)
14381658 goto err_clk_notifier;
14391659
....@@ -1462,7 +1682,7 @@
14621682 return 0;
14631683 }
14641684
1465
-const static struct dev_pm_ops rk3x_i2c_pm_ops = {
1685
+static const struct dev_pm_ops rk3x_i2c_pm_ops = {
14661686 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(rk3x_i2c_suspend_noirq,
14671687 rk3x_i2c_resume_noirq)
14681688 };
....@@ -1482,7 +1702,11 @@
14821702 {
14831703 return platform_driver_register(&rk3x_i2c_driver);
14841704 }
1705
+#ifdef CONFIG_INITCALL_ASYNC
14851706 subsys_initcall_sync(rk3x_i2c_driver_init);
1707
+#else
1708
+subsys_initcall(rk3x_i2c_driver_init);
1709
+#endif
14861710
14871711 static void __exit rk3x_i2c_driver_exit(void)
14881712 {