diff options
Diffstat (limited to 'drivers/i2c')
| -rw-r--r-- | drivers/i2c/busses/i2c-omap.c | 14 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-pxa.c | 25 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-s3c2410.c | 25 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-stu300.c | 157 |
4 files changed, 137 insertions, 84 deletions
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c index d258b02aef44..827da0858136 100644 --- a/drivers/i2c/busses/i2c-omap.c +++ b/drivers/i2c/busses/i2c-omap.c | |||
| @@ -674,7 +674,14 @@ omap_i2c_isr(int this_irq, void *dev_id) | |||
| 674 | 674 | ||
| 675 | err = 0; | 675 | err = 0; |
| 676 | complete: | 676 | complete: |
| 677 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat); | 677 | /* |
| 678 | * Ack the stat in one go, but [R/X]DR and [R/X]RDY should be | ||
| 679 | * acked after the data operation is complete. | ||
| 680 | * Ref: TRM SWPU114Q Figure 18-31 | ||
| 681 | */ | ||
| 682 | omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat & | ||
| 683 | ~(OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR | | ||
| 684 | OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); | ||
| 678 | 685 | ||
| 679 | if (stat & OMAP_I2C_STAT_NACK) { | 686 | if (stat & OMAP_I2C_STAT_NACK) { |
| 680 | err |= OMAP_I2C_STAT_NACK; | 687 | err |= OMAP_I2C_STAT_NACK; |
| @@ -687,6 +694,9 @@ complete: | |||
| 687 | } | 694 | } |
| 688 | if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK | | 695 | if (stat & (OMAP_I2C_STAT_ARDY | OMAP_I2C_STAT_NACK | |
| 689 | OMAP_I2C_STAT_AL)) { | 696 | OMAP_I2C_STAT_AL)) { |
| 697 | omap_i2c_ack_stat(dev, stat & | ||
| 698 | (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR | | ||
| 699 | OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); | ||
| 690 | omap_i2c_complete_cmd(dev, err); | 700 | omap_i2c_complete_cmd(dev, err); |
| 691 | return IRQ_HANDLED; | 701 | return IRQ_HANDLED; |
| 692 | } | 702 | } |
| @@ -774,7 +784,7 @@ complete: | |||
| 774 | * memory to the I2C interface. | 784 | * memory to the I2C interface. |
| 775 | */ | 785 | */ |
| 776 | 786 | ||
| 777 | if (cpu_is_omap34xx()) { | 787 | if (dev->rev <= OMAP_I2C_REV_ON_3430) { |
| 778 | while (!(stat & OMAP_I2C_STAT_XUDF)) { | 788 | while (!(stat & OMAP_I2C_STAT_XUDF)) { |
| 779 | if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) { | 789 | if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) { |
| 780 | omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); | 790 | omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR)); |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index 762e1e530882..049555777f67 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
| @@ -1134,35 +1134,44 @@ static int __exit i2c_pxa_remove(struct platform_device *dev) | |||
| 1134 | } | 1134 | } |
| 1135 | 1135 | ||
| 1136 | #ifdef CONFIG_PM | 1136 | #ifdef CONFIG_PM |
| 1137 | static int i2c_pxa_suspend_late(struct platform_device *dev, pm_message_t state) | 1137 | static int i2c_pxa_suspend_noirq(struct device *dev) |
| 1138 | { | 1138 | { |
| 1139 | struct pxa_i2c *i2c = platform_get_drvdata(dev); | 1139 | struct platform_device *pdev = to_platform_device(dev); |
| 1140 | struct pxa_i2c *i2c = platform_get_drvdata(pdev); | ||
| 1141 | |||
| 1140 | clk_disable(i2c->clk); | 1142 | clk_disable(i2c->clk); |
| 1143 | |||
| 1141 | return 0; | 1144 | return 0; |
| 1142 | } | 1145 | } |
| 1143 | 1146 | ||
| 1144 | static int i2c_pxa_resume_early(struct platform_device *dev) | 1147 | static int i2c_pxa_resume_noirq(struct device *dev) |
| 1145 | { | 1148 | { |
| 1146 | struct pxa_i2c *i2c = platform_get_drvdata(dev); | 1149 | struct platform_device *pdev = to_platform_device(dev); |
| 1150 | struct pxa_i2c *i2c = platform_get_drvdata(pdev); | ||
| 1147 | 1151 | ||
| 1148 | clk_enable(i2c->clk); | 1152 | clk_enable(i2c->clk); |
| 1149 | i2c_pxa_reset(i2c); | 1153 | i2c_pxa_reset(i2c); |
| 1150 | 1154 | ||
| 1151 | return 0; | 1155 | return 0; |
| 1152 | } | 1156 | } |
| 1157 | |||
| 1158 | static struct dev_pm_ops i2c_pxa_dev_pm_ops = { | ||
| 1159 | .suspend_noirq = i2c_pxa_suspend_noirq, | ||
| 1160 | .resume_noirq = i2c_pxa_resume_noirq, | ||
| 1161 | }; | ||
| 1162 | |||
| 1163 | #define I2C_PXA_DEV_PM_OPS (&i2c_pxa_dev_pm_ops) | ||
| 1153 | #else | 1164 | #else |
| 1154 | #define i2c_pxa_suspend_late NULL | 1165 | #define I2C_PXA_DEV_PM_OPS NULL |
| 1155 | #define i2c_pxa_resume_early NULL | ||
| 1156 | #endif | 1166 | #endif |
| 1157 | 1167 | ||
| 1158 | static struct platform_driver i2c_pxa_driver = { | 1168 | static struct platform_driver i2c_pxa_driver = { |
| 1159 | .probe = i2c_pxa_probe, | 1169 | .probe = i2c_pxa_probe, |
| 1160 | .remove = __exit_p(i2c_pxa_remove), | 1170 | .remove = __exit_p(i2c_pxa_remove), |
| 1161 | .suspend_late = i2c_pxa_suspend_late, | ||
| 1162 | .resume_early = i2c_pxa_resume_early, | ||
| 1163 | .driver = { | 1171 | .driver = { |
| 1164 | .name = "pxa2xx-i2c", | 1172 | .name = "pxa2xx-i2c", |
| 1165 | .owner = THIS_MODULE, | 1173 | .owner = THIS_MODULE, |
| 1174 | .pm = I2C_PXA_DEV_PM_OPS, | ||
| 1166 | }, | 1175 | }, |
| 1167 | .id_table = i2c_pxa_id_table, | 1176 | .id_table = i2c_pxa_id_table, |
| 1168 | }; | 1177 | }; |
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 20bb0ceb027b..96aafb91b69a 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c | |||
| @@ -946,17 +946,20 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev) | |||
| 946 | } | 946 | } |
| 947 | 947 | ||
| 948 | #ifdef CONFIG_PM | 948 | #ifdef CONFIG_PM |
| 949 | static int s3c24xx_i2c_suspend_late(struct platform_device *dev, | 949 | static int s3c24xx_i2c_suspend_noirq(struct device *dev) |
| 950 | pm_message_t msg) | ||
| 951 | { | 950 | { |
| 952 | struct s3c24xx_i2c *i2c = platform_get_drvdata(dev); | 951 | struct platform_device *pdev = to_platform_device(dev); |
| 952 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); | ||
| 953 | |||
| 953 | i2c->suspended = 1; | 954 | i2c->suspended = 1; |
| 955 | |||
| 954 | return 0; | 956 | return 0; |
| 955 | } | 957 | } |
| 956 | 958 | ||
| 957 | static int s3c24xx_i2c_resume(struct platform_device *dev) | 959 | static int s3c24xx_i2c_resume(struct device *dev) |
| 958 | { | 960 | { |
| 959 | struct s3c24xx_i2c *i2c = platform_get_drvdata(dev); | 961 | struct platform_device *pdev = to_platform_device(dev); |
| 962 | struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); | ||
| 960 | 963 | ||
| 961 | i2c->suspended = 0; | 964 | i2c->suspended = 0; |
| 962 | s3c24xx_i2c_init(i2c); | 965 | s3c24xx_i2c_init(i2c); |
| @@ -964,9 +967,14 @@ static int s3c24xx_i2c_resume(struct platform_device *dev) | |||
| 964 | return 0; | 967 | return 0; |
| 965 | } | 968 | } |
| 966 | 969 | ||
| 970 | static struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = { | ||
| 971 | .suspend_noirq = s3c24xx_i2c_suspend_noirq, | ||
| 972 | .resume = s3c24xx_i2c_resume, | ||
| 973 | }; | ||
| 974 | |||
| 975 | #define S3C24XX_DEV_PM_OPS (&s3c24xx_i2c_dev_pm_ops) | ||
| 967 | #else | 976 | #else |
| 968 | #define s3c24xx_i2c_suspend_late NULL | 977 | #define S3C24XX_DEV_PM_OPS NULL |
| 969 | #define s3c24xx_i2c_resume NULL | ||
| 970 | #endif | 978 | #endif |
| 971 | 979 | ||
| 972 | /* device driver for platform bus bits */ | 980 | /* device driver for platform bus bits */ |
| @@ -985,12 +993,11 @@ MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); | |||
| 985 | static struct platform_driver s3c24xx_i2c_driver = { | 993 | static struct platform_driver s3c24xx_i2c_driver = { |
| 986 | .probe = s3c24xx_i2c_probe, | 994 | .probe = s3c24xx_i2c_probe, |
| 987 | .remove = s3c24xx_i2c_remove, | 995 | .remove = s3c24xx_i2c_remove, |
| 988 | .suspend_late = s3c24xx_i2c_suspend_late, | ||
| 989 | .resume = s3c24xx_i2c_resume, | ||
| 990 | .id_table = s3c24xx_driver_ids, | 996 | .id_table = s3c24xx_driver_ids, |
| 991 | .driver = { | 997 | .driver = { |
| 992 | .owner = THIS_MODULE, | 998 | .owner = THIS_MODULE, |
| 993 | .name = "s3c-i2c", | 999 | .name = "s3c-i2c", |
| 1000 | .pm = S3C24XX_DEV_PM_OPS, | ||
| 994 | }, | 1001 | }, |
| 995 | }; | 1002 | }; |
| 996 | 1003 | ||
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c index 182e711318ba..d2728a28a8db 100644 --- a/drivers/i2c/busses/i2c-stu300.c +++ b/drivers/i2c/busses/i2c-stu300.c | |||
| @@ -117,7 +117,8 @@ enum stu300_error { | |||
| 117 | STU300_ERROR_NONE = 0, | 117 | STU300_ERROR_NONE = 0, |
| 118 | STU300_ERROR_ACKNOWLEDGE_FAILURE, | 118 | STU300_ERROR_ACKNOWLEDGE_FAILURE, |
| 119 | STU300_ERROR_BUS_ERROR, | 119 | STU300_ERROR_BUS_ERROR, |
| 120 | STU300_ERROR_ARBITRATION_LOST | 120 | STU300_ERROR_ARBITRATION_LOST, |
| 121 | STU300_ERROR_UNKNOWN | ||
| 121 | }; | 122 | }; |
| 122 | 123 | ||
| 123 | /* timeout waiting for the controller to respond */ | 124 | /* timeout waiting for the controller to respond */ |
| @@ -127,7 +128,7 @@ enum stu300_error { | |||
| 127 | * The number of address send athemps tried before giving up. | 128 | * The number of address send athemps tried before giving up. |
| 128 | * If the first one failes it seems like 5 to 8 attempts are required. | 129 | * If the first one failes it seems like 5 to 8 attempts are required. |
| 129 | */ | 130 | */ |
| 130 | #define NUM_ADDR_RESEND_ATTEMPTS 10 | 131 | #define NUM_ADDR_RESEND_ATTEMPTS 12 |
| 131 | 132 | ||
| 132 | /* I2C clock speed, in Hz 0-400kHz*/ | 133 | /* I2C clock speed, in Hz 0-400kHz*/ |
| 133 | static unsigned int scl_frequency = 100000; | 134 | static unsigned int scl_frequency = 100000; |
| @@ -149,6 +150,7 @@ module_param(scl_frequency, uint, 0644); | |||
| 149 | * @msg_index: index of current message | 150 | * @msg_index: index of current message |
| 150 | * @msg_len: length of current message | 151 | * @msg_len: length of current message |
| 151 | */ | 152 | */ |
| 153 | |||
| 152 | struct stu300_dev { | 154 | struct stu300_dev { |
| 153 | struct platform_device *pdev; | 155 | struct platform_device *pdev; |
| 154 | struct i2c_adapter adapter; | 156 | struct i2c_adapter adapter; |
| @@ -188,6 +190,27 @@ static inline u32 stu300_r8(void __iomem *address) | |||
| 188 | return readl(address) & 0x000000FFU; | 190 | return readl(address) & 0x000000FFU; |
| 189 | } | 191 | } |
| 190 | 192 | ||
| 193 | static void stu300_irq_enable(struct stu300_dev *dev) | ||
| 194 | { | ||
| 195 | u32 val; | ||
| 196 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
| 197 | val |= I2C_CR_INTERRUPT_ENABLE; | ||
| 198 | /* Twice paranoia (possible HW glitch) */ | ||
| 199 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 200 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 201 | } | ||
| 202 | |||
| 203 | static void stu300_irq_disable(struct stu300_dev *dev) | ||
| 204 | { | ||
| 205 | u32 val; | ||
| 206 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
| 207 | val &= ~I2C_CR_INTERRUPT_ENABLE; | ||
| 208 | /* Twice paranoia (possible HW glitch) */ | ||
| 209 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 210 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 211 | } | ||
| 212 | |||
| 213 | |||
| 191 | /* | 214 | /* |
| 192 | * Tells whether a certain event or events occurred in | 215 | * Tells whether a certain event or events occurred in |
| 193 | * response to a command. The events represent states in | 216 | * response to a command. The events represent states in |
| @@ -196,9 +219,10 @@ static inline u32 stu300_r8(void __iomem *address) | |||
| 196 | * documentation and can only be treated as abstract state | 219 | * documentation and can only be treated as abstract state |
| 197 | * machine states. | 220 | * machine states. |
| 198 | * | 221 | * |
| 199 | * @ret 0 = event has not occurred, any other value means | 222 | * @ret 0 = event has not occurred or unknown error, any |
| 200 | * the event occurred. | 223 | * other value means the correct event occurred or an error. |
| 201 | */ | 224 | */ |
| 225 | |||
| 202 | static int stu300_event_occurred(struct stu300_dev *dev, | 226 | static int stu300_event_occurred(struct stu300_dev *dev, |
| 203 | enum stu300_event mr_event) { | 227 | enum stu300_event mr_event) { |
| 204 | u32 status1; | 228 | u32 status1; |
| @@ -206,11 +230,28 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
| 206 | 230 | ||
| 207 | /* What event happened? */ | 231 | /* What event happened? */ |
| 208 | status1 = stu300_r8(dev->virtbase + I2C_SR1); | 232 | status1 = stu300_r8(dev->virtbase + I2C_SR1); |
| 233 | |||
| 209 | if (!(status1 & I2C_SR1_EVF_IND)) | 234 | if (!(status1 & I2C_SR1_EVF_IND)) |
| 210 | /* No event at all */ | 235 | /* No event at all */ |
| 211 | return 0; | 236 | return 0; |
| 237 | |||
| 212 | status2 = stu300_r8(dev->virtbase + I2C_SR2); | 238 | status2 = stu300_r8(dev->virtbase + I2C_SR2); |
| 213 | 239 | ||
| 240 | /* Block any multiple interrupts */ | ||
| 241 | stu300_irq_disable(dev); | ||
| 242 | |||
| 243 | /* Check for errors first */ | ||
| 244 | if (status2 & I2C_SR2_AF_IND) { | ||
| 245 | dev->cmd_err = STU300_ERROR_ACKNOWLEDGE_FAILURE; | ||
| 246 | return 1; | ||
| 247 | } else if (status2 & I2C_SR2_BERR_IND) { | ||
| 248 | dev->cmd_err = STU300_ERROR_BUS_ERROR; | ||
| 249 | return 1; | ||
| 250 | } else if (status2 & I2C_SR2_ARLO_IND) { | ||
| 251 | dev->cmd_err = STU300_ERROR_ARBITRATION_LOST; | ||
| 252 | return 1; | ||
| 253 | } | ||
| 254 | |||
| 214 | switch (mr_event) { | 255 | switch (mr_event) { |
| 215 | case STU300_EVENT_1: | 256 | case STU300_EVENT_1: |
| 216 | if (status1 & I2C_SR1_ADSL_IND) | 257 | if (status1 & I2C_SR1_ADSL_IND) |
| @@ -221,10 +262,6 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
| 221 | case STU300_EVENT_7: | 262 | case STU300_EVENT_7: |
| 222 | case STU300_EVENT_8: | 263 | case STU300_EVENT_8: |
| 223 | if (status1 & I2C_SR1_BTF_IND) { | 264 | if (status1 & I2C_SR1_BTF_IND) { |
| 224 | if (status2 & I2C_SR2_AF_IND) | ||
| 225 | dev->cmd_err = STU300_ERROR_ACKNOWLEDGE_FAILURE; | ||
| 226 | else if (status2 & I2C_SR2_BERR_IND) | ||
| 227 | dev->cmd_err = STU300_ERROR_BUS_ERROR; | ||
| 228 | return 1; | 265 | return 1; |
| 229 | } | 266 | } |
| 230 | break; | 267 | break; |
| @@ -240,8 +277,6 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
| 240 | case STU300_EVENT_6: | 277 | case STU300_EVENT_6: |
| 241 | if (status2 & I2C_SR2_ENDAD_IND) { | 278 | if (status2 & I2C_SR2_ENDAD_IND) { |
| 242 | /* First check for any errors */ | 279 | /* First check for any errors */ |
| 243 | if (status2 & I2C_SR2_AF_IND) | ||
| 244 | dev->cmd_err = STU300_ERROR_ACKNOWLEDGE_FAILURE; | ||
| 245 | return 1; | 280 | return 1; |
| 246 | } | 281 | } |
| 247 | break; | 282 | break; |
| @@ -252,8 +287,15 @@ static int stu300_event_occurred(struct stu300_dev *dev, | |||
| 252 | default: | 287 | default: |
| 253 | break; | 288 | break; |
| 254 | } | 289 | } |
| 255 | if (status2 & I2C_SR2_ARLO_IND) | 290 | /* If we get here, we're on thin ice. |
| 256 | dev->cmd_err = STU300_ERROR_ARBITRATION_LOST; | 291 | * Here we are in a status where we have |
| 292 | * gotten a response that does not match | ||
| 293 | * what we requested. | ||
| 294 | */ | ||
| 295 | dev->cmd_err = STU300_ERROR_UNKNOWN; | ||
| 296 | dev_err(&dev->pdev->dev, | ||
| 297 | "Unhandled interrupt! %d sr1: 0x%x sr2: 0x%x\n", | ||
| 298 | mr_event, status1, status2); | ||
| 257 | return 0; | 299 | return 0; |
| 258 | } | 300 | } |
| 259 | 301 | ||
| @@ -262,21 +304,20 @@ static irqreturn_t stu300_irh(int irq, void *data) | |||
| 262 | struct stu300_dev *dev = data; | 304 | struct stu300_dev *dev = data; |
| 263 | int res; | 305 | int res; |
| 264 | 306 | ||
| 307 | /* Just make sure that the block is clocked */ | ||
| 308 | clk_enable(dev->clk); | ||
| 309 | |||
| 265 | /* See if this was what we were waiting for */ | 310 | /* See if this was what we were waiting for */ |
| 266 | spin_lock(&dev->cmd_issue_lock); | 311 | spin_lock(&dev->cmd_issue_lock); |
| 267 | if (dev->cmd_event != STU300_EVENT_NONE) { | 312 | |
| 268 | res = stu300_event_occurred(dev, dev->cmd_event); | 313 | res = stu300_event_occurred(dev, dev->cmd_event); |
| 269 | if (res || dev->cmd_err != STU300_ERROR_NONE) { | 314 | if (res || dev->cmd_err != STU300_ERROR_NONE) |
| 270 | u32 val; | 315 | complete(&dev->cmd_complete); |
| 271 | 316 | ||
| 272 | complete(&dev->cmd_complete); | ||
| 273 | /* Block any multiple interrupts */ | ||
| 274 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
| 275 | val &= ~I2C_CR_INTERRUPT_ENABLE; | ||
| 276 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 277 | } | ||
| 278 | } | ||
| 279 | spin_unlock(&dev->cmd_issue_lock); | 317 | spin_unlock(&dev->cmd_issue_lock); |
| 318 | |||
| 319 | clk_disable(dev->clk); | ||
| 320 | |||
| 280 | return IRQ_HANDLED; | 321 | return IRQ_HANDLED; |
| 281 | } | 322 | } |
| 282 | 323 | ||
| @@ -308,7 +349,6 @@ static int stu300_start_and_await_event(struct stu300_dev *dev, | |||
| 308 | stu300_wr8(cr_value, dev->virtbase + I2C_CR); | 349 | stu300_wr8(cr_value, dev->virtbase + I2C_CR); |
| 309 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, | 350 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, |
| 310 | STU300_TIMEOUT); | 351 | STU300_TIMEOUT); |
| 311 | |||
| 312 | if (ret < 0) { | 352 | if (ret < 0) { |
| 313 | dev_err(&dev->pdev->dev, | 353 | dev_err(&dev->pdev->dev, |
| 314 | "wait_for_completion_interruptible_timeout() " | 354 | "wait_for_completion_interruptible_timeout() " |
| @@ -342,7 +382,6 @@ static int stu300_await_event(struct stu300_dev *dev, | |||
| 342 | enum stu300_event mr_event) | 382 | enum stu300_event mr_event) |
| 343 | { | 383 | { |
| 344 | int ret; | 384 | int ret; |
| 345 | u32 val; | ||
| 346 | 385 | ||
| 347 | if (unlikely(irqs_disabled())) { | 386 | if (unlikely(irqs_disabled())) { |
| 348 | /* TODO: implement polling for this case if need be. */ | 387 | /* TODO: implement polling for this case if need be. */ |
| @@ -354,36 +393,18 @@ static int stu300_await_event(struct stu300_dev *dev, | |||
| 354 | /* Is it already here? */ | 393 | /* Is it already here? */ |
| 355 | spin_lock_irq(&dev->cmd_issue_lock); | 394 | spin_lock_irq(&dev->cmd_issue_lock); |
| 356 | dev->cmd_err = STU300_ERROR_NONE; | 395 | dev->cmd_err = STU300_ERROR_NONE; |
| 357 | if (stu300_event_occurred(dev, mr_event)) { | ||
| 358 | spin_unlock_irq(&dev->cmd_issue_lock); | ||
| 359 | goto exit_await_check_err; | ||
| 360 | } | ||
| 361 | init_completion(&dev->cmd_complete); | ||
| 362 | dev->cmd_err = STU300_ERROR_NONE; | ||
| 363 | dev->cmd_event = mr_event; | 396 | dev->cmd_event = mr_event; |
| 364 | 397 | ||
| 365 | /* Turn on the I2C interrupt for current operation */ | 398 | init_completion(&dev->cmd_complete); |
| 366 | val = stu300_r8(dev->virtbase + I2C_CR); | ||
| 367 | val |= I2C_CR_INTERRUPT_ENABLE; | ||
| 368 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 369 | |||
| 370 | /* Twice paranoia (possible HW glitch) */ | ||
| 371 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 372 | 399 | ||
| 373 | /* Check again: is it already here? */ | 400 | /* Turn on the I2C interrupt for current operation */ |
| 374 | if (unlikely(stu300_event_occurred(dev, mr_event))) { | 401 | stu300_irq_enable(dev); |
| 375 | /* Disable IRQ again. */ | ||
| 376 | val &= ~I2C_CR_INTERRUPT_ENABLE; | ||
| 377 | stu300_wr8(val, dev->virtbase + I2C_CR); | ||
| 378 | spin_unlock_irq(&dev->cmd_issue_lock); | ||
| 379 | goto exit_await_check_err; | ||
| 380 | } | ||
| 381 | 402 | ||
| 382 | /* Unlock the command block and wait for the event to occur */ | 403 | /* Unlock the command block and wait for the event to occur */ |
| 383 | spin_unlock_irq(&dev->cmd_issue_lock); | 404 | spin_unlock_irq(&dev->cmd_issue_lock); |
| 405 | |||
| 384 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, | 406 | ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, |
| 385 | STU300_TIMEOUT); | 407 | STU300_TIMEOUT); |
| 386 | |||
| 387 | if (ret < 0) { | 408 | if (ret < 0) { |
| 388 | dev_err(&dev->pdev->dev, | 409 | dev_err(&dev->pdev->dev, |
| 389 | "wait_for_completion_interruptible_timeout()" | 410 | "wait_for_completion_interruptible_timeout()" |
| @@ -401,7 +422,6 @@ static int stu300_await_event(struct stu300_dev *dev, | |||
| 401 | return -ETIMEDOUT; | 422 | return -ETIMEDOUT; |
| 402 | } | 423 | } |
| 403 | 424 | ||
| 404 | exit_await_check_err: | ||
| 405 | if (dev->cmd_err != STU300_ERROR_NONE) { | 425 | if (dev->cmd_err != STU300_ERROR_NONE) { |
| 406 | if (mr_event != STU300_EVENT_6) { | 426 | if (mr_event != STU300_EVENT_6) { |
| 407 | dev_err(&dev->pdev->dev, "controller " | 427 | dev_err(&dev->pdev->dev, "controller " |
| @@ -457,18 +477,19 @@ struct stu300_clkset { | |||
| 457 | }; | 477 | }; |
| 458 | 478 | ||
| 459 | static const struct stu300_clkset stu300_clktable[] = { | 479 | static const struct stu300_clkset stu300_clktable[] = { |
| 460 | { 0, 0xFFU }, | 480 | { 0, 0xFFU }, |
| 461 | { 2500000, I2C_OAR2_FR_25_10MHZ }, | 481 | { 2500000, I2C_OAR2_FR_25_10MHZ }, |
| 462 | { 10000000, I2C_OAR2_FR_10_1667MHZ }, | 482 | { 10000000, I2C_OAR2_FR_10_1667MHZ }, |
| 463 | { 16670000, I2C_OAR2_FR_1667_2667MHZ }, | 483 | { 16670000, I2C_OAR2_FR_1667_2667MHZ }, |
| 464 | { 26670000, I2C_OAR2_FR_2667_40MHZ }, | 484 | { 26670000, I2C_OAR2_FR_2667_40MHZ }, |
| 465 | { 40000000, I2C_OAR2_FR_40_5333MHZ }, | 485 | { 40000000, I2C_OAR2_FR_40_5333MHZ }, |
| 466 | { 53330000, I2C_OAR2_FR_5333_66MHZ }, | 486 | { 53330000, I2C_OAR2_FR_5333_66MHZ }, |
| 467 | { 66000000, I2C_OAR2_FR_66_80MHZ }, | 487 | { 66000000, I2C_OAR2_FR_66_80MHZ }, |
| 468 | { 80000000, I2C_OAR2_FR_80_100MHZ }, | 488 | { 80000000, I2C_OAR2_FR_80_100MHZ }, |
| 469 | { 100000000, 0xFFU }, | 489 | { 100000000, 0xFFU }, |
| 470 | }; | 490 | }; |
| 471 | 491 | ||
| 492 | |||
| 472 | static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) | 493 | static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) |
| 473 | { | 494 | { |
| 474 | 495 | ||
| @@ -494,10 +515,10 @@ static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate) | |||
| 494 | 515 | ||
| 495 | if (dev->speed > 100000) | 516 | if (dev->speed > 100000) |
| 496 | /* Fast Mode I2C */ | 517 | /* Fast Mode I2C */ |
| 497 | val = ((clkrate/dev->speed)-9)/3; | 518 | val = ((clkrate/dev->speed) - 9)/3 + 1; |
| 498 | else | 519 | else |
| 499 | /* Standard Mode I2C */ | 520 | /* Standard Mode I2C */ |
| 500 | val = ((clkrate/dev->speed)-7)/2; | 521 | val = ((clkrate/dev->speed) - 7)/2 + 1; |
| 501 | 522 | ||
| 502 | /* According to spec the divider must be > 2 */ | 523 | /* According to spec the divider must be > 2 */ |
| 503 | if (val < 0x002) { | 524 | if (val < 0x002) { |
| @@ -557,6 +578,7 @@ static int stu300_init_hw(struct stu300_dev *dev) | |||
| 557 | */ | 578 | */ |
| 558 | clkrate = clk_get_rate(dev->clk); | 579 | clkrate = clk_get_rate(dev->clk); |
| 559 | ret = stu300_set_clk(dev, clkrate); | 580 | ret = stu300_set_clk(dev, clkrate); |
| 581 | |||
| 560 | if (ret) | 582 | if (ret) |
| 561 | return ret; | 583 | return ret; |
| 562 | /* | 584 | /* |
| @@ -641,7 +663,6 @@ static int stu300_xfer_msg(struct i2c_adapter *adap, | |||
| 641 | int attempts = 0; | 663 | int attempts = 0; |
| 642 | struct stu300_dev *dev = i2c_get_adapdata(adap); | 664 | struct stu300_dev *dev = i2c_get_adapdata(adap); |
| 643 | 665 | ||
| 644 | |||
| 645 | clk_enable(dev->clk); | 666 | clk_enable(dev->clk); |
| 646 | 667 | ||
| 647 | /* Remove this if (0) to trace each and every message. */ | 668 | /* Remove this if (0) to trace each and every message. */ |
| @@ -715,14 +736,15 @@ static int stu300_xfer_msg(struct i2c_adapter *adap, | |||
| 715 | 736 | ||
| 716 | if (attempts < NUM_ADDR_RESEND_ATTEMPTS && attempts > 0) { | 737 | if (attempts < NUM_ADDR_RESEND_ATTEMPTS && attempts > 0) { |
| 717 | dev_dbg(&dev->pdev->dev, "managed to get address " | 738 | dev_dbg(&dev->pdev->dev, "managed to get address " |
| 718 | "through after %d attempts\n", attempts); | 739 | "through after %d attempts\n", attempts); |
| 719 | } else if (attempts == NUM_ADDR_RESEND_ATTEMPTS) { | 740 | } else if (attempts == NUM_ADDR_RESEND_ATTEMPTS) { |
| 720 | dev_dbg(&dev->pdev->dev, "I give up, tried %d times " | 741 | dev_dbg(&dev->pdev->dev, "I give up, tried %d times " |
| 721 | "to resend address.\n", | 742 | "to resend address.\n", |
| 722 | NUM_ADDR_RESEND_ATTEMPTS); | 743 | NUM_ADDR_RESEND_ATTEMPTS); |
| 723 | goto exit_disable; | 744 | goto exit_disable; |
| 724 | } | 745 | } |
| 725 | 746 | ||
| 747 | |||
| 726 | if (msg->flags & I2C_M_RD) { | 748 | if (msg->flags & I2C_M_RD) { |
| 727 | /* READ: we read the actual bytes one at a time */ | 749 | /* READ: we read the actual bytes one at a time */ |
| 728 | for (i = 0; i < msg->len; i++) { | 750 | for (i = 0; i < msg->len; i++) { |
| @@ -804,8 +826,10 @@ static int stu300_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, | |||
| 804 | { | 826 | { |
| 805 | int ret = -1; | 827 | int ret = -1; |
| 806 | int i; | 828 | int i; |
| 829 | |||
| 807 | struct stu300_dev *dev = i2c_get_adapdata(adap); | 830 | struct stu300_dev *dev = i2c_get_adapdata(adap); |
| 808 | dev->msg_len = num; | 831 | dev->msg_len = num; |
| 832 | |||
| 809 | for (i = 0; i < num; i++) { | 833 | for (i = 0; i < num; i++) { |
| 810 | /* | 834 | /* |
| 811 | * Another driver appears to send stop for each message, | 835 | * Another driver appears to send stop for each message, |
| @@ -817,6 +841,7 @@ static int stu300_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, | |||
| 817 | dev->msg_index = i; | 841 | dev->msg_index = i; |
| 818 | 842 | ||
| 819 | ret = stu300_xfer_msg(adap, &msgs[i], (i == (num - 1))); | 843 | ret = stu300_xfer_msg(adap, &msgs[i], (i == (num - 1))); |
| 844 | |||
| 820 | if (ret != 0) { | 845 | if (ret != 0) { |
| 821 | num = ret; | 846 | num = ret; |
| 822 | break; | 847 | break; |
| @@ -845,6 +870,7 @@ stu300_probe(struct platform_device *pdev) | |||
| 845 | struct resource *res; | 870 | struct resource *res; |
| 846 | int bus_nr; | 871 | int bus_nr; |
| 847 | int ret = 0; | 872 | int ret = 0; |
| 873 | char clk_name[] = "I2C0"; | ||
| 848 | 874 | ||
| 849 | dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL); | 875 | dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL); |
| 850 | if (!dev) { | 876 | if (!dev) { |
| @@ -854,7 +880,8 @@ stu300_probe(struct platform_device *pdev) | |||
| 854 | } | 880 | } |
| 855 | 881 | ||
| 856 | bus_nr = pdev->id; | 882 | bus_nr = pdev->id; |
| 857 | dev->clk = clk_get(&pdev->dev, NULL); | 883 | clk_name[3] += (char)bus_nr; |
| 884 | dev->clk = clk_get(&pdev->dev, clk_name); | ||
| 858 | if (IS_ERR(dev->clk)) { | 885 | if (IS_ERR(dev->clk)) { |
| 859 | ret = PTR_ERR(dev->clk); | 886 | ret = PTR_ERR(dev->clk); |
| 860 | dev_err(&pdev->dev, "could not retrieve i2c bus clock\n"); | 887 | dev_err(&pdev->dev, "could not retrieve i2c bus clock\n"); |
