/* * __lsdc_gpio_i2c_set - set the state of a gpio pin indicated by mask * @mask: gpio pin mask * @state: "0" for low, "1" for high
*/ staticvoid __lsdc_gpio_i2c_set(struct lsdc_i2c * const li2c, int mask, int state)
{ struct lsdc_device *ldev = to_lsdc(li2c->ddev); unsignedlong flags;
u8 val;
spin_lock_irqsave(&ldev->reglock, flags);
if (state) { /* * Setting this pin as input directly, write 1 for input. * The external pull-up resistor will pull the level up
*/
val = readb(li2c->dir_reg);
val |= mask;
writeb(val, li2c->dir_reg);
} else { /* First set this pin as output, write 0 for output */
val = readb(li2c->dir_reg);
val &= ~mask;
writeb(val, li2c->dir_reg);
/* Then, make this pin output 0 */
val = readb(li2c->dat_reg);
val &= ~mask;
writeb(val, li2c->dat_reg);
}
spin_unlock_irqrestore(&ldev->reglock, flags);
}
/* * __lsdc_gpio_i2c_get - read value back from the gpio pin indicated by mask * @mask: gpio pin mask * return "0" for low, "1" for high
*/ staticint __lsdc_gpio_i2c_get(struct lsdc_i2c * const li2c, int mask)
{ struct lsdc_device *ldev = to_lsdc(li2c->ddev); unsignedlong flags;
u8 val;
spin_lock_irqsave(&ldev->reglock, flags);
/* First set this pin as input */
val = readb(li2c->dir_reg);
val |= mask;
writeb(val, li2c->dir_reg);
/* Then get level state from this pin */
val = readb(li2c->dat_reg);
spin_unlock_irqrestore(&ldev->reglock, flags);
return (val & mask) ? 1 : 0;
}
staticvoid lsdc_gpio_i2c_set_sda(void *i2c, int state)
{ struct lsdc_i2c * const li2c = (struct lsdc_i2c *)i2c; /* set state on the li2c->sda pin */ return __lsdc_gpio_i2c_set(li2c, li2c->sda, state);
}
staticvoid lsdc_gpio_i2c_set_scl(void *i2c, int state)
{ struct lsdc_i2c * const li2c = (struct lsdc_i2c *)i2c; /* set state on the li2c->scl pin */ return __lsdc_gpio_i2c_set(li2c, li2c->scl, state);
}
staticint lsdc_gpio_i2c_get_sda(void *i2c)
{ struct lsdc_i2c * const li2c = (struct lsdc_i2c *)i2c; /* read value from the li2c->sda pin */ return __lsdc_gpio_i2c_get(li2c, li2c->sda);
}
staticint lsdc_gpio_i2c_get_scl(void *i2c)
{ struct lsdc_i2c * const li2c = (struct lsdc_i2c *)i2c; /* read the value from the li2c->scl pin */ return __lsdc_gpio_i2c_get(li2c, li2c->scl);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.