Skip to content

Commit 03240f8

Browse files
Suneel GarapatiAndi Shyti
authored andcommitted
i2c: thunderx: Support for High speed mode
To support bus operations for high speed bus frequencies greater than 400KHZ following control bits need to be setup accordingly - hs_mode (bit 0) field in Mode register to switch controller between low-speed and high-speed frequency operating mode. - Setup clock divisors for desired TWSI bus frequency using FOSCL output frequency divisor (D): 0 - sets the divisor to 10 for low speed mode 1 - sets the divisor to 15 for high speed mode. The TWSI bus output frequency, in master mode is based on: TCLK = 100MHz / (THP + 2) FOSCL = FSAMP / (M+1)×D = TCLK / (2 ^ N × (M + 1) × 15) FSAMP = TCLK / 2 ^ N where, N is <2:0> and M is <6:3> of TWSI Clock Control Register D is 10 for low speed or 15 for HS_MODE With high speed mode support, HLC mode usage is limited to low speed frequency (<=400KHz) bus transfers in hardware. Signed-off-by: Suneel Garapati <sgarapati@marvell.com> Signed-off-by: Piyush Malgujar <pmalgujar@marvell.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
1 parent 114c69f commit 03240f8

3 files changed

Lines changed: 54 additions & 25 deletions

File tree

drivers/i2c/busses/i2c-octeon-core.c

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -612,25 +612,27 @@ int octeon_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
612612
struct octeon_i2c *i2c = i2c_get_adapdata(adap);
613613
int i, ret = 0;
614614

