diff options
author | Jonathan Corbet <corbet@lwn.net> | 2010-04-22 16:36:04 -0400 |
---|---|---|
committer | Jonathan Corbet <corbet@lwn.net> | 2010-05-07 19:16:03 -0400 |
commit | 75b035ace904761b8a340b524533a36e37313b29 (patch) | |
tree | 557cb425b40aeb71c5064529a5fbae5c7aa32ffc /drivers/video/via | |
parent | c389874805a6849e3e347fc0e13fa170d80840c1 (diff) |
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>
Diffstat (limited to 'drivers/video/via')
-rw-r--r-- | drivers/video/via/via-core.c | 2 | ||||
-rw-r--r-- | drivers/video/via/via-gpio.c | 14 | ||||
-rw-r--r-- | drivers/video/via/via_i2c.c | 46 | ||||
-rw-r--r-- | drivers/video/via/via_i2c.h | 2 |
4 files changed, 38 insertions, 26 deletions
diff --git a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c index 806237e8b4a4..a1b5dae285a4 100644 --- a/drivers/video/via/via-core.c +++ b/drivers/video/via/via-core.c | |||
@@ -213,7 +213,7 @@ static int __devinit via_pci_probe(struct pci_dev *pdev, | |||
213 | * Create the I2C busses. Bailing out on failure seems extreme, | 213 | * Create the I2C busses. Bailing out on failure seems extreme, |
214 | * but that's what the code did before. | 214 | * but that's what the code did before. |
215 | */ | 215 | */ |
216 | ret = viafb_create_i2c_busses(adap_configs); | 216 | ret = viafb_create_i2c_busses(&global_dev, adap_configs); |
217 | if (ret) | 217 | if (ret) |
218 | goto out_teardown; | 218 | goto out_teardown; |
219 | /* | 219 | /* |
diff --git a/drivers/video/via/via-gpio.c b/drivers/video/via/via-gpio.c index e119d2103730..6b361177bf03 100644 --- a/drivers/video/via/via-gpio.c +++ b/drivers/video/via/via-gpio.c | |||
@@ -91,13 +91,13 @@ static void via_gpio_set(struct gpio_chip *chip, unsigned int nr, | |||
91 | 91 | ||
92 | spin_lock_irqsave(&cfg->vdev->reg_lock, flags); | 92 | spin_lock_irqsave(&cfg->vdev->reg_lock, flags); |
93 | gpio = cfg->active_gpios[nr]; | 93 | gpio = cfg->active_gpios[nr]; |
94 | reg = viafb_read_reg(VIASR, gpio->vg_port_index); | 94 | reg = via_read_reg(VIASR, gpio->vg_port_index); |
95 | reg |= 0x40 << gpio->vg_mask_shift; /* output enable */ | 95 | reg |= 0x40 << gpio->vg_mask_shift; /* output enable */ |
96 | if (value) | 96 | if (value) |
97 | reg |= 0x10 << gpio->vg_mask_shift; | 97 | reg |= 0x10 << gpio->vg_mask_shift; |
98 | else | 98 | else |
99 | reg &= ~(0x10 << gpio->vg_mask_shift); | 99 | reg &= ~(0x10 << gpio->vg_mask_shift); |
100 | viafb_write_reg(gpio->vg_port_index, VIASR, reg); | 100 | via_write_reg(VIASR, gpio->vg_port_index, reg); |
101 | spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags); | 101 | spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags); |
102 | } | 102 | } |
103 | 103 | ||
@@ -122,8 +122,8 @@ static int via_gpio_dir_input(struct gpio_chip *chip, unsigned int nr) | |||
122 | 122 | ||
123 | spin_lock_irqsave(&cfg->vdev->reg_lock, flags); | 123 | spin_lock_irqsave(&cfg->vdev->reg_lock, flags); |
124 | gpio = cfg->active_gpios[nr]; | 124 | gpio = cfg->active_gpios[nr]; |
125 | viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0, | 125 | via_write_reg_mask(VIASR, gpio->vg_port_index, 0, |
126 | 0x40 << gpio->vg_mask_shift); | 126 | 0x40 << gpio->vg_mask_shift); |
127 | spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags); | 127 | spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags); |
128 | return 0; | 128 | return 0; |
129 | } | 129 | } |
@@ -139,7 +139,7 @@ static int via_gpio_get(struct gpio_chip *chip, unsigned int nr) | |||
139 | 139 | ||
140 | spin_lock_irqsave(&cfg->vdev->reg_lock, flags); | 140 | spin_lock_irqsave(&cfg->vdev->reg_lock, flags); |
141 | gpio = cfg->active_gpios[nr]; | 141 | gpio = cfg->active_gpios[nr]; |
142 | reg = viafb_read_reg(VIASR, gpio->vg_port_index); | 142 | reg = via_read_reg(VIASR, gpio->vg_port_index); |
143 | spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags); | 143 | spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags); |
144 | return reg & (0x04 << gpio->vg_mask_shift); | 144 | return reg & (0x04 << gpio->vg_mask_shift); |
145 | } | 145 | } |
@@ -164,12 +164,12 @@ static struct viafb_gpio_cfg gpio_config = { | |||
164 | */ | 164 | */ |
165 | static void viafb_gpio_enable(struct viafb_gpio *gpio) | 165 | static void viafb_gpio_enable(struct viafb_gpio *gpio) |
166 | { | 166 | { |
167 | viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0x02, 0x02); | 167 | via_write_reg_mask(VIASR, gpio->vg_port_index, 0x02, 0x02); |
168 | } | 168 | } |
169 | 169 | ||
170 | static void viafb_gpio_disable(struct viafb_gpio *gpio) | 170 | static void viafb_gpio_disable(struct viafb_gpio *gpio) |
171 | { | 171 | { |
172 | viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0, 0x02); | 172 | via_write_reg_mask(VIASR, gpio->vg_port_index, 0, 0x02); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
diff --git a/drivers/video/via/via_i2c.c b/drivers/video/via/via_i2c.c index bcf2fe61a6ec..116fd3e62934 100644 --- a/drivers/video/via/via_i2c.c +++ b/drivers/video/via/via_i2c.c | |||
@@ -29,14 +29,16 @@ | |||
29 | */ | 29 | */ |
30 | #define VIAFB_NUM_I2C 5 | 30 | #define VIAFB_NUM_I2C 5 |
31 | static struct via_i2c_stuff via_i2c_par[VIAFB_NUM_I2C]; | 31 | static struct via_i2c_stuff via_i2c_par[VIAFB_NUM_I2C]; |
32 | struct viafb_dev *i2c_vdev; /* Passed in from core */ | ||
32 | 33 | ||
33 | static void via_i2c_setscl(void *data, int state) | 34 | static void via_i2c_setscl(void *data, int state) |
34 | { | 35 | { |
35 | u8 val; | 36 | u8 val; |
36 | struct via_port_cfg *adap_data = data; | 37 | struct via_port_cfg *adap_data = data; |
38 | unsigned long flags; | ||
37 | 39 | ||
38 | val = viafb_read_reg(adap_data->io_port, | 40 | spin_lock_irqsave(&i2c_vdev->reg_lock, flags); |
39 | adap_data->ioport_index) & 0xF0; | 41 | val = via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0xF0; |
40 | if (state) | 42 | if (state) |
41 | val |= 0x20; | 43 | val |= 0x20; |
42 | else | 44 | else |
@@ -51,35 +53,44 @@ static void via_i2c_setscl(void *data, int state) | |||
51 | default: | 53 | default: |
52 | DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n"); | 54 | DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n"); |
53 | } | 55 | } |
54 | viafb_write_reg(adap_data->ioport_index, | 56 | via_write_reg(adap_data->io_port, adap_data->ioport_index, val); |
55 | adap_data->io_port, val); | 57 | spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags); |
56 | } | 58 | } |
57 | 59 | ||
58 | static int via_i2c_getscl(void *data) | 60 | static int via_i2c_getscl(void *data) |
59 | { | 61 | { |
60 | struct via_port_cfg *adap_data = data; | 62 | struct via_port_cfg *adap_data = data; |
61 | 63 | unsigned long flags; | |
62 | if (viafb_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x08) | 64 | int ret = 0; |
63 | return 1; | 65 | |
64 | return 0; | 66 | spin_lock_irqsave(&i2c_vdev->reg_lock, flags); |
67 | if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x08) | ||
68 | ret = 1; | ||
69 | spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags); | ||
70 | return ret; | ||
65 | } | 71 | } |
66 | 72 | ||
67 | static int via_i2c_getsda(void *data) | 73 | static int via_i2c_getsda(void *data) |
68 | { | 74 | { |
69 | struct via_port_cfg *adap_data = data; | 75 | struct via_port_cfg *adap_data = data; |
70 | 76 | unsigned long flags; | |
71 | if (viafb_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x04) | 77 | int ret = 0; |
72 | return 1; | 78 | |
73 | return 0; | 79 | spin_lock_irqsave(&i2c_vdev->reg_lock, flags); |
80 | if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x04) | ||
81 | ret = 1; | ||
82 | spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags); | ||
83 | return ret; | ||
74 | } | 84 | } |
75 | 85 | ||
76 | static void via_i2c_setsda(void *data, int state) | 86 | static void via_i2c_setsda(void *data, int state) |
77 | { | 87 | { |
78 | u8 val; | 88 | u8 val; |
79 | struct via_port_cfg *adap_data = data; | 89 | struct via_port_cfg *adap_data = data; |
90 | unsigned long flags; | ||
80 | 91 | ||
81 | val = viafb_read_reg(adap_data->io_port, | 92 | spin_lock_irqsave(&i2c_vdev->reg_lock, flags); |
82 | adap_data->ioport_index) & 0xF0; | 93 | val = via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0xF0; |
83 | if (state) | 94 | if (state) |
84 | val |= 0x10; | 95 | val |= 0x10; |
85 | else | 96 | else |
@@ -94,8 +105,8 @@ static void via_i2c_setsda(void *data, int state) | |||
94 | default: | 105 | default: |
95 | DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n"); | 106 | DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n"); |
96 | } | 107 | } |
97 | viafb_write_reg(adap_data->ioport_index, | 108 | via_write_reg(adap_data->io_port, adap_data->ioport_index, val); |
98 | adap_data->io_port, val); | 109 | spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags); |
99 | } | 110 | } |
100 | 111 | ||
101 | int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata) | 112 | 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, | |||
174 | return i2c_bit_add_bus(adapter); | 185 | return i2c_bit_add_bus(adapter); |
175 | } | 186 | } |
176 | 187 | ||
177 | int viafb_create_i2c_busses(struct via_port_cfg *configs) | 188 | int viafb_create_i2c_busses(struct viafb_dev *dev, struct via_port_cfg *configs) |
178 | { | 189 | { |
179 | int i, ret; | 190 | int i, ret; |
180 | 191 | ||
192 | i2c_vdev = dev; | ||
181 | for (i = 0; i < VIAFB_NUM_PORTS; i++) { | 193 | for (i = 0; i < VIAFB_NUM_PORTS; i++) { |
182 | struct via_port_cfg *adap_cfg = configs++; | 194 | struct via_port_cfg *adap_cfg = configs++; |
183 | struct via_i2c_stuff *i2c_stuff = &via_i2c_par[i]; | 195 | struct via_i2c_stuff *i2c_stuff = &via_i2c_par[i]; |
diff --git a/drivers/video/via/via_i2c.h b/drivers/video/via/via_i2c.h index 00932914b4ed..0685de9a0c7a 100644 --- a/drivers/video/via/via_i2c.h +++ b/drivers/video/via/via_i2c.h | |||
@@ -36,7 +36,7 @@ int viafb_i2c_writebyte(u8 adap, u8 slave_addr, u8 index, u8 data); | |||
36 | int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len); | 36 | int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len); |
37 | 37 | ||
38 | struct viafb_par; | 38 | struct viafb_par; |
39 | int viafb_create_i2c_busses(struct via_port_cfg *cfg); | 39 | int viafb_create_i2c_busses(struct viafb_dev *vdev, struct via_port_cfg *cfg); |
40 | void viafb_delete_i2c_busses(void); | 40 | void viafb_delete_i2c_busses(void); |
41 | struct i2c_adapter *viafb_find_adapter(enum viafb_i2c_adap which); | 41 | struct i2c_adapter *viafb_find_adapter(enum viafb_i2c_adap which); |
42 | #endif /* __VIA_I2C_H__ */ | 42 | #endif /* __VIA_I2C_H__ */ |