Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: Separate out protocol ops

Move protocol operations and definitions into their own files
in an effort to separate protocol handling and bus
arbitration more clearly.

Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>

+844 -517
+2 -2
drivers/mmc/card/block.c
··· 32 32 33 33 #include <linux/mmc/card.h> 34 34 #include <linux/mmc/host.h> 35 - #include <linux/mmc/protocol.h> 36 - #include <linux/mmc/host.h> 35 + #include <linux/mmc/mmc.h> 36 + #include <linux/mmc/sd.h> 37 37 38 38 #include <asm/system.h> 39 39 #include <asm/uaccess.h>
+1 -1
drivers/mmc/core/Makefile
··· 7 7 endif 8 8 9 9 obj-$(CONFIG_MMC) += mmc_core.o 10 - mmc_core-y := core.o sysfs.o 10 + mmc_core-y := core.o sysfs.o mmc_ops.o sd_ops.o 11 11
+64 -447
drivers/mmc/core/core.c
··· 23 23 24 24 #include <linux/mmc/card.h> 25 25 #include <linux/mmc/host.h> 26 - #include <linux/mmc/protocol.h> 26 + #include <linux/mmc/mmc.h> 27 + #include <linux/mmc/sd.h> 27 28 28 29 #include "core.h" 30 + #include "sysfs.h" 31 + 32 + #include "mmc_ops.h" 33 + #include "sd_ops.h" 29 34 30 35 #define CMD_RETRIES 3 31 36 ··· 196 191 EXPORT_SYMBOL(mmc_wait_for_cmd); 197 192 198 193 /** 199 - * mmc_wait_for_app_cmd - start an application command and wait for 200 - completion 201 - * @host: MMC host to start command 202 - * @rca: RCA to send MMC_APP_CMD to 203 - * @cmd: MMC command to start 204 - * @retries: maximum number of retries 205 - * 206 - * Sends a MMC_APP_CMD, checks the card response, sends the command 207 - * in the parameter and waits for it to complete. Return any error 208 - * that occurred while the command was executing. Do not attempt to 209 - * parse the response. 210 - */ 211 - int mmc_wait_for_app_cmd(struct mmc_host *host, unsigned int rca, 212 - struct mmc_command *cmd, int retries) 213 - { 214 - struct mmc_request mrq; 215 - struct mmc_command appcmd; 216 - 217 - int i, err; 218 - 219 - BUG_ON(!host->claimed); 220 - BUG_ON(retries < 0); 221 - 222 - err = MMC_ERR_INVALID; 223 - 224 - /* 225 - * We have to resend MMC_APP_CMD for each attempt so 226 - * we cannot use the retries field in mmc_command. 227 - */ 228 - for (i = 0;i <= retries;i++) { 229 - memset(&mrq, 0, sizeof(struct mmc_request)); 230 - 231 - appcmd.opcode = MMC_APP_CMD; 232 - appcmd.arg = rca << 16; 233 - appcmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 234 - appcmd.retries = 0; 235 - memset(appcmd.resp, 0, sizeof(appcmd.resp)); 236 - appcmd.data = NULL; 237 - 238 - mrq.cmd = &appcmd; 239 - appcmd.data = NULL; 240 - 241 - mmc_wait_for_req(host, &mrq); 242 - 243 - if (appcmd.error) { 244 - err = appcmd.error; 245 - continue; 246 - } 247 - 248 - /* Check that card supported application commands */ 249 - if (!(appcmd.resp[0] & R1_APP_CMD)) 250 - return MMC_ERR_FAILED; 251 - 252 - memset(&mrq, 0, sizeof(struct mmc_request)); 253 - 254 - memset(cmd->resp, 0, sizeof(cmd->resp)); 255 - cmd->retries = 0; 256 - 257 - mrq.cmd = cmd; 258 - cmd->data = NULL; 259 - 260 - mmc_wait_for_req(host, &mrq); 261 - 262 - err = cmd->error; 263 - if (cmd->error == MMC_ERR_NONE) 264 - break; 265 - } 266 - 267 - return err; 268 - } 269 - 270 - EXPORT_SYMBOL(mmc_wait_for_app_cmd); 271 - 272 - /** 273 194 * mmc_set_data_timeout - set the timeout for a data command 274 195 * @data: data phase for command 275 196 * @card: the MMC card associated with the data transfer ··· 316 385 host->ops->set_ios(host, ios); 317 386 } 318 387 319 - static int mmc_select_card(struct mmc_card *card) 388 + void mmc_set_chip_select(struct mmc_host *host, int mode) 320 389 { 321 - int err; 322 - struct mmc_command cmd; 323 - 324 - BUG_ON(!card->host->claimed); 325 - 326 - cmd.opcode = MMC_SELECT_CARD; 327 - cmd.arg = card->rca << 16; 328 - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 329 - 330 - err = mmc_wait_for_cmd(card->host, &cmd, CMD_RETRIES); 331 - if (err != MMC_ERR_NONE) 332 - return err; 333 - 334 - /* 335 - * We can only change the bus width of SD cards when 336 - * they are selected so we have to put the handling 337 - * here. 338 - * 339 - * The card is in 1 bit mode by default so 340 - * we only need to change if it supports the 341 - * wider version. 342 - */ 343 - if (mmc_card_sd(card) && 344 - (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4) && 345 - (card->host->caps & MMC_CAP_4_BIT_DATA)) { 346 - 347 - struct mmc_command cmd; 348 - cmd.opcode = SD_APP_SET_BUS_WIDTH; 349 - cmd.arg = SD_BUS_WIDTH_4; 350 - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 351 - 352 - err = mmc_wait_for_app_cmd(card->host, card->rca, 353 - &cmd, CMD_RETRIES); 354 - if (err != MMC_ERR_NONE) 355 - return err; 356 - 357 - card->host->ios.bus_width = MMC_BUS_WIDTH_4; 358 - mmc_set_ios(card->host); 359 - } 360 - 361 - return MMC_ERR_NONE; 362 - } 363 - 364 - 365 - static inline void mmc_delay(unsigned int ms) 366 - { 367 - if (ms < 1000 / HZ) { 368 - cond_resched(); 369 - mdelay(ms); 370 - } else { 371 - msleep(ms); 372 - } 390 + host->ios.chip_select = mode; 391 + mmc_set_ios(host); 373 392 } 374 393 375 394 /* ··· 590 709 } 591 710 592 711 /* 593 - * Tell attached cards to go to IDLE state 594 - */ 595 - static void mmc_idle_cards(struct mmc_host *host) 596 - { 597 - struct mmc_command cmd; 598 - 599 - host->ios.chip_select = MMC_CS_HIGH; 600 - mmc_set_ios(host); 601 - 602 - mmc_delay(1); 603 - 604 - cmd.opcode = MMC_GO_IDLE_STATE; 605 - cmd.arg = 0; 606 - cmd.flags = MMC_RSP_NONE | MMC_CMD_BC; 607 - 608 - mmc_wait_for_cmd(host, &cmd, 0); 609 - 610 - mmc_delay(1); 611 - 612 - host->ios.chip_select = MMC_CS_DONTCARE; 613 - mmc_set_ios(host); 614 - 615 - mmc_delay(1); 616 - } 617 - 618 - /* 619 712 * Apply power to the MMC stack. This is a two-stage process. 620 713 * First, we enable power to the card without the clock running. 621 714 * We then wait a bit for the power to stabilise. Finally, ··· 633 778 mmc_set_ios(host); 634 779 } 635 780 636 - static int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) 637 - { 638 - struct mmc_command cmd; 639 - int i, err = 0; 640 - 641 - cmd.opcode = MMC_SEND_OP_COND; 642 - cmd.arg = ocr; 643 - cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 644 - 645 - for (i = 100; i; i--) { 646 - err = mmc_wait_for_cmd(host, &cmd, 0); 647 - if (err != MMC_ERR_NONE) 648 - break; 649 - 650 - if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0) 651 - break; 652 - 653 - err = MMC_ERR_TIMEOUT; 654 - 655 - mmc_delay(10); 656 - } 657 - 658 - if (rocr) 659 - *rocr = cmd.resp[0]; 660 - 661 - return err; 662 - } 663 - 664 - static int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) 665 - { 666 - struct mmc_command cmd; 667 - int i, err = 0; 668 - 669 - cmd.opcode = SD_APP_OP_COND; 670 - cmd.arg = ocr; 671 - cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 672 - 673 - for (i = 100; i; i--) { 674 - err = mmc_wait_for_app_cmd(host, 0, &cmd, CMD_RETRIES); 675 - if (err != MMC_ERR_NONE) 676 - break; 677 - 678 - if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0) 679 - break; 680 - 681 - err = MMC_ERR_TIMEOUT; 682 - 683 - mmc_delay(10); 684 - } 685 - 686 - if (rocr) 687 - *rocr = cmd.resp[0]; 688 - 689 - return err; 690 - } 691 - 692 - static int mmc_send_if_cond(struct mmc_host *host, u32 ocr, int *rsd2) 693 - { 694 - struct mmc_command cmd; 695 - int err, sd2; 696 - static const u8 test_pattern = 0xAA; 697 - 698 - /* 699 - * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND 700 - * before SD_APP_OP_COND. This command will harmlessly fail for 701 - * SD 1.0 cards. 702 - */ 703 - cmd.opcode = SD_SEND_IF_COND; 704 - cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern; 705 - cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR; 706 - 707 - err = mmc_wait_for_cmd(host, &cmd, 0); 708 - if (err == MMC_ERR_NONE) { 709 - if ((cmd.resp[0] & 0xFF) == test_pattern) { 710 - sd2 = 1; 711 - } else { 712 - sd2 = 0; 713 - err = MMC_ERR_FAILED; 714 - } 715 - } else { 716 - /* 717 - * Treat errors as SD 1.0 card. 718 - */ 719 - sd2 = 0; 720 - err = MMC_ERR_NONE; 721 - } 722 - if (rsd2) 723 - *rsd2 = sd2; 724 - return err; 725 - } 726 - 727 781 /* 728 782 * Discover the card by requesting its CID. 729 783 * ··· 642 878 static void mmc_discover_card(struct mmc_host *host) 643 879 { 644 880 unsigned int err; 645 - 646 - struct mmc_command cmd; 881 + u32 cid[4]; 647 882 648 883 BUG_ON(host->card); 649 884 650 - cmd.opcode = MMC_ALL_SEND_CID; 651 - cmd.arg = 0; 652 - cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR; 653 - 654 - err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 655 - if (err == MMC_ERR_TIMEOUT) { 656 - err = MMC_ERR_NONE; 657 - return; 658 - } 885 + err = mmc_all_send_cid(host, cid); 659 886 if (err != MMC_ERR_NONE) { 660 887 printk(KERN_ERR "%s: error requesting CID: %d\n", 661 888 mmc_hostname(host), err); 662 889 return; 663 890 } 664 891 665 - host->card = mmc_alloc_card(host, cmd.resp); 892 + host->card = mmc_alloc_card(host, cid); 666 893 if (IS_ERR(host->card)) { 667 894 err = PTR_ERR(host->card); 668 895 host->card = NULL; ··· 663 908 if (host->mode == MMC_MODE_SD) { 664 909 host->card->type = MMC_TYPE_SD; 665 910 666 - cmd.opcode = SD_SEND_RELATIVE_ADDR; 667 - cmd.arg = 0; 668 - cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR; 669 - 670 - err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 911 + err = mmc_send_relative_addr(host, &host->card->rca); 671 912 if (err != MMC_ERR_NONE) 672 913 mmc_card_set_dead(host->card); 673 914 else { 674 - host->card->rca = cmd.resp[0] >> 16; 675 - 676 915 if (!host->ops->get_ro) { 677 916 printk(KERN_WARNING "%s: host does not " 678 917 "support reading read-only " ··· 681 932 host->card->type = MMC_TYPE_MMC; 682 933 host->card->rca = 1; 683 934 684 - cmd.opcode = MMC_SET_RELATIVE_ADDR; 685 - cmd.arg = host->card->rca << 16; 686 - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 687 - 688 - err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 935 + err = mmc_set_relative_addr(host->card); 689 936 if (err != MMC_ERR_NONE) 690 937 mmc_card_set_dead(host->card); 691 938 } ··· 689 944 690 945 static void mmc_read_csd(struct mmc_host *host) 691 946 { 692 - struct mmc_command cmd; 693 947 int err; 694 948 695 949 if (!host->card) ··· 696 952 if (mmc_card_dead(host->card)) 697 953 return; 698 954 699 - cmd.opcode = MMC_SEND_CSD; 700 - cmd.arg = host->card->rca << 16; 701 - cmd.flags = MMC_RSP_R2 | MMC_CMD_AC; 702 - 703 - err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 955 + err = mmc_send_csd(host->card, host->card->raw_csd); 704 956 if (err != MMC_ERR_NONE) { 705 957 mmc_card_set_dead(host->card); 706 958 return; 707 959 } 708 - 709 - memcpy(host->card->raw_csd, cmd.resp, sizeof(host->card->raw_csd)); 710 960 711 961 mmc_decode_csd(host->card); 712 962 mmc_decode_cid(host->card); ··· 709 971 static void mmc_process_ext_csd(struct mmc_host *host) 710 972 { 711 973 int err; 712 - 713 - struct mmc_request mrq; 714 - struct mmc_command cmd; 715 - struct mmc_data data; 716 - 717 974 u8 *ext_csd; 718 - struct scatterlist sg; 719 975 720 976 if (!host->card) 721 977 return; ··· 732 1000 return; 733 1001 } 734 1002 735 - memset(&cmd, 0, sizeof(struct mmc_command)); 736 - 737 - cmd.opcode = MMC_SEND_EXT_CSD; 738 - cmd.arg = 0; 739 - cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 740 - 741 - memset(&data, 0, sizeof(struct mmc_data)); 742 - 743 - mmc_set_data_timeout(&data, host->card, 0); 744 - 745 - data.blksz = 512; 746 - data.blocks = 1; 747 - data.flags = MMC_DATA_READ; 748 - data.sg = &sg; 749 - data.sg_len = 1; 750 - 751 - memset(&mrq, 0, sizeof(struct mmc_request)); 752 - 753 - mrq.cmd = &cmd; 754 - mrq.data = &data; 755 - 756 - sg_init_one(&sg, ext_csd, 512); 757 - 758 - mmc_wait_for_req(host, &mrq); 759 - 760 - if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE) { 1003 + err = mmc_send_ext_csd(host->card, ext_csd); 1004 + if (err != MMC_ERR_NONE) { 761 1005 if (host->card->csd.capacity == (4096 * 512)) { 762 1006 printk(KERN_ERR "%s: unable to read EXT_CSD " 763 1007 "on a possible high capacity card. " ··· 774 1066 775 1067 if (host->caps & MMC_CAP_MMC_HIGHSPEED) { 776 1068 /* Activate highspeed support. */ 777 - cmd.opcode = MMC_SWITCH; 778 - cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | 779 - (EXT_CSD_HS_TIMING << 16) | 780 - (1 << 8) | 781 - EXT_CSD_CMD_SET_NORMAL; 782 - cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 783 - 784 - err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 1069 + err = mmc_switch(host->card, MMC_SWITCH_MODE_WRITE_BYTE, 1070 + EXT_CSD_HS_TIMING, 1); 785 1071 if (err != MMC_ERR_NONE) { 786 1072 printk("%s: failed to switch card to mmc v4 " 787 1073 "high-speed mode.\n", ··· 792 1090 /* Check for host support for wide-bus modes. */ 793 1091 if (host->caps & MMC_CAP_4_BIT_DATA) { 794 1092 /* Activate 4-bit support. */ 795 - cmd.opcode = MMC_SWITCH; 796 - cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | 797 - (EXT_CSD_BUS_WIDTH << 16) | 798 - (EXT_CSD_BUS_WIDTH_4 << 8) | 799 - EXT_CSD_CMD_SET_NORMAL; 800 - cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 801 - 802 - err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 1093 + err = mmc_switch(host->card, MMC_SWITCH_MODE_WRITE_BYTE, 1094 + EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4 | 1095 + EXT_CSD_CMD_SET_NORMAL); 803 1096 if (err != MMC_ERR_NONE) { 804 1097 printk("%s: failed to switch card to " 805 1098 "mmc v4 4-bit bus mode.\n", ··· 813 1116 static void mmc_read_scr(struct mmc_host *host) 814 1117 { 815 1118 int err; 816 - struct mmc_request mrq; 817 - struct mmc_command cmd; 818 - struct mmc_data data; 819 - struct scatterlist sg; 820 1119 821 1120 if (!host->card) 822 1121 return; ··· 821 1128 if (!mmc_card_sd(host->card)) 822 1129 return; 823 1130 824 - memset(&cmd, 0, sizeof(struct mmc_command)); 825 - 826 - cmd.opcode = MMC_APP_CMD; 827 - cmd.arg = host->card->rca << 16; 828 - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 829 - 830 - err = mmc_wait_for_cmd(host, &cmd, 0); 831 - if ((err != MMC_ERR_NONE) || !(cmd.resp[0] & R1_APP_CMD)) { 1131 + err = mmc_app_send_scr(host->card, host->card->raw_scr); 1132 + if (err != MMC_ERR_NONE) { 832 1133 mmc_card_set_dead(host->card); 833 1134 return; 834 1135 } 835 - 836 - memset(&cmd, 0, sizeof(struct mmc_command)); 837 - 838 - cmd.opcode = SD_APP_SEND_SCR; 839 - cmd.arg = 0; 840 - cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 841 - 842 - memset(&data, 0, sizeof(struct mmc_data)); 843 - 844 - mmc_set_data_timeout(&data, host->card, 0); 845 - 846 - data.blksz = 1 << 3; 847 - data.blocks = 1; 848 - data.flags = MMC_DATA_READ; 849 - data.sg = &sg; 850 - data.sg_len = 1; 851 - 852 - memset(&mrq, 0, sizeof(struct mmc_request)); 853 - 854 - mrq.cmd = &cmd; 855 - mrq.data = &data; 856 - 857 - sg_init_one(&sg, (u8*)host->card->raw_scr, 8); 858 - 859 - mmc_wait_for_req(host, &mrq); 860 - 861 - if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE) { 862 - mmc_card_set_dead(host->card); 863 - return; 864 - } 865 - 866 - host->card->raw_scr[0] = ntohl(host->card->raw_scr[0]); 867 - host->card->raw_scr[1] = ntohl(host->card->raw_scr[1]); 868 1136 869 1137 mmc_decode_scr(host->card); 870 1138 } 871 1139 872 1140 static void mmc_read_switch_caps(struct mmc_host *host) 873 1141 { 874 - struct mmc_request mrq; 875 - struct mmc_command cmd; 876 - struct mmc_data data; 1142 + int err; 877 1143 unsigned char *status; 878 - struct scatterlist sg; 879 1144 880 1145 if (!(host->caps & MMC_CAP_SD_HIGHSPEED)) 881 1146 return; ··· 855 1204 return; 856 1205 } 857 1206 858 - memset(&cmd, 0, sizeof(struct mmc_command)); 859 - 860 - cmd.opcode = SD_SWITCH; 861 - cmd.arg = 0x00FFFFF1; 862 - cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 863 - 864 - memset(&data, 0, sizeof(struct mmc_data)); 865 - 866 - mmc_set_data_timeout(&data, host->card, 0); 867 - 868 - data.blksz = 64; 869 - data.blocks = 1; 870 - data.flags = MMC_DATA_READ; 871 - data.sg = &sg; 872 - data.sg_len = 1; 873 - 874 - memset(&mrq, 0, sizeof(struct mmc_request)); 875 - 876 - mrq.cmd = &cmd; 877 - mrq.data = &data; 878 - 879 - sg_init_one(&sg, status, 64); 880 - 881 - mmc_wait_for_req(host, &mrq); 882 - 883 - if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE) { 1207 + err = mmc_sd_switch(host->card, SD_SWITCH_CHECK, 1208 + SD_SWITCH_GRP_ACCESS, SD_SWITCH_ACCESS_HS, status); 1209 + if (err != MMC_ERR_NONE) { 884 1210 printk("%s: unable to read switch capabilities, " 885 1211 "performance might suffer.\n", 886 1212 mmc_hostname(host)); ··· 867 1239 if (status[13] & 0x02) 868 1240 host->card->sw_caps.hs_max_dtr = 50000000; 869 1241 870 - memset(&cmd, 0, sizeof(struct mmc_command)); 871 - 872 - cmd.opcode = SD_SWITCH; 873 - cmd.arg = 0x80FFFFF1; 874 - cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 875 - 876 - memset(&data, 0, sizeof(struct mmc_data)); 877 - 878 - mmc_set_data_timeout(&data, host->card, 0); 879 - 880 - data.blksz = 64; 881 - data.blocks = 1; 882 - data.flags = MMC_DATA_READ; 883 - data.sg = &sg; 884 - data.sg_len = 1; 885 - 886 - memset(&mrq, 0, sizeof(struct mmc_request)); 887 - 888 - mrq.cmd = &cmd; 889 - mrq.data = &data; 890 - 891 - sg_init_one(&sg, status, 64); 892 - 893 - mmc_wait_for_req(host, &mrq); 894 - 895 - if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE || 896 - (status[16] & 0xF) != 1) { 1242 + err = mmc_sd_switch(host->card, SD_SWITCH_SET, 1243 + SD_SWITCH_GRP_ACCESS, SD_SWITCH_ACCESS_HS, status); 1244 + if (err != MMC_ERR_NONE || (status[16] & 0xF) != 1) { 897 1245 printk(KERN_WARNING "%s: Problem switching card " 898 1246 "into high-speed mode!\n", 899 1247 mmc_hostname(host)); ··· 918 1314 */ 919 1315 static void mmc_check_card(struct mmc_card *card) 920 1316 { 921 - struct mmc_command cmd; 922 1317 int err; 923 1318 924 1319 BUG_ON(!card); 925 1320 926 - cmd.opcode = MMC_SEND_STATUS; 927 - cmd.arg = card->rca << 16; 928 - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 929 - 930 - err = mmc_wait_for_cmd(card->host, &cmd, CMD_RETRIES); 1321 + err = mmc_send_status(card, NULL); 931 1322 if (err == MMC_ERR_NONE) 932 1323 return; 933 1324 ··· 937 1338 host->mode = MMC_MODE_SD; 938 1339 939 1340 mmc_power_up(host); 940 - mmc_idle_cards(host); 1341 + mmc_go_idle(host); 941 1342 942 - err = mmc_send_if_cond(host, host->ocr_avail, NULL); 1343 + err = mmc_send_if_cond(host, host->ocr_avail); 943 1344 if (err != MMC_ERR_NONE) { 944 1345 return; 945 1346 } ··· 968 1369 * state. We wait 1ms to give cards time to 969 1370 * respond. 970 1371 */ 971 - mmc_idle_cards(host); 1372 + mmc_go_idle(host); 972 1373 973 1374 /* 974 1375 * Send the selected OCR multiple times... until the cards ··· 976 1377 * (My SanDisk card seems to need this.) 977 1378 */ 978 1379 if (host->mode == MMC_MODE_SD) { 979 - int err, sd2; 980 - err = mmc_send_if_cond(host, host->ocr, &sd2); 981 - if (err == MMC_ERR_NONE) { 982 - /* 983 - * If SD_SEND_IF_COND indicates an SD 2.0 984 - * compliant card and we should set bit 30 985 - * of the ocr to indicate that we can handle 986 - * block-addressed SDHC cards. 987 - */ 988 - mmc_send_app_op_cond(host, host->ocr | (sd2 << 30), NULL); 989 - } 1380 + /* 1381 + * If SD_SEND_IF_COND indicates an SD 2.0 1382 + * compliant card and we should set bit 30 1383 + * of the ocr to indicate that we can handle 1384 + * block-addressed SDHC cards. 1385 + */ 1386 + err = mmc_send_if_cond(host, host->ocr); 1387 + if (err == MMC_ERR_NONE) 1388 + ocr = host->ocr | (1 << 30); 1389 + 1390 + mmc_send_app_op_cond(host, ocr, NULL); 990 1391 } else { 991 1392 /* The extra bit indicates that we support high capacity */ 992 1393 mmc_send_op_cond(host, host->ocr | (1 << 30), NULL); ··· 1006 1407 err = mmc_select_card(host->card); 1007 1408 if (err != MMC_ERR_NONE) 1008 1409 mmc_card_set_dead(host->card); 1410 + } 1411 + 1412 + /* 1413 + * The card is in 1 bit mode by default so 1414 + * we only need to change if it supports the 1415 + * wider version. 1416 + */ 1417 + if (host->card && !mmc_card_dead(host->card) && 1418 + mmc_card_sd(host->card) && 1419 + (host->card->scr.bus_widths & SD_SCR_BUS_WIDTH_4) && 1420 + (host->card->host->caps & MMC_CAP_4_BIT_DATA)) { 1421 + err = mmc_app_set_bus_width(host->card, SD_BUS_WIDTH_4); 1422 + if (err != MMC_ERR_NONE) 1423 + mmc_card_set_dead(host->card); 1424 + else { 1425 + host->ios.bus_width = MMC_BUS_WIDTH_4; 1426 + mmc_set_ios(host); 1427 + } 1009 1428 } 1010 1429 1011 1430 if (host->mode == MMC_MODE_SD) {
+19 -13
drivers/mmc/core/core.h
··· 2 2 * linux/drivers/mmc/core/core.h 3 3 * 4 4 * Copyright (C) 2003 Russell King, All Rights Reserved. 5 + * Copyright 2007 Pierre Ossman 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify 7 8 * it under the terms of the GNU General Public License version 2 as 8 9 * published by the Free Software Foundation. 9 10 */ 10 - #ifndef _MMC_CORE_H 11 - #define _MMC_CORE_H 12 - /* core-internal functions */ 13 - void mmc_init_card(struct mmc_card *card, struct mmc_host *host); 14 - int mmc_register_card(struct mmc_card *card); 15 - void mmc_remove_card(struct mmc_card *card); 11 + #ifndef _MMC_CORE_CORE_H 12 + #define _MMC_CORE_CORE_H 16 13 17 - struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev); 18 - int mmc_add_host_sysfs(struct mmc_host *host); 19 - void mmc_remove_host_sysfs(struct mmc_host *host); 20 - void mmc_free_host_sysfs(struct mmc_host *host); 14 + #include <linux/delay.h> 21 15 22 - int mmc_schedule_work(struct work_struct *work); 23 - int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay); 24 - void mmc_flush_scheduled_work(void); 16 + #define MMC_CMD_RETRIES 3 17 + 18 + void mmc_set_chip_select(struct mmc_host *host, int mode); 19 + 20 + static inline void mmc_delay(unsigned int ms) 21 + { 22 + if (ms < 1000 / HZ) { 23 + cond_resched(); 24 + mdelay(ms); 25 + } else { 26 + msleep(ms); 27 + } 28 + } 29 + 25 30 #endif 31 +
+276
drivers/mmc/core/mmc_ops.c
··· 1 + /* 2 + * linux/drivers/mmc/mmc_ops.h 3 + * 4 + * Copyright 2006-2007 Pierre Ossman 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or (at 9 + * your option) any later version. 10 + */ 11 + 12 + #include <linux/types.h> 13 + #include <asm/scatterlist.h> 14 + #include <linux/scatterlist.h> 15 + 16 + #include <linux/mmc/host.h> 17 + #include <linux/mmc/card.h> 18 + #include <linux/mmc/mmc.h> 19 + 20 + #include "core.h" 21 + #include "mmc_ops.h" 22 + 23 + static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card) 24 + { 25 + int err; 26 + struct mmc_command cmd; 27 + 28 + BUG_ON(!host); 29 + 30 + memset(&cmd, 0, sizeof(struct mmc_command)); 31 + 32 + cmd.opcode = MMC_SELECT_CARD; 33 + 34 + if (card) { 35 + cmd.arg = card->rca << 16; 36 + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 37 + } else { 38 + cmd.arg = 0; 39 + cmd.flags = MMC_RSP_NONE | MMC_CMD_AC; 40 + } 41 + 42 + err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); 43 + if (err != MMC_ERR_NONE) 44 + return err; 45 + 46 + return MMC_ERR_NONE; 47 + } 48 + 49 + int mmc_select_card(struct mmc_card *card) 50 + { 51 + BUG_ON(!card); 52 + 53 + return _mmc_select_card(card->host, card); 54 + } 55 + 56 + int mmc_deselect_cards(struct mmc_host *host) 57 + { 58 + return _mmc_select_card(host, NULL); 59 + } 60 + 61 + int mmc_go_idle(struct mmc_host *host) 62 + { 63 + int err; 64 + struct mmc_command cmd; 65 + 66 + mmc_set_chip_select(host, MMC_CS_HIGH); 67 + 68 + mmc_delay(1); 69 + 70 + memset(&cmd, 0, sizeof(struct mmc_command)); 71 + 72 + cmd.opcode = MMC_GO_IDLE_STATE; 73 + cmd.arg = 0; 74 + cmd.flags = MMC_RSP_NONE | MMC_CMD_BC; 75 + 76 + err = mmc_wait_for_cmd(host, &cmd, 0); 77 + 78 + mmc_delay(1); 79 + 80 + mmc_set_chip_select(host, MMC_CS_DONTCARE); 81 + 82 + mmc_delay(1); 83 + 84 + return err; 85 + } 86 + 87 + int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) 88 + { 89 + struct mmc_command cmd; 90 + int i, err = 0; 91 + 92 + BUG_ON(!host); 93 + 94 + memset(&cmd, 0, sizeof(struct mmc_command)); 95 + 96 + cmd.opcode = MMC_SEND_OP_COND; 97 + cmd.arg = ocr; 98 + cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 99 + 100 + for (i = 100; i; i--) { 101 + err = mmc_wait_for_cmd(host, &cmd, 0); 102 + if (err != MMC_ERR_NONE) 103 + break; 104 + 105 + if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0) 106 + break; 107 + 108 + err = MMC_ERR_TIMEOUT; 109 + 110 + mmc_delay(10); 111 + } 112 + 113 + if (rocr) 114 + *rocr = cmd.resp[0]; 115 + 116 + return err; 117 + } 118 + 119 + int mmc_all_send_cid(struct mmc_host *host, u32 *cid) 120 + { 121 + int err; 122 + struct mmc_command cmd; 123 + 124 + BUG_ON(!host); 125 + BUG_ON(!cid); 126 + 127 + memset(&cmd, 0, sizeof(struct mmc_command)); 128 + 129 + cmd.opcode = MMC_ALL_SEND_CID; 130 + cmd.arg = 0; 131 + cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR; 132 + 133 + err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); 134 + if (err != MMC_ERR_NONE) 135 + return err; 136 + 137 + memcpy(cid, cmd.resp, sizeof(u32) * 4); 138 + 139 + return MMC_ERR_NONE; 140 + } 141 + 142 + int mmc_set_relative_addr(struct mmc_card *card) 143 + { 144 + int err; 145 + struct mmc_command cmd; 146 + 147 + BUG_ON(!card); 148 + BUG_ON(!card->host); 149 + 150 + memset(&cmd, 0, sizeof(struct mmc_command)); 151 + 152 + cmd.opcode = MMC_SET_RELATIVE_ADDR; 153 + cmd.arg = card->rca << 16; 154 + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 155 + 156 + err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 157 + if (err != MMC_ERR_NONE) 158 + return err; 159 + 160 + return MMC_ERR_NONE; 161 + } 162 + 163 + int mmc_send_csd(struct mmc_card *card, u32 *csd) 164 + { 165 + int err; 166 + struct mmc_command cmd; 167 + 168 + BUG_ON(!card); 169 + BUG_ON(!card->host); 170 + BUG_ON(!csd); 171 + 172 + memset(&cmd, 0, sizeof(struct mmc_command)); 173 + 174 + cmd.opcode = MMC_SEND_CSD; 175 + cmd.arg = card->rca << 16; 176 + cmd.flags = MMC_RSP_R2 | MMC_CMD_AC; 177 + 178 + err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 179 + if (err != MMC_ERR_NONE) 180 + return err; 181 + 182 + memcpy(csd, cmd.resp, sizeof(u32) * 4); 183 + 184 + return MMC_ERR_NONE; 185 + } 186 + 187 + int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd) 188 + { 189 + struct mmc_request mrq; 190 + struct mmc_command cmd; 191 + struct mmc_data data; 192 + struct scatterlist sg; 193 + 194 + BUG_ON(!card); 195 + BUG_ON(!card->host); 196 + BUG_ON(!ext_csd); 197 + 198 + memset(&mrq, 0, sizeof(struct mmc_request)); 199 + memset(&cmd, 0, sizeof(struct mmc_command)); 200 + memset(&data, 0, sizeof(struct mmc_data)); 201 + 202 + mrq.cmd = &cmd; 203 + mrq.data = &data; 204 + 205 + cmd.opcode = MMC_SEND_EXT_CSD; 206 + cmd.arg = 0; 207 + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 208 + 209 + data.blksz = 512; 210 + data.blocks = 1; 211 + data.flags = MMC_DATA_READ; 212 + data.sg = &sg; 213 + data.sg_len = 1; 214 + 215 + sg_init_one(&sg, ext_csd, 512); 216 + 217 + mmc_set_data_timeout(&data, card, 0); 218 + 219 + mmc_wait_for_req(card->host, &mrq); 220 + 221 + if (cmd.error != MMC_ERR_NONE) 222 + return cmd.error; 223 + if (data.error != MMC_ERR_NONE) 224 + return data.error; 225 + 226 + return MMC_ERR_NONE; 227 + } 228 + 229 + int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value) 230 + { 231 + int err; 232 + struct mmc_command cmd; 233 + 234 + BUG_ON(!card); 235 + BUG_ON(!card->host); 236 + 237 + memset(&cmd, 0, sizeof(struct mmc_command)); 238 + 239 + cmd.opcode = MMC_SWITCH; 240 + cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | 241 + (index << 16) | 242 + (value << 8) | 243 + set; 244 + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 245 + 246 + err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 247 + if (err != MMC_ERR_NONE) 248 + return err; 249 + 250 + return MMC_ERR_NONE; 251 + } 252 + 253 + int mmc_send_status(struct mmc_card *card, u32 *status) 254 + { 255 + int err; 256 + struct mmc_command cmd; 257 + 258 + BUG_ON(!card); 259 + BUG_ON(!card->host); 260 + 261 + memset(&cmd, 0, sizeof(struct mmc_command)); 262 + 263 + cmd.opcode = MMC_SEND_STATUS; 264 + cmd.arg = card->rca << 16; 265 + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 266 + 267 + err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 268 + if (err != MMC_ERR_NONE) 269 + return err; 270 + 271 + if (status) 272 + *status = cmd.resp[0]; 273 + 274 + return MMC_ERR_NONE; 275 + } 276 +
+27
drivers/mmc/core/mmc_ops.h
··· 1 + /* 2 + * linux/drivers/mmc/mmc_ops.h 3 + * 4 + * Copyright 2006-2007 Pierre Ossman 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or (at 9 + * your option) any later version. 10 + */ 11 + 12 + #ifndef _MMC_MMC_OPS_H 13 + #define _MMC_MMC_OPS_H 14 + 15 + int mmc_select_card(struct mmc_card *card); 16 + int mmc_deselect_cards(struct mmc_host *host); 17 + int mmc_go_idle(struct mmc_host *host); 18 + int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); 19 + int mmc_all_send_cid(struct mmc_host *host, u32 *cid); 20 + int mmc_set_relative_addr(struct mmc_card *card); 21 + int mmc_send_csd(struct mmc_card *card, u32 *csd); 22 + int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd); 23 + int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value); 24 + int mmc_send_status(struct mmc_card *card, u32 *status); 25 + 26 + #endif 27 +
+316
drivers/mmc/core/sd_ops.c
··· 1 + /* 2 + * linux/drivers/mmc/sd_ops.h 3 + * 4 + * Copyright 2006-2007 Pierre Ossman 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or (at 9 + * your option) any later version. 10 + */ 11 + 12 + #include <linux/types.h> 13 + #include <asm/scatterlist.h> 14 + #include <linux/scatterlist.h> 15 + 16 + #include <linux/mmc/host.h> 17 + #include <linux/mmc/card.h> 18 + #include <linux/mmc/mmc.h> 19 + #include <linux/mmc/sd.h> 20 + 21 + #include "core.h" 22 + #include "sd_ops.h" 23 + 24 + /** 25 + * mmc_wait_for_app_cmd - start an application command and wait for 26 + completion 27 + * @host: MMC host to start command 28 + * @rca: RCA to send MMC_APP_CMD to 29 + * @cmd: MMC command to start 30 + * @retries: maximum number of retries 31 + * 32 + * Sends a MMC_APP_CMD, checks the card response, sends the command 33 + * in the parameter and waits for it to complete. Return any error 34 + * that occurred while the command was executing. Do not attempt to 35 + * parse the response. 36 + */ 37 + int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card, 38 + struct mmc_command *cmd, int retries) 39 + { 40 + struct mmc_request mrq; 41 + 42 + int i, err; 43 + 44 + BUG_ON(!cmd); 45 + BUG_ON(retries < 0); 46 + 47 + err = MMC_ERR_INVALID; 48 + 49 + /* 50 + * We have to resend MMC_APP_CMD for each attempt so 51 + * we cannot use the retries field in mmc_command. 52 + */ 53 + for (i = 0;i <= retries;i++) { 54 + memset(&mrq, 0, sizeof(struct mmc_request)); 55 + 56 + err = mmc_app_cmd(host, card); 57 + if (err != MMC_ERR_NONE) 58 + continue; 59 + 60 + memset(&mrq, 0, sizeof(struct mmc_request)); 61 + 62 + memset(cmd->resp, 0, sizeof(cmd->resp)); 63 + cmd->retries = 0; 64 + 65 + mrq.cmd = cmd; 66 + cmd->data = NULL; 67 + 68 + mmc_wait_for_req(host, &mrq); 69 + 70 + err = cmd->error; 71 + if (cmd->error == MMC_ERR_NONE) 72 + break; 73 + } 74 + 75 + return err; 76 + } 77 + 78 + EXPORT_SYMBOL(mmc_wait_for_app_cmd); 79 + 80 + int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card) 81 + { 82 + int err; 83 + struct mmc_command cmd; 84 + 85 + BUG_ON(!host); 86 + BUG_ON(card && (card->host != host)); 87 + 88 + cmd.opcode = MMC_APP_CMD; 89 + 90 + if (card) { 91 + cmd.arg = card->rca << 16; 92 + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 93 + } else { 94 + cmd.arg = 0; 95 + cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR; 96 + } 97 + 98 + err = mmc_wait_for_cmd(host, &cmd, 0); 99 + if (err != MMC_ERR_NONE) 100 + return err; 101 + 102 + /* Check that card supported application commands */ 103 + if (!(cmd.resp[0] & R1_APP_CMD)) 104 + return MMC_ERR_FAILED; 105 + 106 + return MMC_ERR_NONE; 107 + } 108 + 109 + int mmc_app_set_bus_width(struct mmc_card *card, int width) 110 + { 111 + int err; 112 + struct mmc_command cmd; 113 + 114 + BUG_ON(!card); 115 + BUG_ON(!card->host); 116 + 117 + memset(&cmd, 0, sizeof(struct mmc_command)); 118 + 119 + cmd.opcode = SD_APP_SET_BUS_WIDTH; 120 + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 121 + 122 + switch (width) { 123 + case MMC_BUS_WIDTH_1: 124 + cmd.arg = SD_BUS_WIDTH_1; 125 + break; 126 + case MMC_BUS_WIDTH_4: 127 + cmd.arg = SD_BUS_WIDTH_4; 128 + break; 129 + default: 130 + return MMC_ERR_INVALID; 131 + } 132 + 133 + err = mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES); 134 + if (err != MMC_ERR_NONE) 135 + return err; 136 + 137 + return MMC_ERR_NONE; 138 + } 139 + 140 + int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) 141 + { 142 + struct mmc_command cmd; 143 + int i, err = 0; 144 + 145 + BUG_ON(!host); 146 + 147 + memset(&cmd, 0, sizeof(struct mmc_command)); 148 + 149 + cmd.opcode = SD_APP_OP_COND; 150 + cmd.arg = ocr; 151 + cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 152 + 153 + for (i = 100; i; i--) { 154 + err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES); 155 + if (err != MMC_ERR_NONE) 156 + break; 157 + 158 + if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0) 159 + break; 160 + 161 + err = MMC_ERR_TIMEOUT; 162 + 163 + mmc_delay(10); 164 + } 165 + 166 + if (rocr) 167 + *rocr = cmd.resp[0]; 168 + 169 + return err; 170 + } 171 + 172 + int mmc_send_if_cond(struct mmc_host *host, u32 ocr) 173 + { 174 + struct mmc_command cmd; 175 + int err; 176 + static const u8 test_pattern = 0xAA; 177 + 178 + /* 179 + * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND 180 + * before SD_APP_OP_COND. This command will harmlessly fail for 181 + * SD 1.0 cards. 182 + */ 183 + cmd.opcode = SD_SEND_IF_COND; 184 + cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern; 185 + cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR; 186 + 187 + err = mmc_wait_for_cmd(host, &cmd, 0); 188 + if (err != MMC_ERR_NONE) 189 + return err; 190 + 191 + if ((cmd.resp[0] & 0xFF) != test_pattern) 192 + return MMC_ERR_FAILED; 193 + 194 + return MMC_ERR_NONE; 195 + } 196 + 197 + int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca) 198 + { 199 + int err; 200 + struct mmc_command cmd; 201 + 202 + BUG_ON(!host); 203 + BUG_ON(!rca); 204 + 205 + memset(&cmd, 0, sizeof(struct mmc_command)); 206 + 207 + cmd.opcode = SD_SEND_RELATIVE_ADDR; 208 + cmd.arg = 0; 209 + cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR; 210 + 211 + err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); 212 + if (err != MMC_ERR_NONE) 213 + return err; 214 + 215 + *rca = cmd.resp[0] >> 16; 216 + 217 + return MMC_ERR_NONE; 218 + } 219 + 220 + int mmc_app_send_scr(struct mmc_card *card, u32 *scr) 221 + { 222 + int err; 223 + struct mmc_request mrq; 224 + struct mmc_command cmd; 225 + struct mmc_data data; 226 + struct scatterlist sg; 227 + 228 + BUG_ON(!card); 229 + BUG_ON(!card->host); 230 + BUG_ON(!scr); 231 + 232 + err = mmc_app_cmd(card->host, card); 233 + if (err != MMC_ERR_NONE) 234 + return err; 235 + 236 + memset(&mrq, 0, sizeof(struct mmc_request)); 237 + memset(&cmd, 0, sizeof(struct mmc_command)); 238 + memset(&data, 0, sizeof(struct mmc_data)); 239 + 240 + mrq.cmd = &cmd; 241 + mrq.data = &data; 242 + 243 + cmd.opcode = SD_APP_SEND_SCR; 244 + cmd.arg = 0; 245 + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 246 + 247 + data.blksz = 8; 248 + data.blocks = 1; 249 + data.flags = MMC_DATA_READ; 250 + data.sg = &sg; 251 + data.sg_len = 1; 252 + 253 + sg_init_one(&sg, scr, 8); 254 + 255 + mmc_set_data_timeout(&data, card, 0); 256 + 257 + mmc_wait_for_req(card->host, &mrq); 258 + 259 + if (cmd.error != MMC_ERR_NONE) 260 + return cmd.error; 261 + if (data.error != MMC_ERR_NONE) 262 + return data.error; 263 + 264 + scr[0] = ntohl(scr[0]); 265 + scr[1] = ntohl(scr[1]); 266 + 267 + return MMC_ERR_NONE; 268 + } 269 + 270 + int mmc_sd_switch(struct mmc_card *card, int mode, int group, 271 + u8 value, u8 *resp) 272 + { 273 + struct mmc_request mrq; 274 + struct mmc_command cmd; 275 + struct mmc_data data; 276 + struct scatterlist sg; 277 + 278 + BUG_ON(!card); 279 + BUG_ON(!card->host); 280 + 281 + mode = !!mode; 282 + value &= 0xF; 283 + 284 + memset(&mrq, 0, sizeof(struct mmc_request)); 285 + memset(&cmd, 0, sizeof(struct mmc_command)); 286 + memset(&data, 0, sizeof(struct mmc_data)); 287 + 288 + mrq.cmd = &cmd; 289 + mrq.data = &data; 290 + 291 + cmd.opcode = SD_SWITCH; 292 + cmd.arg = mode << 31 | 0x00FFFFFF; 293 + cmd.arg &= ~(0xF << (group * 4)); 294 + cmd.arg |= value << (group * 4); 295 + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 296 + 297 + data.blksz = 64; 298 + data.blocks = 1; 299 + data.flags = MMC_DATA_READ; 300 + data.sg = &sg; 301 + data.sg_len = 1; 302 + 303 + sg_init_one(&sg, resp, 64); 304 + 305 + mmc_set_data_timeout(&data, card, 0); 306 + 307 + mmc_wait_for_req(card->host, &mrq); 308 + 309 + if (cmd.error != MMC_ERR_NONE) 310 + return cmd.error; 311 + if (data.error != MMC_ERR_NONE) 312 + return data.error; 313 + 314 + return MMC_ERR_NONE; 315 + } 316 +
+25
drivers/mmc/core/sd_ops.h
··· 1 + /* 2 + * linux/drivers/mmc/sd_ops.h 3 + * 4 + * Copyright 2006-2007 Pierre Ossman 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or (at 9 + * your option) any later version. 10 + */ 11 + 12 + #ifndef _MMC_SD_OPS_H 13 + #define _MMC_SD_OPS_H 14 + 15 + int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card); 16 + int mmc_app_set_bus_width(struct mmc_card *card, int width); 17 + int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); 18 + int mmc_send_if_cond(struct mmc_host *host, u32 ocr); 19 + int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca); 20 + int mmc_app_send_scr(struct mmc_card *card, u32 *scr); 21 + int mmc_sd_switch(struct mmc_card *card, int mode, int group, 22 + u8 value, u8 *resp); 23 + 24 + #endif 25 +
+1 -1
drivers/mmc/core/sysfs.c
··· 18 18 #include <linux/mmc/card.h> 19 19 #include <linux/mmc/host.h> 20 20 21 - #include "core.h" 21 + #include "sysfs.h" 22 22 23 23 #define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev) 24 24 #define to_mmc_driver(d) container_of(d, struct mmc_driver, drv)
+27
drivers/mmc/core/sysfs.h
··· 1 + /* 2 + * linux/drivers/mmc/core/sysfs.h 3 + * 4 + * Copyright (C) 2003 Russell King, All Rights Reserved. 5 + * Copyright 2007 Pierre Ossman 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + */ 11 + #ifndef _MMC_CORE_SYSFS_H 12 + #define _MMC_CORE_SYSFS_H 13 + 14 + void mmc_init_card(struct mmc_card *card, struct mmc_host *host); 15 + int mmc_register_card(struct mmc_card *card); 16 + void mmc_remove_card(struct mmc_card *card); 17 + 18 + struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev); 19 + int mmc_add_host_sysfs(struct mmc_host *host); 20 + void mmc_remove_host_sysfs(struct mmc_host *host); 21 + void mmc_free_host_sysfs(struct mmc_host *host); 22 + 23 + int mmc_schedule_work(struct work_struct *work); 24 + int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay); 25 + void mmc_flush_scheduled_work(void); 26 + 27 + #endif
+1 -1
include/linux/mmc/core.h
··· 101 101 102 102 extern int mmc_wait_for_req(struct mmc_host *, struct mmc_request *); 103 103 extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int); 104 - extern int mmc_wait_for_app_cmd(struct mmc_host *, unsigned int, 104 + extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *, 105 105 struct mmc_command *, int); 106 106 107 107 extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *, int);
+2 -52
include/linux/mmc/protocol.h include/linux/mmc/mmc.h
··· 22 22 * 15 May 2002 23 23 */ 24 24 25 - #ifndef MMC_MMC_PROTOCOL_H 26 - #define MMC_MMC_PROTOCOL_H 25 + #ifndef MMC_MMC_H 26 + #define MMC_MMC_H 27 27 28 28 /* Standard MMC commands (4.1) type argument response */ 29 29 /* class 1 */ ··· 78 78 #define MMC_APP_CMD 55 /* ac [31:16] RCA R1 */ 79 79 #define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1 */ 80 80 81 - /* SD commands type argument response */ 82 - /* class 0 */ 83 - /* This is basically the same command as for MMC with some quirks. */ 84 - #define SD_SEND_RELATIVE_ADDR 3 /* bcr R6 */ 85 - #define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7 */ 86 - 87 - /* class 10 */ 88 - #define SD_SWITCH 6 /* adtc [31:0] See below R1 */ 89 - 90 - /* Application commands */ 91 - #define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */ 92 - #define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */ 93 - #define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */ 94 - #define SD_APP_SEND_SCR 51 /* adtc R1 */ 95 - 96 81 /* 97 82 * MMC_SWITCH argument format: 98 83 * ··· 87 102 * [15:08] Value Byte 88 103 * [07:03] Always 0 89 104 * [02:00] Command Set 90 - */ 91 - 92 - /* 93 - * SD_SWITCH argument format: 94 - * 95 - * [31] Check (0) or switch (1) 96 - * [30:24] Reserved (0) 97 - * [23:20] Function group 6 98 - * [19:16] Function group 5 99 - * [15:12] Function group 4 100 - * [11:8] Function group 3 101 - * [7:4] Function group 2 102 - * [3:0] Function group 1 103 - */ 104 - 105 - /* 106 - * SD_SEND_IF_COND argument format: 107 - * 108 - * [31:12] Reserved (0) 109 - * [11:8] Host Voltage Supply Flags 110 - * [7:0] Check Pattern (0xAA) 111 105 */ 112 106 113 107 /* ··· 252 288 #define MMC_SWITCH_MODE_SET_BITS 0x01 /* Set bits which are 1 in value */ 253 289 #define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits which are 1 in value */ 254 290 #define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */ 255 - 256 - /* 257 - * SCR field definitions 258 - */ 259 - 260 - #define SCR_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.01 */ 261 - #define SCR_SPEC_VER_1 1 /* Implements system specification 1.10 */ 262 - #define SCR_SPEC_VER_2 2 /* Implements system specification 2.00 */ 263 - 264 - /* 265 - * SD bus widths 266 - */ 267 - #define SD_BUS_WIDTH_1 0 268 - #define SD_BUS_WIDTH_4 2 269 291 270 292 #endif /* MMC_MMC_PROTOCOL_H */ 271 293
+83
include/linux/mmc/sd.h
··· 1 + /* 2 + * include/linux/mmc/sd.h 3 + * 4 + * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or (at 9 + * your option) any later version. 10 + */ 11 + 12 + #ifndef MMC_SD_H 13 + #define MMC_SD_H 14 + 15 + /* SD commands type argument response */ 16 + /* class 0 */ 17 + /* This is basically the same command as for MMC with some quirks. */ 18 + #define SD_SEND_RELATIVE_ADDR 3 /* bcr R6 */ 19 + #define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7 */ 20 + 21 + /* class 10 */ 22 + #define SD_SWITCH 6 /* adtc [31:0] See below R1 */ 23 + 24 + /* Application commands */ 25 + #define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */ 26 + #define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */ 27 + #define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */ 28 + #define SD_APP_SEND_SCR 51 /* adtc R1 */ 29 + 30 + /* 31 + * SD_SWITCH argument format: 32 + * 33 + * [31] Check (0) or switch (1) 34 + * [30:24] Reserved (0) 35 + * [23:20] Function group 6 36 + * [19:16] Function group 5 37 + * [15:12] Function group 4 38 + * [11:8] Function group 3 39 + * [7:4] Function group 2 40 + * [3:0] Function group 1 41 + */ 42 + 43 + /* 44 + * SD_SEND_IF_COND argument format: 45 + * 46 + * [31:12] Reserved (0) 47 + * [11:8] Host Voltage Supply Flags 48 + * [7:0] Check Pattern (0xAA) 49 + */ 50 + 51 + /* 52 + * SCR field definitions 53 + */ 54 + 55 + #define SCR_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.01 */ 56 + #define SCR_SPEC_VER_1 1 /* Implements system specification 1.10 */ 57 + #define SCR_SPEC_VER_2 2 /* Implements system specification 2.00 */ 58 + 59 + /* 60 + * SD bus widths 61 + */ 62 + #define SD_BUS_WIDTH_1 0 63 + #define SD_BUS_WIDTH_4 2 64 + 65 + /* 66 + * SD_SWITCH mode 67 + */ 68 + #define SD_SWITCH_CHECK 0 69 + #define SD_SWITCH_SET 1 70 + 71 + /* 72 + * SD_SWITCH function groups 73 + */ 74 + #define SD_SWITCH_GRP_ACCESS 0 75 + 76 + /* 77 + * SD_SWITCH access modes 78 + */ 79 + #define SD_SWITCH_ACCESS_DEF 0 80 + #define SD_SWITCH_ACCESS_HS 1 81 + 82 + #endif 83 +