6
6
*/
7
7
8
8
#include <linux/acpi.h>
9
+ #include <linux/bitfield.h>
9
10
#include <linux/delay.h>
10
11
#include <linux/err.h>
11
12
#include <linux/interrupt.h>
63
64
*/
64
65
#define MLXBF_I2C_TYU_PLL_OUT_FREQ (400 * 1000 * 1000)
65
66
/* Reference clock for Bluefield - 156 MHz. */
66
- #define MLXBF_I2C_PLL_IN_FREQ (156 * 1000 * 1000)
67
+ #define MLXBF_I2C_PLL_IN_FREQ 156250000ULL
67
68
68
69
/* Constant used to determine the PLL frequency. */
69
- #define MLNXBF_I2C_COREPLL_CONST 16384
70
+ #define MLNXBF_I2C_COREPLL_CONST 16384ULL
71
+
72
+ #define MLXBF_I2C_FREQUENCY_1GHZ 1000000000ULL
70
73
71
74
/* PLL registers. */
72
- #define MLXBF_I2C_CORE_PLL_REG0 0x0
73
75
#define MLXBF_I2C_CORE_PLL_REG1 0x4
74
76
#define MLXBF_I2C_CORE_PLL_REG2 0x8
75
77
181
183
#define MLXBF_I2C_COREPLL_FREQ MLXBF_I2C_TYU_PLL_OUT_FREQ
182
184
183
185
/* Core PLL TYU configuration. */
184
- #define MLXBF_I2C_COREPLL_CORE_F_TYU_MASK GENMASK(12, 0)
185
- #define MLXBF_I2C_COREPLL_CORE_OD_TYU_MASK GENMASK(3, 0)
186
- #define MLXBF_I2C_COREPLL_CORE_R_TYU_MASK GENMASK(5, 0)
187
-
188
- #define MLXBF_I2C_COREPLL_CORE_F_TYU_SHIFT 3
189
- #define MLXBF_I2C_COREPLL_CORE_OD_TYU_SHIFT 16
190
- #define MLXBF_I2C_COREPLL_CORE_R_TYU_SHIFT 20
186
+ #define MLXBF_I2C_COREPLL_CORE_F_TYU_MASK GENMASK(15, 3)
187
+ #define MLXBF_I2C_COREPLL_CORE_OD_TYU_MASK GENMASK(19, 16)
188
+ #define MLXBF_I2C_COREPLL_CORE_R_TYU_MASK GENMASK(25, 20)
191
189
192
190
/* Core PLL YU configuration. */
193
191
#define MLXBF_I2C_COREPLL_CORE_F_YU_MASK GENMASK(25, 0)
194
192
#define MLXBF_I2C_COREPLL_CORE_OD_YU_MASK GENMASK(3, 0)
195
- #define MLXBF_I2C_COREPLL_CORE_R_YU_MASK GENMASK(5, 0 )
193
+ #define MLXBF_I2C_COREPLL_CORE_R_YU_MASK GENMASK(31, 26 )
196
194
197
- #define MLXBF_I2C_COREPLL_CORE_F_YU_SHIFT 0
198
- #define MLXBF_I2C_COREPLL_CORE_OD_YU_SHIFT 1
199
- #define MLXBF_I2C_COREPLL_CORE_R_YU_SHIFT 26
200
195
201
196
/* Core PLL frequency. */
202
197
static u64 mlxbf_i2c_corepll_frequency ;
@@ -479,8 +474,6 @@ static struct mutex mlxbf_i2c_bus_lock;
479
474
#define MLXBF_I2C_MASK_8 GENMASK(7, 0)
480
475
#define MLXBF_I2C_MASK_16 GENMASK(15, 0)
481
476
482
- #define MLXBF_I2C_FREQUENCY_1GHZ 1000000000
483
-
484
477
/*
485
478
* Function to poll a set of bits at a specific address; it checks whether
486
479
* the bits are equal to zero when eq_zero is set to 'true', and not equal
@@ -669,7 +662,7 @@ static int mlxbf_i2c_smbus_enable(struct mlxbf_i2c_priv *priv, u8 slave,
669
662
/* Clear status bits. */
670
663
writel (0x0 , priv -> smbus -> io + MLXBF_I2C_SMBUS_MASTER_STATUS );
671
664
/* Set the cause data. */
672
- writel (~0x0 , priv -> smbus -> io + MLXBF_I2C_CAUSE_OR_CLEAR );
665
+ writel (~0x0 , priv -> mst_cause -> io + MLXBF_I2C_CAUSE_OR_CLEAR );
673
666
/* Zero PEC byte. */
674
667
writel (0x0 , priv -> smbus -> io + MLXBF_I2C_SMBUS_MASTER_PEC );
675
668
/* Zero byte count. */
@@ -738,6 +731,9 @@ mlxbf_i2c_smbus_start_transaction(struct mlxbf_i2c_priv *priv,
738
731
if (flags & MLXBF_I2C_F_WRITE ) {
739
732
write_en = 1 ;
740
733
write_len += operation -> length ;
734
+ if (data_idx + operation -> length >
735
+ MLXBF_I2C_MASTER_DATA_DESC_SIZE )
736
+ return - ENOBUFS ;
741
737
memcpy (data_desc + data_idx ,
742
738
operation -> buffer , operation -> length );
743
739
data_idx += operation -> length ;
@@ -1407,24 +1403,19 @@ static int mlxbf_i2c_init_master(struct platform_device *pdev,
1407
1403
return 0 ;
1408
1404
}
1409
1405
1410
- static u64 mlxbf_calculate_freq_from_tyu (struct mlxbf_i2c_resource * corepll_res )
1406
+ static u64 mlxbf_i2c_calculate_freq_from_tyu (struct mlxbf_i2c_resource * corepll_res )
1411
1407
{
1412
- u64 core_frequency , pad_frequency ;
1408
+ u64 core_frequency ;
1413
1409
u8 core_od , core_r ;
1414
1410
u32 corepll_val ;
1415
1411
u16 core_f ;
1416
1412
1417
- pad_frequency = MLXBF_I2C_PLL_IN_FREQ ;
1418
-
1419
1413
corepll_val = readl (corepll_res -> io + MLXBF_I2C_CORE_PLL_REG1 );
1420
1414
1421
1415
/* Get Core PLL configuration bits. */
1422
- core_f = rol32 (corepll_val , MLXBF_I2C_COREPLL_CORE_F_TYU_SHIFT ) &
1423
- MLXBF_I2C_COREPLL_CORE_F_TYU_MASK ;
1424
- core_od = rol32 (corepll_val , MLXBF_I2C_COREPLL_CORE_OD_TYU_SHIFT ) &
1425
- MLXBF_I2C_COREPLL_CORE_OD_TYU_MASK ;
1426
- core_r = rol32 (corepll_val , MLXBF_I2C_COREPLL_CORE_R_TYU_SHIFT ) &
1427
- MLXBF_I2C_COREPLL_CORE_R_TYU_MASK ;
1416
+ core_f = FIELD_GET (MLXBF_I2C_COREPLL_CORE_F_TYU_MASK , corepll_val );
1417
+ core_od = FIELD_GET (MLXBF_I2C_COREPLL_CORE_OD_TYU_MASK , corepll_val );
1418
+ core_r = FIELD_GET (MLXBF_I2C_COREPLL_CORE_R_TYU_MASK , corepll_val );
1428
1419
1429
1420
/*
1430
1421
* Compute PLL output frequency as follow:
@@ -1436,31 +1427,26 @@ static u64 mlxbf_calculate_freq_from_tyu(struct mlxbf_i2c_resource *corepll_res)
1436
1427
* Where PLL_OUT_FREQ and PLL_IN_FREQ refer to CoreFrequency
1437
1428
* and PadFrequency, respectively.
1438
1429
*/
1439
- core_frequency = pad_frequency * (++ core_f );
1430
+ core_frequency = MLXBF_I2C_PLL_IN_FREQ * (++ core_f );
1440
1431
core_frequency /= (++ core_r ) * (++ core_od );
1441
1432
1442
1433
return core_frequency ;
1443
1434
}
1444
1435
1445
- static u64 mlxbf_calculate_freq_from_yu (struct mlxbf_i2c_resource * corepll_res )
1436
+ static u64 mlxbf_i2c_calculate_freq_from_yu (struct mlxbf_i2c_resource * corepll_res )
1446
1437
{
1447
1438
u32 corepll_reg1_val , corepll_reg2_val ;
1448
- u64 corepll_frequency , pad_frequency ;
1439
+ u64 corepll_frequency ;
1449
1440
u8 core_od , core_r ;
1450
1441
u32 core_f ;
1451
1442
1452
- pad_frequency = MLXBF_I2C_PLL_IN_FREQ ;
1453
-
1454
1443
corepll_reg1_val = readl (corepll_res -> io + MLXBF_I2C_CORE_PLL_REG1 );
1455
1444
corepll_reg2_val = readl (corepll_res -> io + MLXBF_I2C_CORE_PLL_REG2 );
1456
1445
1457
1446
/* Get Core PLL configuration bits */
1458
- core_f = rol32 (corepll_reg1_val , MLXBF_I2C_COREPLL_CORE_F_YU_SHIFT ) &
1459
- MLXBF_I2C_COREPLL_CORE_F_YU_MASK ;
1460
- core_r = rol32 (corepll_reg1_val , MLXBF_I2C_COREPLL_CORE_R_YU_SHIFT ) &
1461
- MLXBF_I2C_COREPLL_CORE_R_YU_MASK ;
1462
- core_od = rol32 (corepll_reg2_val , MLXBF_I2C_COREPLL_CORE_OD_YU_SHIFT ) &
1463
- MLXBF_I2C_COREPLL_CORE_OD_YU_MASK ;
1447
+ core_f = FIELD_GET (MLXBF_I2C_COREPLL_CORE_F_YU_MASK , corepll_reg1_val );
1448
+ core_r = FIELD_GET (MLXBF_I2C_COREPLL_CORE_R_YU_MASK , corepll_reg1_val );
1449
+ core_od = FIELD_GET (MLXBF_I2C_COREPLL_CORE_OD_YU_MASK , corepll_reg2_val );
1464
1450
1465
1451
/*
1466
1452
* Compute PLL output frequency as follow:
@@ -1472,7 +1458,7 @@ static u64 mlxbf_calculate_freq_from_yu(struct mlxbf_i2c_resource *corepll_res)
1472
1458
* Where PLL_OUT_FREQ and PLL_IN_FREQ refer to CoreFrequency
1473
1459
* and PadFrequency, respectively.
1474
1460
*/
1475
- corepll_frequency = (pad_frequency * core_f ) / MLNXBF_I2C_COREPLL_CONST ;
1461
+ corepll_frequency = (MLXBF_I2C_PLL_IN_FREQ * core_f ) / MLNXBF_I2C_COREPLL_CONST ;
1476
1462
corepll_frequency /= (++ core_r ) * (++ core_od );
1477
1463
1478
1464
return corepll_frequency ;
@@ -2180,14 +2166,14 @@ static struct mlxbf_i2c_chip_info mlxbf_i2c_chip[] = {
2180
2166
[1 ] = & mlxbf_i2c_corepll_res [MLXBF_I2C_CHIP_TYPE_1 ],
2181
2167
[2 ] = & mlxbf_i2c_gpio_res [MLXBF_I2C_CHIP_TYPE_1 ]
2182
2168
},
2183
- .calculate_freq = mlxbf_calculate_freq_from_tyu
2169
+ .calculate_freq = mlxbf_i2c_calculate_freq_from_tyu
2184
2170
},
2185
2171
[MLXBF_I2C_CHIP_TYPE_2 ] = {
2186
2172
.type = MLXBF_I2C_CHIP_TYPE_2 ,
2187
2173
.shared_res = {
2188
2174
[0 ] = & mlxbf_i2c_corepll_res [MLXBF_I2C_CHIP_TYPE_2 ]
2189
2175
},
2190
- .calculate_freq = mlxbf_calculate_freq_from_yu
2176
+ .calculate_freq = mlxbf_i2c_calculate_freq_from_yu
2191
2177
}
2192
2178
};
2193
2179
0 commit comments