mirror of
https://github.com/edk2-porting/linux-next.git
synced 2025-01-17 18:14:34 +08:00
i2c: Blackfin TWI: make sure we don't end up with a CLKDIV=0
Make sure we don't end up with an invalid CLKDIV=0 in case someone specifies 20kHz SCL or less (5 * 1024 / 20 = 0x100). Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Bryan Wu <cooloney@kernel.org> [ben-linux@fluff.org: shortened subject line] Signed-off-by: Ben Dooks <ben-linux@fluff.org>
This commit is contained in:
parent
f3ad116588
commit
9528d1c7a5
@ -298,7 +298,7 @@ config I2C_BLACKFIN_TWI
|
|||||||
config I2C_BLACKFIN_TWI_CLK_KHZ
|
config I2C_BLACKFIN_TWI_CLK_KHZ
|
||||||
int "Blackfin TWI I2C clock (kHz)"
|
int "Blackfin TWI I2C clock (kHz)"
|
||||||
depends on I2C_BLACKFIN_TWI
|
depends on I2C_BLACKFIN_TWI
|
||||||
range 10 400
|
range 21 400
|
||||||
default 50
|
default 50
|
||||||
help
|
help
|
||||||
The unit of the TWI clock is kHz.
|
The unit of the TWI clock is kHz.
|
||||||
|
@ -614,6 +614,7 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
|
|||||||
struct i2c_adapter *p_adap;
|
struct i2c_adapter *p_adap;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
int rc;
|
int rc;
|
||||||
|
unsigned int clkhilow;
|
||||||
|
|
||||||
iface = kzalloc(sizeof(struct bfin_twi_iface), GFP_KERNEL);
|
iface = kzalloc(sizeof(struct bfin_twi_iface), GFP_KERNEL);
|
||||||
if (!iface) {
|
if (!iface) {
|
||||||
@ -675,10 +676,14 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
|
|||||||
/* Set TWI internal clock as 10MHz */
|
/* Set TWI internal clock as 10MHz */
|
||||||
write_CONTROL(iface, ((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F);
|
write_CONTROL(iface, ((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We will not end up with a CLKDIV=0 because no one will specify
|
||||||
|
* 20kHz SCL or less in Kconfig now. (5 * 1024 / 20 = 0x100)
|
||||||
|
*/
|
||||||
|
clkhilow = 5 * 1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ;
|
||||||
|
|
||||||
/* Set Twi interface clock as specified */
|
/* Set Twi interface clock as specified */
|
||||||
write_CLKDIV(iface, ((5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ)
|
write_CLKDIV(iface, (clkhilow << 8) | clkhilow);
|
||||||
<< 8) | ((5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ)
|
|
||||||
& 0xFF));
|
|
||||||
|
|
||||||
/* Enable TWI */
|
/* Enable TWI */
|
||||||
write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
|
write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
|
||||||
|
Loading…
Reference in New Issue
Block a user