forked from Minki/linux
viafb: Convert GPIO and i2c to the new indexed port ops
Also add low-level locking to the i2c driver. Signed-off-by: Jonathan Corbet <corbet@lwn.net>
This commit is contained in:
parent
c389874805
commit
75b035ace9
@ -213,7 +213,7 @@ static int __devinit via_pci_probe(struct pci_dev *pdev,
|
|||||||
* Create the I2C busses. Bailing out on failure seems extreme,
|
* Create the I2C busses. Bailing out on failure seems extreme,
|
||||||
* but that's what the code did before.
|
* but that's what the code did before.
|
||||||
*/
|
*/
|
||||||
ret = viafb_create_i2c_busses(adap_configs);
|
ret = viafb_create_i2c_busses(&global_dev, adap_configs);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
/*
|
/*
|
||||||
|
@ -91,13 +91,13 @@ static void via_gpio_set(struct gpio_chip *chip, unsigned int nr,
|
|||||||
|
|
||||||
spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
|
spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
|
||||||
gpio = cfg->active_gpios[nr];
|
gpio = cfg->active_gpios[nr];
|
||||||
reg = viafb_read_reg(VIASR, gpio->vg_port_index);
|
reg = via_read_reg(VIASR, gpio->vg_port_index);
|
||||||
reg |= 0x40 << gpio->vg_mask_shift; /* output enable */
|
reg |= 0x40 << gpio->vg_mask_shift; /* output enable */
|
||||||
if (value)
|
if (value)
|
||||||
reg |= 0x10 << gpio->vg_mask_shift;
|
reg |= 0x10 << gpio->vg_mask_shift;
|
||||||
else
|
else
|
||||||
reg &= ~(0x10 << gpio->vg_mask_shift);
|
reg &= ~(0x10 << gpio->vg_mask_shift);
|
||||||
viafb_write_reg(gpio->vg_port_index, VIASR, reg);
|
via_write_reg(VIASR, gpio->vg_port_index, reg);
|
||||||
spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
|
spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,8 +122,8 @@ static int via_gpio_dir_input(struct gpio_chip *chip, unsigned int nr)
|
|||||||
|
|
||||||
spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
|
spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
|
||||||
gpio = cfg->active_gpios[nr];
|
gpio = cfg->active_gpios[nr];
|
||||||
viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0,
|
via_write_reg_mask(VIASR, gpio->vg_port_index, 0,
|
||||||
0x40 << gpio->vg_mask_shift);
|
0x40 << gpio->vg_mask_shift);
|
||||||
spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
|
spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ static int via_gpio_get(struct gpio_chip *chip, unsigned int nr)
|
|||||||
|
|
||||||
spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
|
spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
|
||||||
gpio = cfg->active_gpios[nr];
|
gpio = cfg->active_gpios[nr];
|
||||||
reg = viafb_read_reg(VIASR, gpio->vg_port_index);
|
reg = via_read_reg(VIASR, gpio->vg_port_index);
|
||||||
spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
|
spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
|
||||||
return reg & (0x04 << gpio->vg_mask_shift);
|
return reg & (0x04 << gpio->vg_mask_shift);
|
||||||
}
|
}
|
||||||
@ -164,12 +164,12 @@ static struct viafb_gpio_cfg gpio_config = {
|
|||||||
*/
|
*/
|
||||||
static void viafb_gpio_enable(struct viafb_gpio *gpio)
|
static void viafb_gpio_enable(struct viafb_gpio *gpio)
|
||||||
{
|
{
|
||||||
viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0x02, 0x02);
|
via_write_reg_mask(VIASR, gpio->vg_port_index, 0x02, 0x02);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void viafb_gpio_disable(struct viafb_gpio *gpio)
|
static void viafb_gpio_disable(struct viafb_gpio *gpio)
|
||||||
{
|
{
|
||||||
viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0, 0x02);
|
via_write_reg_mask(VIASR, gpio->vg_port_index, 0, 0x02);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,14 +29,16 @@
|
|||||||
*/
|
*/
|
||||||
#define VIAFB_NUM_I2C 5
|
#define VIAFB_NUM_I2C 5
|
||||||
static struct via_i2c_stuff via_i2c_par[VIAFB_NUM_I2C];
|
static struct via_i2c_stuff via_i2c_par[VIAFB_NUM_I2C];
|
||||||
|
struct viafb_dev *i2c_vdev; /* Passed in from core */
|
||||||
|
|
||||||
static void via_i2c_setscl(void *data, int state)
|
static void via_i2c_setscl(void *data, int state)
|
||||||
{
|
{
|
||||||
u8 val;
|
u8 val;
|
||||||
struct via_port_cfg *adap_data = data;
|
struct via_port_cfg *adap_data = data;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
val = viafb_read_reg(adap_data->io_port,
|
spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
|
||||||
adap_data->ioport_index) & 0xF0;
|
val = via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0xF0;
|
||||||
if (state)
|
if (state)
|
||||||
val |= 0x20;
|
val |= 0x20;
|
||||||
else
|
else
|
||||||
@ -51,35 +53,44 @@ static void via_i2c_setscl(void *data, int state)
|
|||||||
default:
|
default:
|
||||||
DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
|
DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
|
||||||
}
|
}
|
||||||
viafb_write_reg(adap_data->ioport_index,
|
via_write_reg(adap_data->io_port, adap_data->ioport_index, val);
|
||||||
adap_data->io_port, val);
|
spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int via_i2c_getscl(void *data)
|
static int via_i2c_getscl(void *data)
|
||||||
{
|
{
|
||||||
struct via_port_cfg *adap_data = data;
|
struct via_port_cfg *adap_data = data;
|
||||||
|
unsigned long flags;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (viafb_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x08)
|
spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
|
||||||
return 1;
|
if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x08)
|
||||||
return 0;
|
ret = 1;
|
||||||
|
spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int via_i2c_getsda(void *data)
|
static int via_i2c_getsda(void *data)
|
||||||
{
|
{
|
||||||
struct via_port_cfg *adap_data = data;
|
struct via_port_cfg *adap_data = data;
|
||||||
|
unsigned long flags;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (viafb_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x04)
|
spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
|
||||||
return 1;
|
if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x04)
|
||||||
return 0;
|
ret = 1;
|
||||||
|
spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void via_i2c_setsda(void *data, int state)
|
static void via_i2c_setsda(void *data, int state)
|
||||||
{
|
{
|
||||||
u8 val;
|
u8 val;
|
||||||
struct via_port_cfg *adap_data = data;
|
struct via_port_cfg *adap_data = data;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
val = viafb_read_reg(adap_data->io_port,
|
spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
|
||||||
adap_data->ioport_index) & 0xF0;
|
val = via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0xF0;
|
||||||
if (state)
|
if (state)
|
||||||
val |= 0x10;
|
val |= 0x10;
|
||||||
else
|
else
|
||||||
@ -94,8 +105,8 @@ static void via_i2c_setsda(void *data, int state)
|
|||||||
default:
|
default:
|
||||||
DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
|
DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
|
||||||
}
|
}
|
||||||
viafb_write_reg(adap_data->ioport_index,
|
via_write_reg(adap_data->io_port, adap_data->ioport_index, val);
|
||||||
adap_data->io_port, val);
|
spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata)
|
int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata)
|
||||||
@ -174,10 +185,11 @@ static int create_i2c_bus(struct i2c_adapter *adapter,
|
|||||||
return i2c_bit_add_bus(adapter);
|
return i2c_bit_add_bus(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int viafb_create_i2c_busses(struct via_port_cfg *configs)
|
int viafb_create_i2c_busses(struct viafb_dev *dev, struct via_port_cfg *configs)
|
||||||
{
|
{
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
|
i2c_vdev = dev;
|
||||||
for (i = 0; i < VIAFB_NUM_PORTS; i++) {
|
for (i = 0; i < VIAFB_NUM_PORTS; i++) {
|
||||||
struct via_port_cfg *adap_cfg = configs++;
|
struct via_port_cfg *adap_cfg = configs++;
|
||||||
struct via_i2c_stuff *i2c_stuff = &via_i2c_par[i];
|
struct via_i2c_stuff *i2c_stuff = &via_i2c_par[i];
|
||||||
|
@ -36,7 +36,7 @@ int viafb_i2c_writebyte(u8 adap, u8 slave_addr, u8 index, u8 data);
|
|||||||
int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len);
|
int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len);
|
||||||
|
|
||||||
struct viafb_par;
|
struct viafb_par;
|
||||||
int viafb_create_i2c_busses(struct via_port_cfg *cfg);
|
int viafb_create_i2c_busses(struct viafb_dev *vdev, struct via_port_cfg *cfg);
|
||||||
void viafb_delete_i2c_busses(void);
|
void viafb_delete_i2c_busses(void);
|
||||||
struct i2c_adapter *viafb_find_adapter(enum viafb_i2c_adap which);
|
struct i2c_adapter *viafb_find_adapter(enum viafb_i2c_adap which);
|
||||||
#endif /* __VIA_I2C_H__ */
|
#endif /* __VIA_I2C_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user