Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 120045
b: refs/heads/master
c: a5616bd
h: refs/heads/master
i:
  120043: de432d8
v: v3
  • Loading branch information
Magnus Damm authored and Paul Mundt committed Dec 22, 2008
1 parent 7377dac commit e183565
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f2eb0109fb4268505b0737cfe661542eb6151907
refs/heads/master: a5616bd0f19730a780c354110454ce37209f1ded
4 changes: 2 additions & 2 deletions trunk/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static struct resource iic0_resources[] = {

static struct platform_device iic0_device = {
.name = "i2c-sh_mobile",
.id = 0, /* "i2c0" clock */
.num_resources = ARRAY_SIZE(iic0_resources),
.resource = iic0_resources,
};
Expand All @@ -50,6 +51,7 @@ static struct resource iic1_resources[] = {

static struct platform_device iic1_device = {
.name = "i2c-sh_mobile",
.id = 1, /* "i2c1" clock */
.num_resources = ARRAY_SIZE(iic1_resources),
.resource = iic1_resources,
};
Expand Down Expand Up @@ -147,8 +149,6 @@ static int __init sh7343_devices_setup(void)
clk_always_enable("mstp023"); /* INTC3 */
clk_always_enable("mstp022"); /* INTC */
clk_always_enable("mstp020"); /* SuperHyway */
clk_always_enable("mstp109"); /* I2C0 */
clk_always_enable("mstp108"); /* I2C1 */
clk_always_enable("mstp202"); /* VEU */
clk_always_enable("mstp201"); /* VPU */

Expand Down
2 changes: 1 addition & 1 deletion trunk/arch/sh/kernel/cpu/sh4a/setup-sh7366.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static struct resource iic_resources[] = {

static struct platform_device iic_device = {
.name = "i2c-sh_mobile",
.id = 0, /* "i2c0" clock */
.num_resources = ARRAY_SIZE(iic_resources),
.resource = iic_resources,
};
Expand Down Expand Up @@ -184,7 +185,6 @@ static int __init sh7366_devices_setup(void)
clk_always_enable("mstp023"); /* INTC3 */
clk_always_enable("mstp022"); /* INTC */
clk_always_enable("mstp020"); /* SuperHyway */
clk_always_enable("mstp109"); /* I2C */
clk_always_enable("mstp211"); /* USB */
clk_always_enable("mstp207"); /* VEU-2 */
clk_always_enable("mstp202"); /* VEU-1 */
Expand Down
2 changes: 1 addition & 1 deletion trunk/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static struct resource iic_resources[] = {

static struct platform_device iic_device = {
.name = "i2c-sh_mobile",
.id = 0, /* "i2c0" clock */
.num_resources = ARRAY_SIZE(iic_resources),
.resource = iic_resources,
};
Expand Down Expand Up @@ -197,7 +198,6 @@ static int __init sh7722_devices_setup(void)
clk_always_enable("mstp026"); /* XYMEM */
clk_always_enable("mstp022"); /* INTC */
clk_always_enable("mstp020"); /* SuperHyway */
clk_always_enable("mstp109"); /* I2C */
clk_always_enable("mstp211"); /* USB */
clk_always_enable("mstp202"); /* VEU */
clk_always_enable("mstp201"); /* VPU */
Expand Down
2 changes: 1 addition & 1 deletion trunk/arch/sh/kernel/cpu/sh4a/setup-sh7723.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ static struct resource iic_resources[] = {

static struct platform_device iic_device = {
.name = "i2c-sh_mobile",
.id = 0, /* "i2c0" clock */
.num_resources = ARRAY_SIZE(iic_resources),
.resource = iic_resources,
};
Expand All @@ -238,7 +239,6 @@ static int __init sh7723_devices_setup(void)
clk_always_enable("mstp022"); /* INTC */
clk_always_enable("mstp020"); /* SuperHyway */
clk_always_enable("mstp000"); /* MERAM */
clk_always_enable("mstp109"); /* I2C */
clk_always_enable("mstp108"); /* RTC */
clk_always_enable("mstp211"); /* USB */
clk_always_enable("mstp206"); /* VEU2H1 */
Expand Down
73 changes: 36 additions & 37 deletions trunk/drivers/i2c/busses/i2c-sh_mobile.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,39 @@ struct sh_mobile_i2c_data {

static void activate_ch(struct sh_mobile_i2c_data *pd)
{
unsigned long i2c_clk;
u_int32_t num;
u_int32_t denom;
u_int32_t tmp;

/* Make sure the clock is enabled */
clk_enable(pd->clk);

/* Get clock rate after clock is enabled */
i2c_clk = clk_get_rate(pd->clk);

/* Calculate the value for iccl. From the data sheet:
* iccl = (p clock / transfer rate) * (L / (L + H))
* where L and H are the SCL low/high ratio (5/4 in this case).
* We also round off the result.
*/
num = i2c_clk * 5;
denom = NORMAL_SPEED * 9;
tmp = num * 10 / denom;
if (tmp % 10 >= 5)
pd->iccl = (u_int8_t)((num/denom) + 1);
else
pd->iccl = (u_int8_t)(num/denom);

/* Calculate the value for icch. From the data sheet:
icch = (p clock / transfer rate) * (H / (L + H)) */
num = i2c_clk * 4;
tmp = num * 10 / denom;
if (tmp % 10 >= 5)
pd->icch = (u_int8_t)((num/denom) + 1);
else
pd->icch = (u_int8_t)(num/denom);

/* Enable channel and configure rx ack */
iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd));

Expand Down Expand Up @@ -459,40 +489,6 @@ static struct i2c_algorithm sh_mobile_i2c_algorithm = {
.master_xfer = sh_mobile_i2c_xfer,
};

static void sh_mobile_i2c_setup_channel(struct platform_device *dev)
{
struct sh_mobile_i2c_data *pd = platform_get_drvdata(dev);
unsigned long peripheral_clk = clk_get_rate(pd->clk);
u_int32_t num;
u_int32_t denom;
u_int32_t tmp;

spin_lock_init(&pd->lock);
init_waitqueue_head(&pd->wait);

/* Calculate the value for iccl. From the data sheet:
* iccl = (p clock / transfer rate) * (L / (L + H))
* where L and H are the SCL low/high ratio (5/4 in this case).
* We also round off the result.
*/
num = peripheral_clk * 5;
denom = NORMAL_SPEED * 9;
tmp = num * 10 / denom;
if (tmp % 10 >= 5)
pd->iccl = (u_int8_t)((num/denom) + 1);
else
pd->iccl = (u_int8_t)(num/denom);

/* Calculate the value for icch. From the data sheet:
icch = (p clock / transfer rate) * (H / (L + H)) */
num = peripheral_clk * 4;
tmp = num * 10 / denom;
if (tmp % 10 >= 5)
pd->icch = (u_int8_t)((num/denom) + 1);
else
pd->icch = (u_int8_t)(num/denom);
}

static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
{
struct resource *res;
Expand Down Expand Up @@ -533,6 +529,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
struct sh_mobile_i2c_data *pd;
struct i2c_adapter *adap;
struct resource *res;
char clk_name[8];
int size;
int ret;

Expand All @@ -542,9 +539,10 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
return -ENOMEM;
}

pd->clk = clk_get(&dev->dev, "peripheral_clk");
snprintf(clk_name, sizeof(clk_name), "i2c%d", dev->id);
pd->clk = clk_get(&dev->dev, clk_name);
if (IS_ERR(pd->clk)) {
dev_err(&dev->dev, "cannot get peripheral clock\n");
dev_err(&dev->dev, "cannot get clock \"%s\"\n", clk_name);
ret = PTR_ERR(pd->clk);
goto err;
}
Expand Down Expand Up @@ -586,7 +584,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)

strlcpy(adap->name, dev->name, sizeof(adap->name));

sh_mobile_i2c_setup_channel(dev);
spin_lock_init(&pd->lock);
init_waitqueue_head(&pd->wait);

ret = i2c_add_numbered_adapter(adap);
if (ret < 0) {
Expand Down

0 comments on commit e183565

Please sign in to comment.