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/via_i2c.c | |
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/via_i2c.c')
-rw-r--r-- | drivers/video/via/via_i2c.c | 46 |
1 files changed, 29 insertions, 17 deletions
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]; |