forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-09 244b2c5ca8b14627e4a17755e5922221e121c771
kernel/drivers/i2c/busses/i2c-altera.c
....@@ -1,17 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright Intel Corporation (C) 2017.
3
- *
4
- * This program is free software; you can redistribute it and/or modify it
5
- * under the terms and conditions of the GNU General Public License,
6
- * version 2, as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope it will be useful, but WITHOUT
9
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
- * more details.
12
- *
13
- * You should have received a copy of the GNU General Public License along with
14
- * this program. If not, see <http://www.gnu.org/licenses/>.
154 *
165 * Based on the i2c-axxia.c driver.
176 */
....@@ -80,7 +69,6 @@
8069 * @fifo_size: size of the FIFO passed in.
8170 * @isr_mask: cached copy of local ISR enables.
8271 * @isr_status: cached copy of local ISR status.
83
- * @lock: spinlock for IRQ synchronization.
8472 * @isr_mutex: mutex for IRQ thread.
8573 */
8674 struct altr_i2c_dev {
....@@ -97,17 +85,13 @@
9785 u32 fifo_size;
9886 u32 isr_mask;
9987 u32 isr_status;
100
- spinlock_t lock; /* IRQ synchronization */
10188 struct mutex isr_mutex;
10289 };
10390
10491 static void
10592 altr_i2c_int_enable(struct altr_i2c_dev *idev, u32 mask, bool enable)
10693 {
107
- unsigned long flags;
10894 u32 int_en;
109
-
110
- spin_lock_irqsave(&idev->lock, flags);
11195
11296 int_en = readl(idev->base + ALTR_I2C_ISER);
11397 if (enable)
....@@ -116,8 +100,6 @@
116100 idev->isr_mask = int_en & ~mask;
117101
118102 writel(idev->isr_mask, idev->base + ALTR_I2C_ISER);
119
-
120
- spin_unlock_irqrestore(&idev->lock, flags);
121103 }
122104
123105 static void altr_i2c_int_clear(struct altr_i2c_dev *idev, u32 mask)
....@@ -160,7 +142,7 @@
160142 (ALTR_I2C_THRESHOLD << ALTR_I2C_CTRL_TCT_SHFT);
161143 u32 t_high, t_low;
162144
163
- if (idev->bus_clk_rate <= 100000) {
145
+ if (idev->bus_clk_rate <= I2C_MAX_STANDARD_MODE_FREQ) {
164146 tmp &= ~ALTR_I2C_CTRL_BSPEED;
165147 /* Standard mode SCL 50/50 */
166148 t_high = divisor * 1 / 2;
....@@ -357,6 +339,7 @@
357339
358340 time_left = wait_for_completion_timeout(&idev->msg_complete,
359341 ALTR_I2C_XFER_TIMEOUT);
342
+ mutex_lock(&idev->isr_mutex);
360343 altr_i2c_int_enable(idev, imask, false);
361344
362345 value = readl(idev->base + ALTR_I2C_STATUS) & ALTR_I2C_STAT_CORE;
....@@ -369,6 +352,7 @@
369352 }
370353
371354 altr_i2c_core_disable(idev);
355
+ mutex_unlock(&idev->isr_mutex);
372356
373357 return idev->msg_err;
374358 }
....@@ -400,23 +384,19 @@
400384 static int altr_i2c_probe(struct platform_device *pdev)
401385 {
402386 struct altr_i2c_dev *idev = NULL;
403
- struct resource *res;
404387 int irq, ret;
405388
406389 idev = devm_kzalloc(&pdev->dev, sizeof(*idev), GFP_KERNEL);
407390 if (!idev)
408391 return -ENOMEM;
409392
410
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
411
- idev->base = devm_ioremap_resource(&pdev->dev, res);
393
+ idev->base = devm_platform_ioremap_resource(pdev, 0);
412394 if (IS_ERR(idev->base))
413395 return PTR_ERR(idev->base);
414396
415397 irq = platform_get_irq(pdev, 0);
416
- if (irq < 0) {
417
- dev_err(&pdev->dev, "missing interrupt resource\n");
398
+ if (irq < 0)
418399 return irq;
419
- }
420400
421401 idev->i2c_clk = devm_clk_get(&pdev->dev, NULL);
422402 if (IS_ERR(idev->i2c_clk)) {
....@@ -426,7 +406,6 @@
426406
427407 idev->dev = &pdev->dev;
428408 init_completion(&idev->msg_complete);
429
- spin_lock_init(&idev->lock);
430409 mutex_init(&idev->isr_mutex);
431410
432411 ret = device_property_read_u32(idev->dev, "fifo-size",
....@@ -441,10 +420,10 @@
441420 &idev->bus_clk_rate);
442421 if (ret) {
443422 dev_err(&pdev->dev, "Default to 100kHz\n");
444
- idev->bus_clk_rate = 100000; /* default clock rate */
423
+ idev->bus_clk_rate = I2C_MAX_STANDARD_MODE_FREQ; /* default clock rate */
445424 }
446425
447
- if (idev->bus_clk_rate > 400000) {
426
+ if (idev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ) {
448427 dev_err(&pdev->dev, "invalid clock-frequency %d\n",
449428 idev->bus_clk_rate);
450429 return -EINVAL;
....@@ -464,7 +443,9 @@
464443 return ret;
465444 }
466445
446
+ mutex_lock(&idev->isr_mutex);
467447 altr_i2c_init(idev);
448
+ mutex_unlock(&idev->isr_mutex);
468449
469450 i2c_set_adapdata(&idev->adapter, idev);
470451 strlcpy(idev->adapter.name, pdev->name, sizeof(idev->adapter.name));