615-
if (num == 1) {
616-
if (msgs[0].len > 0 && msgs[0].len <= 8) {
617-
if (msgs[0].flags & I2C_M_RD)
618-
ret = octeon_i2c_hlc_read(i2c, msgs);
619-
else
620-
ret = octeon_i2c_hlc_write(i2c, msgs);
621-
goto out;
622-
}
623-
} else if (num == 2) {
624-
if ((msgs[0].flags & I2C_M_RD) == 0 &&
625-
(msgs[1].flags & I2C_M_RECV_LEN) == 0 &&
626-
msgs[0].len > 0 && msgs[0].len <= 2 &&
627-
msgs[1].len > 0 && msgs[1].len <= 8 &&
628-
msgs[0].addr == msgs[1].addr) {
629-
if (msgs[1].flags & I2C_M_RD)
630-
ret = octeon_i2c_hlc_comp_read(i2c, msgs);
631-
else
632-
ret = octeon_i2c_hlc_comp_write(i2c, msgs);
633-
goto out;
615+
if (IS_LS_FREQ(i2c->twsi_freq)) {
616+
if (num == 1) {
617+
if (msgs[0].len > 0 && msgs[0].len <= 8) {
618+
if (msgs[0].flags & I2C_M_RD)
619+
ret = octeon_i2c_hlc_read(i2c, msgs);
620+
else
621+
ret = octeon_i2c_hlc_write(i2c, msgs);
622+
goto out;
623+
}
624+
} else if (num == 2) {
625+
if ((msgs[0].flags & I2C_M_RD) == 0 &&
626+
(msgs[1].flags & I2C_M_RECV_LEN) == 0 &&
627+
msgs[0].len > 0 && msgs[0].len <= 2 &&
628+
msgs[1].len > 0 && msgs[1].len <= 8 &&
629+
msgs[0].addr == msgs[1].addr) {
630+
if (msgs[1].flags & I2C_M_RD)
631+
ret = octeon_i2c_hlc_comp_read(i2c, msgs);
632+
else
633+
ret = octeon_i2c_hlc_comp_write(i2c, msgs);
634+
goto out;
635+
}
634636
}
635637
}
636638

@@ -664,19 +666,24 @@ void octeon_i2c_set_clock(struct octeon_i2c *i2c)
664666
{
665667
int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff;
666668
bool is_plat_otx2;
667-
unsigned int mdiv_min = 2;
668669
/*
669670
* Find divisors to produce target frequency, start with large delta
670-
* to cover wider range of divisors, note thp = TCLK half period.
671+
* to cover wider range of divisors, note thp = TCLK half period and
672+
* ds is OSCL output frequency divisor.
671673
*/
672-
unsigned int thp = TWSI_MASTER_CLK_REG_DEF_VAL, mdiv = 2, ndiv = 0;
674+
unsigned int thp, mdiv_min, mdiv = 2, ndiv = 0, ds = 10;
673675
unsigned int delta_hz = INITIAL_DELTA_HZ;
674676

675677
is_plat_otx2 = octeon_i2c_is_otx2(to_pci_dev(i2c->dev));
676678

677679
if (is_plat_otx2) {
678680
thp = TWSI_MASTER_CLK_REG_OTX2_VAL;
679681
mdiv_min = 0;
682+
if (!IS_LS_FREQ(i2c->twsi_freq))
683+
ds = 15;
684+
} else {
685+
thp = TWSI_MASTER_CLK_REG_DEF_VAL;
686+
mdiv_min = 2;
680687
}
681688

682689
for (ndiv_idx = 0; ndiv_idx < 8 && delta_hz != 0; ndiv_idx++) {
@@ -689,7 +696,7 @@ void octeon_i2c_set_clock(struct octeon_i2c *i2c)
689696
* For given ndiv and mdiv values check the
690697
* two closest thp values.
691698
*/
692-
tclk = i2c->twsi_freq * (mdiv_idx + 1) * 10;
699+
tclk = i2c->twsi_freq * (mdiv_idx + 1) * ds;
693700
tclk *= (1 << ndiv_idx);
694701
if (is_plat_otx2)
695702
thp_base = (i2c->sys_freq / tclk) - 2;
@@ -707,7 +714,9 @@ void octeon_i2c_set_clock(struct octeon_i2c *i2c)
707714
foscl = i2c->sys_freq /
708715
(2 * (thp_idx + 1));
709716
foscl = foscl / (1 << ndiv_idx);
710-
foscl = foscl / (mdiv_idx + 1) / 10;
717+
foscl = foscl / (mdiv_idx + 1) / ds;
718+
if (foscl > i2c->twsi_freq)
719+
continue;
711720
diff = abs(foscl - i2c->twsi_freq);
712721
/*
713722
* Diff holds difference between calculated frequency
@@ -725,6 +734,17 @@ void octeon_i2c_set_clock(struct octeon_i2c *i2c)
725734
}
726735
octeon_i2c_reg_write(i2c, SW_TWSI_OP_TWSI_CLK, thp);
727736
octeon_i2c_reg_write(i2c, SW_TWSI_EOP_TWSI_CLKCTL, (mdiv << 3) | ndiv);
737+
if (is_plat_otx2) {
738+
u64 mode;
739+
740+
mode = __raw_readq(i2c->twsi_base + MODE(i2c));
741+
/* Set REFCLK_SRC and HS_MODE in TWSX_MODE register */
742+
if (!IS_LS_FREQ(i2c->twsi_freq))
743+
mode |= TWSX_MODE_HS_MASK;
744+
else
745+
mode &= ~TWSX_MODE_HS_MASK;
746+
octeon_i2c_writeq_flush(mode, i2c->twsi_base + MODE(i2c));
747+
}
728748
}
729749

730750
int octeon_i2c_init_lowlevel(struct octeon_i2c *i2c)

drivers/i2c/busses/i2c-octeon-core.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,18 @@ struct octeon_i2c_reg_offset {
9494
unsigned int sw_twsi;
9595
unsigned int twsi_int;
9696
unsigned int sw_twsi_ext;
97+
unsigned int mode;
9798
};
9899

99100
#define SW_TWSI(x) (x->roff.sw_twsi)
100101
#define TWSI_INT(x) (x->roff.twsi_int)
101102
#define SW_TWSI_EXT(x) (x->roff.sw_twsi_ext)
103+
#define MODE(x) ((x)->roff.mode)
104+
105+
/* Set REFCLK_SRC and HS_MODE in TWSX_MODE register */
106+
#define TWSX_MODE_REFCLK_SRC BIT(4)
107+
#define TWSX_MODE_HS_MODE BIT(0)
108+
#define TWSX_MODE_HS_MASK (TWSX_MODE_REFCLK_SRC | TWSX_MODE_HS_MODE)
102109

103110
struct octeon_i2c {
104111
wait_queue_head_t queue;
@@ -213,6 +220,7 @@ static inline void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data)
213220
octeon_i2c_writeq_flush(data, i2c->twsi_base + TWSI_INT(i2c));
214221
}
215222

223+
#define IS_LS_FREQ(twsi_freq) ((twsi_freq) <= 400000)
216224
#define PCI_SUBSYS_DEVID_9XXX 0xB
217225
#define PCI_SUBSYS_MASK GENMASK(15, 12)
218226
/**

drivers/i2c/busses/i2c-thunderx-pcidrv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
166166
i2c->roff.sw_twsi = 0x1000;
167167
i2c->roff.twsi_int = 0x1010;
168168
i2c->roff.sw_twsi_ext = 0x1018;
169+
i2c->roff.mode = 0x1038;
169170

170171
i2c->dev = dev;
171172
pci_set_drvdata(pdev, i2c);
@@ -210,7 +211,7 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev,
210211
* For OcteonTX2 chips, set reference frequency to 100MHz
211212
* as refclk_src in TWSI_MODE register defaults to 100MHz.
212213
*/
213-
if (octeon_i2c_is_otx2(pdev))
214+
if (octeon_i2c_is_otx2(pdev) && IS_LS_FREQ(i2c->twsi_freq))
214215
i2c->sys_freq = OTX2_REF_FREQ_DEFAULT;
215216
octeon_i2c_set_clock(i2c);
216217

0 commit comments

Comments
 (0)