Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | /* ////////////////////////////////////////////////////////////////////////// */ |
| 2 | /* */ |
| 3 | /* Copyright (c) Atmel Corporation. All rights reserved. */ |
| 4 | /* */ |
| 5 | /* Module Name: wilc_sdio.c */ |
| 6 | /* */ |
| 7 | /* */ |
| 8 | /* //////////////////////////////////////////////////////////////////////////// */ |
| 9 | |
Chaehyun Lim | 0c9fc33 | 2015-09-30 17:52:14 +0900 | [diff] [blame] | 10 | #include <linux/string.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 11 | #include "wilc_wlan_if.h" |
| 12 | #include "wilc_wlan.h" |
Glen Lee | 9c80032 | 2015-11-06 18:40:22 +0900 | [diff] [blame] | 13 | #include "wilc_wfi_netdevice.h" |
Glen Lee | 35a4569 | 2015-12-21 14:18:29 +0900 | [diff] [blame] | 14 | #include <linux/mmc/sdio_func.h> |
| 15 | #include <linux/mmc/card.h> |
| 16 | #include <linux/mmc/sdio_ids.h> |
| 17 | #include <linux/mmc/sdio.h> |
| 18 | #include <linux/mmc/host.h> |
| 19 | #include <linux/of_gpio.h> |
| 20 | |
| 21 | #define SDIO_MODALIAS "wilc1000_sdio" |
| 22 | |
| 23 | #define SDIO_VENDOR_ID_WILC 0x0296 |
| 24 | #define SDIO_DEVICE_ID_WILC 0x5347 |
| 25 | |
| 26 | static const struct sdio_device_id wilc_sdio_ids[] = { |
| 27 | { SDIO_DEVICE(SDIO_VENDOR_ID_WILC, SDIO_DEVICE_ID_WILC) }, |
| 28 | { }, |
| 29 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 30 | |
Tony Cho | 229d740 | 2015-07-28 17:47:26 +0900 | [diff] [blame] | 31 | #define WILC_SDIO_BLOCK_SIZE 512 |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 32 | |
Bhumika Goyal | 6a707a9 | 2016-02-21 03:12:11 +0530 | [diff] [blame] | 33 | struct wilc_sdio { |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 34 | bool irq_gpio; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 35 | u32 block_size; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 36 | int nint; |
| 37 | #define MAX_NUN_INT_THRPT_ENH2 (5) /* Max num interrupts allowed in registers 0xf7, 0xf8 */ |
| 38 | int has_thrpt_enh3; |
Bhumika Goyal | 6a707a9 | 2016-02-21 03:12:11 +0530 | [diff] [blame] | 39 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 40 | |
Bhumika Goyal | 6a707a9 | 2016-02-21 03:12:11 +0530 | [diff] [blame] | 41 | static struct wilc_sdio g_sdio; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 42 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 43 | static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data); |
| 44 | static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data); |
Glen Lee | 5397cbc | 2016-01-25 16:35:09 +0900 | [diff] [blame] | 45 | static int sdio_init(struct wilc *wilc, bool resume); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 46 | |
Glen Lee | 35a4569 | 2015-12-21 14:18:29 +0900 | [diff] [blame] | 47 | static void wilc_sdio_interrupt(struct sdio_func *func) |
| 48 | { |
| 49 | sdio_release_host(func); |
| 50 | wilc_handle_isr(sdio_get_drvdata(func)); |
| 51 | sdio_claim_host(func); |
| 52 | } |
| 53 | |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 54 | static int wilc_sdio_cmd52(struct wilc *wilc, struct sdio_cmd52 *cmd) |
Glen Lee | 35a4569 | 2015-12-21 14:18:29 +0900 | [diff] [blame] | 55 | { |
| 56 | struct sdio_func *func = container_of(wilc->dev, struct sdio_func, dev); |
| 57 | int ret; |
| 58 | u8 data; |
| 59 | |
| 60 | sdio_claim_host(func); |
| 61 | |
| 62 | func->num = cmd->function; |
| 63 | if (cmd->read_write) { /* write */ |
| 64 | if (cmd->raw) { |
| 65 | sdio_writeb(func, cmd->data, cmd->address, &ret); |
| 66 | data = sdio_readb(func, cmd->address, &ret); |
| 67 | cmd->data = data; |
| 68 | } else { |
| 69 | sdio_writeb(func, cmd->data, cmd->address, &ret); |
| 70 | } |
| 71 | } else { /* read */ |
| 72 | data = sdio_readb(func, cmd->address, &ret); |
| 73 | cmd->data = data; |
| 74 | } |
| 75 | |
| 76 | sdio_release_host(func); |
| 77 | |
| 78 | if (ret) |
| 79 | dev_err(&func->dev, "wilc_sdio_cmd52..failed, err(%d)\n", ret); |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | |
Chaehyun Lim | fc17eaa | 2016-03-03 14:28:22 +0900 | [diff] [blame] | 84 | static int wilc_sdio_cmd53(struct wilc *wilc, struct sdio_cmd53 *cmd) |
Glen Lee | 35a4569 | 2015-12-21 14:18:29 +0900 | [diff] [blame] | 85 | { |
| 86 | struct sdio_func *func = container_of(wilc->dev, struct sdio_func, dev); |
| 87 | int size, ret; |
| 88 | |
| 89 | sdio_claim_host(func); |
| 90 | |
| 91 | func->num = cmd->function; |
| 92 | func->cur_blksize = cmd->block_size; |
| 93 | if (cmd->block_mode) |
| 94 | size = cmd->count * cmd->block_size; |
| 95 | else |
| 96 | size = cmd->count; |
| 97 | |
| 98 | if (cmd->read_write) { /* write */ |
| 99 | ret = sdio_memcpy_toio(func, cmd->address, |
| 100 | (void *)cmd->buffer, size); |
| 101 | } else { /* read */ |
| 102 | ret = sdio_memcpy_fromio(func, (void *)cmd->buffer, |
| 103 | cmd->address, size); |
| 104 | } |
| 105 | |
| 106 | sdio_release_host(func); |
| 107 | |
| 108 | if (ret) |
| 109 | dev_err(&func->dev, "wilc_sdio_cmd53..failed, err(%d)\n", ret); |
| 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | static int linux_sdio_probe(struct sdio_func *func, |
| 115 | const struct sdio_device_id *id) |
| 116 | { |
| 117 | struct wilc *wilc; |
| 118 | int gpio, ret; |
| 119 | |
| 120 | gpio = -1; |
| 121 | if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) { |
| 122 | gpio = of_get_gpio(func->dev.of_node, 0); |
| 123 | if (gpio < 0) |
| 124 | gpio = GPIO_NUM; |
| 125 | } |
| 126 | |
| 127 | dev_dbg(&func->dev, "Initializing netdev\n"); |
| 128 | ret = wilc_netdev_init(&wilc, &func->dev, HIF_SDIO, gpio, |
| 129 | &wilc_hif_sdio); |
| 130 | if (ret) { |
| 131 | dev_err(&func->dev, "Couldn't initialize netdev\n"); |
| 132 | return ret; |
| 133 | } |
| 134 | sdio_set_drvdata(func, wilc); |
| 135 | wilc->dev = &func->dev; |
| 136 | |
| 137 | dev_info(&func->dev, "Driver Initializing success\n"); |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static void linux_sdio_remove(struct sdio_func *func) |
| 142 | { |
| 143 | wilc_netdev_cleanup(sdio_get_drvdata(func)); |
| 144 | } |
| 145 | |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 146 | static int sdio_reset(struct wilc *wilc) |
| 147 | { |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 148 | struct sdio_cmd52 cmd; |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 149 | int ret; |
| 150 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
| 151 | |
| 152 | cmd.read_write = 1; |
| 153 | cmd.function = 0; |
| 154 | cmd.raw = 0; |
| 155 | cmd.address = 0x6; |
| 156 | cmd.data = 0x8; |
| 157 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 158 | if (ret) { |
| 159 | dev_err(&func->dev, "Fail cmd 52, reset cmd ...\n"); |
| 160 | return ret; |
| 161 | } |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static int wilc_sdio_suspend(struct device *dev) |
| 166 | { |
| 167 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 168 | struct wilc *wilc = sdio_get_drvdata(func); |
| 169 | int ret; |
| 170 | |
| 171 | dev_info(dev, "sdio suspend\n"); |
| 172 | chip_wakeup(wilc); |
| 173 | |
| 174 | if (!wilc->suspend_event) { |
| 175 | wilc_chip_sleep_manually(wilc); |
| 176 | } else { |
| 177 | host_sleep_notify(wilc); |
| 178 | chip_allow_sleep(wilc); |
| 179 | } |
| 180 | |
| 181 | ret = sdio_reset(wilc); |
| 182 | if (ret) { |
| 183 | dev_err(&func->dev, "Fail reset sdio\n"); |
| 184 | return ret; |
| 185 | } |
| 186 | sdio_claim_host(func); |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static int wilc_sdio_resume(struct device *dev) |
| 192 | { |
| 193 | struct sdio_func *func = dev_to_sdio_func(dev); |
| 194 | struct wilc *wilc = sdio_get_drvdata(func); |
| 195 | |
| 196 | dev_info(dev, "sdio resume\n"); |
| 197 | sdio_release_host(func); |
| 198 | chip_wakeup(wilc); |
Glen Lee | 5397cbc | 2016-01-25 16:35:09 +0900 | [diff] [blame] | 199 | sdio_init(wilc, true); |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 200 | |
| 201 | if (wilc->suspend_event) |
| 202 | host_wakeup_notify(wilc); |
| 203 | |
| 204 | chip_allow_sleep(wilc); |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static const struct dev_pm_ops wilc_sdio_pm_ops = { |
| 210 | .suspend = wilc_sdio_suspend, |
| 211 | .resume = wilc_sdio_resume, |
| 212 | }; |
| 213 | |
Glen Lee | 35a4569 | 2015-12-21 14:18:29 +0900 | [diff] [blame] | 214 | static struct sdio_driver wilc1000_sdio_driver = { |
| 215 | .name = SDIO_MODALIAS, |
| 216 | .id_table = wilc_sdio_ids, |
| 217 | .probe = linux_sdio_probe, |
| 218 | .remove = linux_sdio_remove, |
Glen Lee | 76855ba | 2016-01-25 16:35:08 +0900 | [diff] [blame] | 219 | .drv = { |
| 220 | .pm = &wilc_sdio_pm_ops, |
| 221 | } |
Glen Lee | 35a4569 | 2015-12-21 14:18:29 +0900 | [diff] [blame] | 222 | }; |
| 223 | module_driver(wilc1000_sdio_driver, |
| 224 | sdio_register_driver, |
| 225 | sdio_unregister_driver); |
| 226 | MODULE_LICENSE("GPL"); |
| 227 | |
| 228 | static int wilc_sdio_enable_interrupt(struct wilc *dev) |
| 229 | { |
| 230 | struct sdio_func *func = container_of(dev->dev, struct sdio_func, dev); |
| 231 | int ret = 0; |
| 232 | |
| 233 | sdio_claim_host(func); |
| 234 | ret = sdio_claim_irq(func, wilc_sdio_interrupt); |
| 235 | sdio_release_host(func); |
| 236 | |
| 237 | if (ret < 0) { |
| 238 | dev_err(&func->dev, "can't claim sdio_irq, err(%d)\n", ret); |
| 239 | ret = -EIO; |
| 240 | } |
| 241 | return ret; |
| 242 | } |
| 243 | |
| 244 | static void wilc_sdio_disable_interrupt(struct wilc *dev) |
| 245 | { |
| 246 | struct sdio_func *func = container_of(dev->dev, struct sdio_func, dev); |
| 247 | int ret; |
| 248 | |
| 249 | dev_dbg(&func->dev, "wilc_sdio_disable_interrupt IN\n"); |
| 250 | |
| 251 | sdio_claim_host(func); |
| 252 | ret = sdio_release_irq(func); |
| 253 | if (ret < 0) |
| 254 | dev_err(&func->dev, "can't release sdio_irq, err(%d)\n", ret); |
| 255 | sdio_release_host(func); |
| 256 | |
| 257 | dev_info(&func->dev, "wilc_sdio_disable_interrupt OUT\n"); |
| 258 | } |
| 259 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 260 | /******************************************** |
| 261 | * |
| 262 | * Function 0 |
| 263 | * |
| 264 | ********************************************/ |
| 265 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 266 | static int sdio_set_func0_csa_address(struct wilc *wilc, u32 adr) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 267 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 268 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 269 | struct sdio_cmd52 cmd; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 270 | int ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * Review: BIG ENDIAN |
| 274 | **/ |
| 275 | cmd.read_write = 1; |
| 276 | cmd.function = 0; |
| 277 | cmd.raw = 0; |
| 278 | cmd.address = 0x10c; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 279 | cmd.data = (u8)adr; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 280 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 281 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 282 | dev_err(&func->dev, "Failed cmd52, set 0x10c data...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 283 | goto _fail_; |
| 284 | } |
| 285 | |
| 286 | cmd.address = 0x10d; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 287 | cmd.data = (u8)(adr >> 8); |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 288 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 289 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 290 | dev_err(&func->dev, "Failed cmd52, set 0x10d data...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 291 | goto _fail_; |
| 292 | } |
| 293 | |
| 294 | cmd.address = 0x10e; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 295 | cmd.data = (u8)(adr >> 16); |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 296 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 297 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 298 | dev_err(&func->dev, "Failed cmd52, set 0x10e data...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 299 | goto _fail_; |
| 300 | } |
| 301 | |
| 302 | return 1; |
| 303 | _fail_: |
| 304 | return 0; |
| 305 | } |
| 306 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 307 | static int sdio_set_func0_block_size(struct wilc *wilc, u32 block_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 308 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 309 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 310 | struct sdio_cmd52 cmd; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 311 | int ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 312 | |
| 313 | cmd.read_write = 1; |
| 314 | cmd.function = 0; |
| 315 | cmd.raw = 0; |
| 316 | cmd.address = 0x10; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 317 | cmd.data = (u8)block_size; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 318 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 319 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 320 | dev_err(&func->dev, "Failed cmd52, set 0x10 data...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 321 | goto _fail_; |
| 322 | } |
| 323 | |
| 324 | cmd.address = 0x11; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 325 | cmd.data = (u8)(block_size >> 8); |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 326 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 327 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 328 | dev_err(&func->dev, "Failed cmd52, set 0x11 data...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 329 | goto _fail_; |
| 330 | } |
| 331 | |
| 332 | return 1; |
| 333 | _fail_: |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | /******************************************** |
| 338 | * |
| 339 | * Function 1 |
| 340 | * |
| 341 | ********************************************/ |
| 342 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 343 | static int sdio_set_func1_block_size(struct wilc *wilc, u32 block_size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 344 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 345 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 346 | struct sdio_cmd52 cmd; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 347 | int ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 348 | |
| 349 | cmd.read_write = 1; |
| 350 | cmd.function = 0; |
| 351 | cmd.raw = 0; |
| 352 | cmd.address = 0x110; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 353 | cmd.data = (u8)block_size; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 354 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 355 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 356 | dev_err(&func->dev, "Failed cmd52, set 0x110 data...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 357 | goto _fail_; |
| 358 | } |
| 359 | cmd.address = 0x111; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 360 | cmd.data = (u8)(block_size >> 8); |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 361 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 362 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 363 | dev_err(&func->dev, "Failed cmd52, set 0x111 data...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 364 | goto _fail_; |
| 365 | } |
| 366 | |
| 367 | return 1; |
| 368 | _fail_: |
| 369 | return 0; |
| 370 | } |
| 371 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 372 | /******************************************** |
| 373 | * |
| 374 | * Sdio interfaces |
| 375 | * |
| 376 | ********************************************/ |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 377 | static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 378 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 379 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 380 | int ret; |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 381 | |
Glen Lee | 9e6627a | 2015-12-21 14:18:08 +0900 | [diff] [blame] | 382 | data = cpu_to_le32(data); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 383 | |
| 384 | if ((addr >= 0xf0) && (addr <= 0xff)) { |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 385 | struct sdio_cmd52 cmd; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 386 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 387 | cmd.read_write = 1; |
| 388 | cmd.function = 0; |
| 389 | cmd.raw = 0; |
| 390 | cmd.address = addr; |
| 391 | cmd.data = data; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 392 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 393 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 394 | dev_err(&func->dev, |
| 395 | "Failed cmd 52, read reg (%08x) ...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 396 | goto _fail_; |
| 397 | } |
| 398 | } else { |
Chaehyun Lim | fc17eaa | 2016-03-03 14:28:22 +0900 | [diff] [blame] | 399 | struct sdio_cmd53 cmd; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 400 | |
| 401 | /** |
| 402 | * set the AHB address |
| 403 | **/ |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 404 | if (!sdio_set_func0_csa_address(wilc, addr)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 405 | goto _fail_; |
| 406 | |
| 407 | cmd.read_write = 1; |
| 408 | cmd.function = 0; |
| 409 | cmd.address = 0x10f; |
| 410 | cmd.block_mode = 0; |
| 411 | cmd.increment = 1; |
| 412 | cmd.count = 4; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 413 | cmd.buffer = (u8 *)&data; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 414 | cmd.block_size = g_sdio.block_size; /* johnny : prevent it from setting unexpected value */ |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 415 | ret = wilc_sdio_cmd53(wilc, &cmd); |
| 416 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 417 | dev_err(&func->dev, |
| 418 | "Failed cmd53, write reg (%08x)...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 419 | goto _fail_; |
| 420 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | return 1; |
| 424 | |
| 425 | _fail_: |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 430 | static int sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 431 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 432 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 433 | u32 block_size = g_sdio.block_size; |
Chaehyun Lim | fc17eaa | 2016-03-03 14:28:22 +0900 | [diff] [blame] | 434 | struct sdio_cmd53 cmd; |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 435 | int nblk, nleft, ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 436 | |
| 437 | cmd.read_write = 1; |
| 438 | if (addr > 0) { |
| 439 | /** |
| 440 | * has to be word aligned... |
| 441 | **/ |
| 442 | if (size & 0x3) { |
| 443 | size += 4; |
| 444 | size &= ~0x3; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * func 0 access |
| 449 | **/ |
| 450 | cmd.function = 0; |
| 451 | cmd.address = 0x10f; |
| 452 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 453 | /** |
| 454 | * has to be word aligned... |
| 455 | **/ |
| 456 | if (size & 0x3) { |
| 457 | size += 4; |
| 458 | size &= ~0x3; |
| 459 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * func 1 access |
| 463 | **/ |
| 464 | cmd.function = 1; |
| 465 | cmd.address = 0; |
| 466 | } |
| 467 | |
| 468 | nblk = size / block_size; |
| 469 | nleft = size % block_size; |
| 470 | |
| 471 | if (nblk > 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 472 | cmd.block_mode = 1; |
| 473 | cmd.increment = 1; |
| 474 | cmd.count = nblk; |
| 475 | cmd.buffer = buf; |
| 476 | cmd.block_size = block_size; |
| 477 | if (addr > 0) { |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 478 | if (!sdio_set_func0_csa_address(wilc, addr)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 479 | goto _fail_; |
| 480 | } |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 481 | ret = wilc_sdio_cmd53(wilc, &cmd); |
| 482 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 483 | dev_err(&func->dev, |
| 484 | "Failed cmd53 [%x], block send...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 485 | goto _fail_; |
| 486 | } |
| 487 | if (addr > 0) |
| 488 | addr += nblk * block_size; |
| 489 | buf += nblk * block_size; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 490 | } |
| 491 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 492 | if (nleft > 0) { |
| 493 | cmd.block_mode = 0; |
| 494 | cmd.increment = 1; |
| 495 | cmd.count = nleft; |
| 496 | cmd.buffer = buf; |
| 497 | |
| 498 | cmd.block_size = block_size; /* johnny : prevent it from setting unexpected value */ |
| 499 | |
| 500 | if (addr > 0) { |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 501 | if (!sdio_set_func0_csa_address(wilc, addr)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 502 | goto _fail_; |
| 503 | } |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 504 | ret = wilc_sdio_cmd53(wilc, &cmd); |
| 505 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 506 | dev_err(&func->dev, |
| 507 | "Failed cmd53 [%x], bytes send...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 508 | goto _fail_; |
| 509 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | return 1; |
| 513 | |
| 514 | _fail_: |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 519 | static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 520 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 521 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 522 | int ret; |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 523 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 524 | if ((addr >= 0xf0) && (addr <= 0xff)) { |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 525 | struct sdio_cmd52 cmd; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 526 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 527 | cmd.read_write = 0; |
| 528 | cmd.function = 0; |
| 529 | cmd.raw = 0; |
| 530 | cmd.address = addr; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 531 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 532 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 533 | dev_err(&func->dev, |
| 534 | "Failed cmd 52, read reg (%08x) ...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 535 | goto _fail_; |
| 536 | } |
| 537 | *data = cmd.data; |
| 538 | } else { |
Chaehyun Lim | fc17eaa | 2016-03-03 14:28:22 +0900 | [diff] [blame] | 539 | struct sdio_cmd53 cmd; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 540 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 541 | if (!sdio_set_func0_csa_address(wilc, addr)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 542 | goto _fail_; |
| 543 | |
| 544 | cmd.read_write = 0; |
| 545 | cmd.function = 0; |
| 546 | cmd.address = 0x10f; |
| 547 | cmd.block_mode = 0; |
| 548 | cmd.increment = 1; |
| 549 | cmd.count = 4; |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 550 | cmd.buffer = (u8 *)data; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 551 | |
| 552 | cmd.block_size = g_sdio.block_size; /* johnny : prevent it from setting unexpected value */ |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 553 | ret = wilc_sdio_cmd53(wilc, &cmd); |
| 554 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 555 | dev_err(&func->dev, |
| 556 | "Failed cmd53, read reg (%08x)...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 557 | goto _fail_; |
| 558 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 559 | } |
| 560 | |
Glen Lee | 9e6627a | 2015-12-21 14:18:08 +0900 | [diff] [blame] | 561 | *data = cpu_to_le32(*data); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 562 | |
| 563 | return 1; |
| 564 | |
| 565 | _fail_: |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 570 | static int sdio_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 571 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 572 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 573 | u32 block_size = g_sdio.block_size; |
Chaehyun Lim | fc17eaa | 2016-03-03 14:28:22 +0900 | [diff] [blame] | 574 | struct sdio_cmd53 cmd; |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 575 | int nblk, nleft, ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 576 | |
| 577 | cmd.read_write = 0; |
| 578 | if (addr > 0) { |
| 579 | /** |
| 580 | * has to be word aligned... |
| 581 | **/ |
| 582 | if (size & 0x3) { |
| 583 | size += 4; |
| 584 | size &= ~0x3; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * func 0 access |
| 589 | **/ |
| 590 | cmd.function = 0; |
| 591 | cmd.address = 0x10f; |
| 592 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 593 | /** |
| 594 | * has to be word aligned... |
| 595 | **/ |
| 596 | if (size & 0x3) { |
| 597 | size += 4; |
| 598 | size &= ~0x3; |
| 599 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 600 | |
| 601 | /** |
| 602 | * func 1 access |
| 603 | **/ |
| 604 | cmd.function = 1; |
| 605 | cmd.address = 0; |
| 606 | } |
| 607 | |
| 608 | nblk = size / block_size; |
| 609 | nleft = size % block_size; |
| 610 | |
| 611 | if (nblk > 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 612 | cmd.block_mode = 1; |
| 613 | cmd.increment = 1; |
| 614 | cmd.count = nblk; |
| 615 | cmd.buffer = buf; |
| 616 | cmd.block_size = block_size; |
| 617 | if (addr > 0) { |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 618 | if (!sdio_set_func0_csa_address(wilc, addr)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 619 | goto _fail_; |
| 620 | } |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 621 | ret = wilc_sdio_cmd53(wilc, &cmd); |
| 622 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 623 | dev_err(&func->dev, |
| 624 | "Failed cmd53 [%x], block read...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 625 | goto _fail_; |
| 626 | } |
| 627 | if (addr > 0) |
| 628 | addr += nblk * block_size; |
| 629 | buf += nblk * block_size; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 630 | } /* if (nblk > 0) */ |
| 631 | |
| 632 | if (nleft > 0) { |
| 633 | cmd.block_mode = 0; |
| 634 | cmd.increment = 1; |
| 635 | cmd.count = nleft; |
| 636 | cmd.buffer = buf; |
| 637 | |
| 638 | cmd.block_size = block_size; /* johnny : prevent it from setting unexpected value */ |
| 639 | |
| 640 | if (addr > 0) { |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 641 | if (!sdio_set_func0_csa_address(wilc, addr)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 642 | goto _fail_; |
| 643 | } |
Glen Lee | 6f8bded | 2015-12-21 14:18:18 +0900 | [diff] [blame] | 644 | ret = wilc_sdio_cmd53(wilc, &cmd); |
| 645 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 646 | dev_err(&func->dev, |
| 647 | "Failed cmd53 [%x], bytes read...\n", addr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 648 | goto _fail_; |
| 649 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | return 1; |
| 653 | |
| 654 | _fail_: |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | /******************************************** |
| 660 | * |
| 661 | * Bus interfaces |
| 662 | * |
| 663 | ********************************************/ |
| 664 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 665 | static int sdio_deinit(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 666 | { |
| 667 | return 1; |
| 668 | } |
| 669 | |
Glen Lee | 5397cbc | 2016-01-25 16:35:09 +0900 | [diff] [blame] | 670 | static int sdio_init(struct wilc *wilc, bool resume) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 671 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 672 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 673 | struct sdio_cmd52 cmd; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 674 | int loop, ret; |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 675 | u32 chipid; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 676 | |
Glen Lee | 5397cbc | 2016-01-25 16:35:09 +0900 | [diff] [blame] | 677 | if (!resume) { |
Bhumika Goyal | 6a707a9 | 2016-02-21 03:12:11 +0530 | [diff] [blame] | 678 | memset(&g_sdio, 0, sizeof(struct wilc_sdio)); |
Janani Ravichandran | 5343c7b | 2016-02-11 16:41:21 -0500 | [diff] [blame] | 679 | g_sdio.irq_gpio = wilc->dev_irq_num; |
Glen Lee | 5397cbc | 2016-01-25 16:35:09 +0900 | [diff] [blame] | 680 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 681 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 682 | /** |
| 683 | * function 0 csa enable |
| 684 | **/ |
| 685 | cmd.read_write = 1; |
| 686 | cmd.function = 0; |
| 687 | cmd.raw = 1; |
| 688 | cmd.address = 0x100; |
| 689 | cmd.data = 0x80; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 690 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 691 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 692 | dev_err(&func->dev, "Fail cmd 52, enable csa...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 693 | goto _fail_; |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * function 0 block size |
| 698 | **/ |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 699 | if (!sdio_set_func0_block_size(wilc, WILC_SDIO_BLOCK_SIZE)) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 700 | dev_err(&func->dev, "Fail cmd 52, set func 0 block size...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 701 | goto _fail_; |
| 702 | } |
| 703 | g_sdio.block_size = WILC_SDIO_BLOCK_SIZE; |
| 704 | |
| 705 | /** |
| 706 | * enable func1 IO |
| 707 | **/ |
| 708 | cmd.read_write = 1; |
| 709 | cmd.function = 0; |
| 710 | cmd.raw = 1; |
| 711 | cmd.address = 0x2; |
| 712 | cmd.data = 0x2; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 713 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 714 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 715 | dev_err(&func->dev, |
| 716 | "Fail cmd 52, set IOE register...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 717 | goto _fail_; |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * make sure func 1 is up |
| 722 | **/ |
| 723 | cmd.read_write = 0; |
| 724 | cmd.function = 0; |
| 725 | cmd.raw = 0; |
| 726 | cmd.address = 0x3; |
| 727 | loop = 3; |
| 728 | do { |
| 729 | cmd.data = 0; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 730 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 731 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 732 | dev_err(&func->dev, |
| 733 | "Fail cmd 52, get IOR register...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 734 | goto _fail_; |
| 735 | } |
| 736 | if (cmd.data == 0x2) |
| 737 | break; |
| 738 | } while (loop--); |
| 739 | |
| 740 | if (loop <= 0) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 741 | dev_err(&func->dev, "Fail func 1 is not ready...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 742 | goto _fail_; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * func 1 is ready, set func 1 block size |
| 747 | **/ |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 748 | if (!sdio_set_func1_block_size(wilc, WILC_SDIO_BLOCK_SIZE)) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 749 | dev_err(&func->dev, "Fail set func 1 block size...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 750 | goto _fail_; |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * func 1 interrupt enable |
| 755 | **/ |
| 756 | cmd.read_write = 1; |
| 757 | cmd.function = 0; |
| 758 | cmd.raw = 1; |
| 759 | cmd.address = 0x4; |
| 760 | cmd.data = 0x3; |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 761 | ret = wilc_sdio_cmd52(wilc, &cmd); |
| 762 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 763 | dev_err(&func->dev, "Fail cmd 52, set IEN register...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 764 | goto _fail_; |
| 765 | } |
| 766 | |
| 767 | /** |
| 768 | * make sure can read back chip id correctly |
| 769 | **/ |
Glen Lee | 5397cbc | 2016-01-25 16:35:09 +0900 | [diff] [blame] | 770 | if (!resume) { |
| 771 | if (!sdio_read_reg(wilc, 0x1000, &chipid)) { |
| 772 | dev_err(&func->dev, "Fail cmd read chip id...\n"); |
| 773 | goto _fail_; |
| 774 | } |
| 775 | dev_err(&func->dev, "chipid (%08x)\n", chipid); |
| 776 | if ((chipid & 0xfff) > 0x2a0) |
| 777 | g_sdio.has_thrpt_enh3 = 1; |
| 778 | else |
| 779 | g_sdio.has_thrpt_enh3 = 0; |
| 780 | dev_info(&func->dev, "has_thrpt_enh3 = %d...\n", |
| 781 | g_sdio.has_thrpt_enh3); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 782 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 783 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 784 | return 1; |
| 785 | |
| 786 | _fail_: |
| 787 | |
| 788 | return 0; |
| 789 | } |
| 790 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 791 | static int sdio_read_size(struct wilc *wilc, u32 *size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 792 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 793 | u32 tmp; |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 794 | struct sdio_cmd52 cmd; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 795 | |
| 796 | /** |
| 797 | * Read DMA count in words |
| 798 | **/ |
Tony Cho | 202f66a | 2015-07-28 17:47:35 +0900 | [diff] [blame] | 799 | cmd.read_write = 0; |
| 800 | cmd.function = 0; |
| 801 | cmd.raw = 0; |
| 802 | cmd.address = 0xf2; |
| 803 | cmd.data = 0; |
Glen Lee | ea5779b | 2015-11-18 15:11:27 +0900 | [diff] [blame] | 804 | wilc_sdio_cmd52(wilc, &cmd); |
Tony Cho | 202f66a | 2015-07-28 17:47:35 +0900 | [diff] [blame] | 805 | tmp = cmd.data; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 806 | |
Tony Cho | 202f66a | 2015-07-28 17:47:35 +0900 | [diff] [blame] | 807 | /* cmd.read_write = 0; */ |
| 808 | /* cmd.function = 0; */ |
| 809 | /* cmd.raw = 0; */ |
| 810 | cmd.address = 0xf3; |
| 811 | cmd.data = 0; |
Glen Lee | ea5779b | 2015-11-18 15:11:27 +0900 | [diff] [blame] | 812 | wilc_sdio_cmd52(wilc, &cmd); |
Tony Cho | 202f66a | 2015-07-28 17:47:35 +0900 | [diff] [blame] | 813 | tmp |= (cmd.data << 8); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 814 | |
| 815 | *size = tmp; |
| 816 | return 1; |
| 817 | } |
| 818 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 819 | static int sdio_read_int(struct wilc *wilc, u32 *int_status) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 820 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 821 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 822 | u32 tmp; |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 823 | struct sdio_cmd52 cmd; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 824 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 825 | sdio_read_size(wilc, &tmp); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 826 | |
| 827 | /** |
| 828 | * Read IRQ flags |
| 829 | **/ |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 830 | if (!g_sdio.irq_gpio) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 831 | int i; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 832 | |
Colin Ian King | 6e18378 | 2018-12-19 16:30:07 +0000 | [diff] [blame] | 833 | cmd.read_write = 0; |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 834 | cmd.function = 1; |
| 835 | cmd.address = 0x04; |
| 836 | cmd.data = 0; |
Glen Lee | ea5779b | 2015-11-18 15:11:27 +0900 | [diff] [blame] | 837 | wilc_sdio_cmd52(wilc, &cmd); |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 838 | |
| 839 | if (cmd.data & BIT(0)) |
| 840 | tmp |= INT_0; |
| 841 | if (cmd.data & BIT(2)) |
| 842 | tmp |= INT_1; |
| 843 | if (cmd.data & BIT(3)) |
| 844 | tmp |= INT_2; |
| 845 | if (cmd.data & BIT(4)) |
| 846 | tmp |= INT_3; |
| 847 | if (cmd.data & BIT(5)) |
| 848 | tmp |= INT_4; |
| 849 | if (cmd.data & BIT(6)) |
| 850 | tmp |= INT_5; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 851 | for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { |
| 852 | if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 853 | dev_err(&func->dev, |
| 854 | "Unexpected interrupt (1) : tmp=%x, data=%x\n", |
| 855 | tmp, cmd.data); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 856 | break; |
| 857 | } |
| 858 | } |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 859 | } else { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 860 | u32 irq_flags; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 861 | |
| 862 | cmd.read_write = 0; |
| 863 | cmd.function = 0; |
| 864 | cmd.raw = 0; |
| 865 | cmd.address = 0xf7; |
| 866 | cmd.data = 0; |
Glen Lee | ea5779b | 2015-11-18 15:11:27 +0900 | [diff] [blame] | 867 | wilc_sdio_cmd52(wilc, &cmd); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 868 | irq_flags = cmd.data & 0x1f; |
| 869 | tmp |= ((irq_flags >> 0) << IRG_FLAGS_OFFSET); |
| 870 | } |
| 871 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 872 | *int_status = tmp; |
| 873 | |
| 874 | return 1; |
| 875 | } |
| 876 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 877 | static int sdio_clear_int_ext(struct wilc *wilc, u32 val) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 878 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 879 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 880 | int ret; |
| 881 | |
| 882 | if (g_sdio.has_thrpt_enh3) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 883 | u32 reg; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 884 | |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 885 | if (g_sdio.irq_gpio) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 886 | u32 flags; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 887 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 888 | flags = val & (BIT(MAX_NUN_INT_THRPT_ENH2) - 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 889 | reg = flags; |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 890 | } else { |
| 891 | reg = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 892 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 893 | /* select VMM table 0 */ |
| 894 | if ((val & SEL_VMM_TBL0) == SEL_VMM_TBL0) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 895 | reg |= BIT(5); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 896 | /* select VMM table 1 */ |
| 897 | if ((val & SEL_VMM_TBL1) == SEL_VMM_TBL1) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 898 | reg |= BIT(6); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 899 | /* enable VMM */ |
| 900 | if ((val & EN_VMM) == EN_VMM) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 901 | reg |= BIT(7); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 902 | if (reg) { |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 903 | struct sdio_cmd52 cmd; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 904 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 905 | cmd.read_write = 1; |
| 906 | cmd.function = 0; |
| 907 | cmd.raw = 0; |
| 908 | cmd.address = 0xf8; |
| 909 | cmd.data = reg; |
| 910 | |
Glen Lee | ea5779b | 2015-11-18 15:11:27 +0900 | [diff] [blame] | 911 | ret = wilc_sdio_cmd52(wilc, &cmd); |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 912 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 913 | dev_err(&func->dev, |
| 914 | "Failed cmd52, set 0xf8 data (%d) ...\n", |
| 915 | __LINE__); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 916 | goto _fail_; |
| 917 | } |
| 918 | |
| 919 | } |
| 920 | } else { |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 921 | if (g_sdio.irq_gpio) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 922 | /* see below. has_thrpt_enh2 uses register 0xf8 to clear interrupts. */ |
| 923 | /* Cannot clear multiple interrupts. Must clear each interrupt individually */ |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 924 | u32 flags; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 925 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 926 | flags = val & (BIT(MAX_NUM_INT) - 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 927 | if (flags) { |
| 928 | int i; |
| 929 | |
| 930 | ret = 1; |
| 931 | for (i = 0; i < g_sdio.nint; i++) { |
| 932 | if (flags & 1) { |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 933 | struct sdio_cmd52 cmd; |
Tony Cho | 9c84469 | 2015-07-28 17:47:24 +0900 | [diff] [blame] | 934 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 935 | cmd.read_write = 1; |
| 936 | cmd.function = 0; |
| 937 | cmd.raw = 0; |
| 938 | cmd.address = 0xf8; |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 939 | cmd.data = BIT(i); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 940 | |
Glen Lee | ea5779b | 2015-11-18 15:11:27 +0900 | [diff] [blame] | 941 | ret = wilc_sdio_cmd52(wilc, &cmd); |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 942 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 943 | dev_err(&func->dev, |
| 944 | "Failed cmd52, set 0xf8 data (%d) ...\n", |
| 945 | __LINE__); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 946 | goto _fail_; |
| 947 | } |
| 948 | |
| 949 | } |
| 950 | if (!ret) |
| 951 | break; |
| 952 | flags >>= 1; |
| 953 | } |
Tony Cho | 4aa85772 | 2015-07-28 17:47:25 +0900 | [diff] [blame] | 954 | if (!ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 955 | goto _fail_; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 956 | for (i = g_sdio.nint; i < MAX_NUM_INT; i++) { |
| 957 | if (flags & 1) |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 958 | dev_err(&func->dev, |
| 959 | "Unexpected interrupt cleared %d...\n", |
| 960 | i); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 961 | flags >>= 1; |
| 962 | } |
| 963 | } |
| 964 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 965 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 966 | { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 967 | u32 vmm_ctl; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 968 | |
| 969 | vmm_ctl = 0; |
| 970 | /* select VMM table 0 */ |
| 971 | if ((val & SEL_VMM_TBL0) == SEL_VMM_TBL0) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 972 | vmm_ctl |= BIT(0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 973 | /* select VMM table 1 */ |
| 974 | if ((val & SEL_VMM_TBL1) == SEL_VMM_TBL1) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 975 | vmm_ctl |= BIT(1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 976 | /* enable VMM */ |
| 977 | if ((val & EN_VMM) == EN_VMM) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 978 | vmm_ctl |= BIT(2); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 979 | |
| 980 | if (vmm_ctl) { |
Chaehyun Lim | a91632f | 2016-03-03 14:28:20 +0900 | [diff] [blame] | 981 | struct sdio_cmd52 cmd; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 982 | |
| 983 | cmd.read_write = 1; |
| 984 | cmd.function = 0; |
| 985 | cmd.raw = 0; |
| 986 | cmd.address = 0xf6; |
| 987 | cmd.data = vmm_ctl; |
Glen Lee | ea5779b | 2015-11-18 15:11:27 +0900 | [diff] [blame] | 988 | ret = wilc_sdio_cmd52(wilc, &cmd); |
Glen Lee | 28e9ad2 | 2015-12-21 14:18:19 +0900 | [diff] [blame] | 989 | if (ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 990 | dev_err(&func->dev, |
| 991 | "Failed cmd52, set 0xf6 data (%d) ...\n", |
| 992 | __LINE__); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 993 | goto _fail_; |
| 994 | } |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | return 1; |
| 1000 | _fail_: |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1004 | static int sdio_sync_ext(struct wilc *wilc, int nint) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1005 | { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1006 | struct sdio_func *func = dev_to_sdio_func(wilc->dev); |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1007 | u32 reg; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1008 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1009 | if (nint > MAX_NUM_INT) { |
Colin Ian King | 95b8cb8 | 2016-06-23 14:14:07 +0100 | [diff] [blame] | 1010 | dev_err(&func->dev, "Too many interrupts (%d)...\n", nint); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1011 | return 0; |
| 1012 | } |
| 1013 | if (nint > MAX_NUN_INT_THRPT_ENH2) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1014 | dev_err(&func->dev, |
| 1015 | "Cannot support more than 5 interrupts when has_thrpt_enh2=1.\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1016 | return 0; |
| 1017 | } |
| 1018 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1019 | g_sdio.nint = nint; |
| 1020 | |
| 1021 | /** |
| 1022 | * Disable power sequencer |
| 1023 | **/ |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1024 | if (!sdio_read_reg(wilc, WILC_MISC, ®)) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1025 | dev_err(&func->dev, "Failed read misc reg...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
| 1028 | |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1029 | reg &= ~BIT(8); |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1030 | if (!sdio_write_reg(wilc, WILC_MISC, reg)) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1031 | dev_err(&func->dev, "Failed write misc reg...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1032 | return 0; |
| 1033 | } |
| 1034 | |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 1035 | if (g_sdio.irq_gpio) { |
Chaehyun Lim | fbc2fe1 | 2015-09-15 14:06:16 +0900 | [diff] [blame] | 1036 | u32 reg; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1037 | int ret, i; |
| 1038 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1039 | /** |
| 1040 | * interrupt pin mux select |
| 1041 | **/ |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1042 | ret = sdio_read_reg(wilc, WILC_PIN_MUX_0, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1043 | if (!ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1044 | dev_err(&func->dev, "Failed read reg (%08x)...\n", |
| 1045 | WILC_PIN_MUX_0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1046 | return 0; |
| 1047 | } |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1048 | reg |= BIT(8); |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1049 | ret = sdio_write_reg(wilc, WILC_PIN_MUX_0, reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1050 | if (!ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1051 | dev_err(&func->dev, "Failed write reg (%08x)...\n", |
| 1052 | WILC_PIN_MUX_0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
| 1057 | * interrupt enable |
| 1058 | **/ |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1059 | ret = sdio_read_reg(wilc, WILC_INTR_ENABLE, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1060 | if (!ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1061 | dev_err(&func->dev, "Failed read reg (%08x)...\n", |
| 1062 | WILC_INTR_ENABLE); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1063 | return 0; |
| 1064 | } |
| 1065 | |
Tony Cho | 4aa85772 | 2015-07-28 17:47:25 +0900 | [diff] [blame] | 1066 | for (i = 0; (i < 5) && (nint > 0); i++, nint--) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1067 | reg |= BIT((27 + i)); |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1068 | ret = sdio_write_reg(wilc, WILC_INTR_ENABLE, reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1069 | if (!ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1070 | dev_err(&func->dev, "Failed write reg (%08x)...\n", |
| 1071 | WILC_INTR_ENABLE); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1072 | return 0; |
| 1073 | } |
| 1074 | if (nint) { |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1075 | ret = sdio_read_reg(wilc, WILC_INTR2_ENABLE, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1076 | if (!ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1077 | dev_err(&func->dev, |
| 1078 | "Failed read reg (%08x)...\n", |
| 1079 | WILC_INTR2_ENABLE); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1080 | return 0; |
| 1081 | } |
| 1082 | |
Tony Cho | 4aa85772 | 2015-07-28 17:47:25 +0900 | [diff] [blame] | 1083 | for (i = 0; (i < 3) && (nint > 0); i++, nint--) |
Anish Bhatt | ffda203 | 2015-09-29 12:15:49 -0700 | [diff] [blame] | 1084 | reg |= BIT(i); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1085 | |
Glen Lee | 49dcd0d | 2015-11-18 15:11:26 +0900 | [diff] [blame] | 1086 | ret = sdio_read_reg(wilc, WILC_INTR2_ENABLE, ®); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1087 | if (!ret) { |
Glen Lee | ac1da16 | 2015-12-21 14:18:13 +0900 | [diff] [blame] | 1088 | dev_err(&func->dev, |
| 1089 | "Failed write reg (%08x)...\n", |
| 1090 | WILC_INTR2_ENABLE); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1091 | return 0; |
| 1092 | } |
| 1093 | } |
| 1094 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1095 | return 1; |
| 1096 | } |
| 1097 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1098 | /******************************************** |
| 1099 | * |
| 1100 | * Global sdio HIF function table |
| 1101 | * |
| 1102 | ********************************************/ |
| 1103 | |
Arnd Bergmann | 7d37a4a | 2015-11-16 15:05:05 +0100 | [diff] [blame] | 1104 | const struct wilc_hif_func wilc_hif_sdio = { |
| 1105 | .hif_init = sdio_init, |
| 1106 | .hif_deinit = sdio_deinit, |
| 1107 | .hif_read_reg = sdio_read_reg, |
| 1108 | .hif_write_reg = sdio_write_reg, |
| 1109 | .hif_block_rx = sdio_read, |
| 1110 | .hif_block_tx = sdio_write, |
Arnd Bergmann | 7d37a4a | 2015-11-16 15:05:05 +0100 | [diff] [blame] | 1111 | .hif_read_int = sdio_read_int, |
| 1112 | .hif_clear_int_ext = sdio_clear_int_ext, |
| 1113 | .hif_read_size = sdio_read_size, |
| 1114 | .hif_block_tx_ext = sdio_write, |
| 1115 | .hif_block_rx_ext = sdio_read, |
| 1116 | .hif_sync_ext = sdio_sync_ext, |
Arnd Bergmann | 5547c1f | 2015-11-16 15:05:06 +0100 | [diff] [blame] | 1117 | .enable_interrupt = wilc_sdio_enable_interrupt, |
| 1118 | .disable_interrupt = wilc_sdio_disable_interrupt, |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1119 | }; |
| 1120 | |