Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved. |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 5 | * Copyright (C) 2010 ST-Ericsson SA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/ioport.h> |
| 15 | #include <linux/device.h> |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 16 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Russell King | 613b152 | 2011-01-30 21:06:53 +0000 | [diff] [blame] | 18 | #include <linux/kernel.h> |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 19 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/highmem.h> |
Nicolas Pitre | 019a5f5 | 2007-10-11 01:06:03 -0400 | [diff] [blame] | 23 | #include <linux/log2.h> |
Ludovic Barre | c8073e5 | 2018-12-06 16:13:31 +0100 | [diff] [blame] | 24 | #include <linux/mmc/mmc.h> |
Ulf Hansson | 70be208 | 2013-01-07 15:35:06 +0100 | [diff] [blame] | 25 | #include <linux/mmc/pm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/mmc/host.h> |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 27 | #include <linux/mmc/card.h> |
Ulf Hansson | d276209 | 2014-03-17 13:56:19 +0100 | [diff] [blame] | 28 | #include <linux/mmc/slot-gpio.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 29 | #include <linux/amba/bus.h> |
Russell King | f8ce254 | 2006-01-07 16:15:52 +0000 | [diff] [blame] | 30 | #include <linux/clk.h> |
Jens Axboe | bd6dee6 | 2007-10-24 09:01:09 +0200 | [diff] [blame] | 31 | #include <linux/scatterlist.h> |
Linus Walleij | 9ef986a | 2018-09-20 16:01:10 -0700 | [diff] [blame] | 32 | #include <linux/of.h> |
Linus Walleij | 34e84f3 | 2009-09-22 14:41:40 +0100 | [diff] [blame] | 33 | #include <linux/regulator/consumer.h> |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 34 | #include <linux/dmaengine.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/amba/mmci.h> |
Russell King | 1c3be36 | 2011-08-14 09:17:05 +0100 | [diff] [blame] | 37 | #include <linux/pm_runtime.h> |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 38 | #include <linux/types.h> |
Linus Walleij | a9a8378 | 2012-10-29 14:39:30 +0100 | [diff] [blame] | 39 | #include <linux/pinctrl/consumer.h> |
Ludovic Barre | 15878e5 | 2018-10-08 14:08:51 +0200 | [diff] [blame] | 40 | #include <linux/reset.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Russell King | 7b09cda | 2005-07-01 12:02:59 +0100 | [diff] [blame] | 42 | #include <asm/div64.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #include "mmci.h" |
| 46 | |
| 47 | #define DRIVER_NAME "mmci-pl18x" |
| 48 | |
Ulf Hansson | 71953e0 | 2019-03-06 15:04:56 +0100 | [diff] [blame] | 49 | static void mmci_variant_init(struct mmci_host *host); |
Ludovic Barre | b3fb9d6 | 2019-03-27 10:05:29 +0100 | [diff] [blame] | 50 | static void ux500v2_variant_init(struct mmci_host *host); |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static unsigned int fmax = 515633; |
| 53 | |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 54 | static struct variant_data variant_arm = { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 55 | .fifosize = 16 * 4, |
| 56 | .fifohalfsize = 8 * 4, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 57 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 58 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 59 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 60 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 61 | .datalength_bits = 16, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 62 | .datactrl_blocksz = 11, |
Ulf Hansson | 7d72a1d | 2011-12-13 16:54:55 +0100 | [diff] [blame] | 63 | .pwrreg_powerup = MCI_PWR_UP, |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 64 | .f_max = 100000000, |
Ulf Hansson | 7878289 | 2014-06-13 13:21:38 +0200 | [diff] [blame] | 65 | .reversed_irq_handling = true, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 66 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 67 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 68 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 69 | .opendrain = MCI_ROD, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 70 | .init = mmci_variant_init, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Pawel Moll | 768fbc1 | 2011-03-11 17:18:07 +0000 | [diff] [blame] | 73 | static struct variant_data variant_arm_extended_fifo = { |
| 74 | .fifosize = 128 * 4, |
| 75 | .fifohalfsize = 64 * 4, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 76 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 77 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 78 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 79 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Pawel Moll | 768fbc1 | 2011-03-11 17:18:07 +0000 | [diff] [blame] | 80 | .datalength_bits = 16, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 81 | .datactrl_blocksz = 11, |
Ulf Hansson | 7d72a1d | 2011-12-13 16:54:55 +0100 | [diff] [blame] | 82 | .pwrreg_powerup = MCI_PWR_UP, |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 83 | .f_max = 100000000, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 84 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 85 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 86 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 87 | .opendrain = MCI_ROD, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 88 | .init = mmci_variant_init, |
Pawel Moll | 768fbc1 | 2011-03-11 17:18:07 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Pawel Moll | 3a37298 | 2013-01-24 14:12:45 +0100 | [diff] [blame] | 91 | static struct variant_data variant_arm_extended_fifo_hwfc = { |
| 92 | .fifosize = 128 * 4, |
| 93 | .fifohalfsize = 64 * 4, |
| 94 | .clkreg_enable = MCI_ARM_HWFCEN, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 95 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 96 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 97 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 98 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Pawel Moll | 3a37298 | 2013-01-24 14:12:45 +0100 | [diff] [blame] | 99 | .datalength_bits = 16, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 100 | .datactrl_blocksz = 11, |
Pawel Moll | 3a37298 | 2013-01-24 14:12:45 +0100 | [diff] [blame] | 101 | .pwrreg_powerup = MCI_PWR_UP, |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 102 | .f_max = 100000000, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 103 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 104 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 105 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 106 | .opendrain = MCI_ROD, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 107 | .init = mmci_variant_init, |
Pawel Moll | 3a37298 | 2013-01-24 14:12:45 +0100 | [diff] [blame] | 108 | }; |
| 109 | |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 110 | static struct variant_data variant_u300 = { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 111 | .fifosize = 16 * 4, |
| 112 | .fifohalfsize = 8 * 4, |
Linus Walleij | 49ac215 | 2011-03-04 14:54:16 +0100 | [diff] [blame] | 113 | .clkreg_enable = MCI_ST_U300_HWFCEN, |
Srinivas Kandagatla | e1412d8 | 2014-06-02 10:09:23 +0100 | [diff] [blame] | 114 | .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 115 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 116 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 117 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 118 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 119 | .datalength_bits = 16, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 120 | .datactrl_blocksz = 11, |
Linus Walleij | 5db3eee | 2016-10-25 11:06:05 +0200 | [diff] [blame] | 121 | .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN, |
Srinivas Kandagatla | c735413 | 2014-08-22 05:55:16 +0100 | [diff] [blame] | 122 | .st_sdio = true, |
Ulf Hansson | 7d72a1d | 2011-12-13 16:54:55 +0100 | [diff] [blame] | 123 | .pwrreg_powerup = MCI_PWR_ON, |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 124 | .f_max = 100000000, |
Ulf Hansson | 4d1a3a0 | 2011-12-13 16:57:07 +0100 | [diff] [blame] | 125 | .signal_direction = true, |
Ulf Hansson | f4670da | 2013-01-09 17:19:54 +0100 | [diff] [blame] | 126 | .pwrreg_clkgate = true, |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 127 | .pwrreg_nopower = true, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 128 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 129 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 130 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 131 | .opendrain = MCI_OD, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 132 | .init = mmci_variant_init, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 133 | }; |
| 134 | |
Linus Walleij | 34fd421 | 2012-04-10 17:43:59 +0100 | [diff] [blame] | 135 | static struct variant_data variant_nomadik = { |
| 136 | .fifosize = 16 * 4, |
| 137 | .fifohalfsize = 8 * 4, |
| 138 | .clkreg = MCI_CLK_ENABLE, |
Linus Walleij | f5abc76 | 2016-01-04 02:22:08 +0100 | [diff] [blame] | 139 | .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 140 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 141 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 142 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 143 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Linus Walleij | 34fd421 | 2012-04-10 17:43:59 +0100 | [diff] [blame] | 144 | .datalength_bits = 24, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 145 | .datactrl_blocksz = 11, |
Linus Walleij | 5db3eee | 2016-10-25 11:06:05 +0200 | [diff] [blame] | 146 | .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN, |
Srinivas Kandagatla | c735413 | 2014-08-22 05:55:16 +0100 | [diff] [blame] | 147 | .st_sdio = true, |
Linus Walleij | 34fd421 | 2012-04-10 17:43:59 +0100 | [diff] [blame] | 148 | .st_clkdiv = true, |
| 149 | .pwrreg_powerup = MCI_PWR_ON, |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 150 | .f_max = 100000000, |
Linus Walleij | 34fd421 | 2012-04-10 17:43:59 +0100 | [diff] [blame] | 151 | .signal_direction = true, |
Ulf Hansson | f4670da | 2013-01-09 17:19:54 +0100 | [diff] [blame] | 152 | .pwrreg_clkgate = true, |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 153 | .pwrreg_nopower = true, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 154 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 155 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 156 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 157 | .opendrain = MCI_OD, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 158 | .init = mmci_variant_init, |
Linus Walleij | 34fd421 | 2012-04-10 17:43:59 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 161 | static struct variant_data variant_ux500 = { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 162 | .fifosize = 30 * 4, |
| 163 | .fifohalfsize = 8 * 4, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 164 | .clkreg = MCI_CLK_ENABLE, |
Linus Walleij | 49ac215 | 2011-03-04 14:54:16 +0100 | [diff] [blame] | 165 | .clkreg_enable = MCI_ST_UX500_HWFCEN, |
Srinivas Kandagatla | e1412d8 | 2014-06-02 10:09:23 +0100 | [diff] [blame] | 166 | .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, |
Srinivas Kandagatla | e874064 | 2014-06-02 10:09:30 +0100 | [diff] [blame] | 167 | .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 168 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 169 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 170 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 171 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 172 | .datalength_bits = 24, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 173 | .datactrl_blocksz = 11, |
Linus Walleij | 5db3eee | 2016-10-25 11:06:05 +0200 | [diff] [blame] | 174 | .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN, |
Srinivas Kandagatla | c735413 | 2014-08-22 05:55:16 +0100 | [diff] [blame] | 175 | .st_sdio = true, |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame] | 176 | .st_clkdiv = true, |
Ulf Hansson | 7d72a1d | 2011-12-13 16:54:55 +0100 | [diff] [blame] | 177 | .pwrreg_powerup = MCI_PWR_ON, |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 178 | .f_max = 100000000, |
Ulf Hansson | 4d1a3a0 | 2011-12-13 16:57:07 +0100 | [diff] [blame] | 179 | .signal_direction = true, |
Ulf Hansson | f4670da | 2013-01-09 17:19:54 +0100 | [diff] [blame] | 180 | .pwrreg_clkgate = true, |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 181 | .busy_detect = true, |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 182 | .busy_dpsm_flag = MCI_DPSM_ST_BUSYMODE, |
| 183 | .busy_detect_flag = MCI_ST_CARDBUSY, |
| 184 | .busy_detect_mask = MCI_ST_BUSYENDMASK, |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 185 | .pwrreg_nopower = true, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 186 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 187 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 188 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 189 | .opendrain = MCI_OD, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 190 | .init = mmci_variant_init, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 191 | }; |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame] | 192 | |
Philippe Langlais | 1784b15 | 2011-03-25 08:51:52 +0100 | [diff] [blame] | 193 | static struct variant_data variant_ux500v2 = { |
| 194 | .fifosize = 30 * 4, |
| 195 | .fifohalfsize = 8 * 4, |
| 196 | .clkreg = MCI_CLK_ENABLE, |
| 197 | .clkreg_enable = MCI_ST_UX500_HWFCEN, |
Srinivas Kandagatla | e1412d8 | 2014-06-02 10:09:23 +0100 | [diff] [blame] | 198 | .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, |
Srinivas Kandagatla | e874064 | 2014-06-02 10:09:30 +0100 | [diff] [blame] | 199 | .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 200 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 201 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 202 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 203 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Linus Walleij | 5db3eee | 2016-10-25 11:06:05 +0200 | [diff] [blame] | 204 | .datactrl_mask_ddrmode = MCI_DPSM_ST_DDRMODE, |
Philippe Langlais | 1784b15 | 2011-03-25 08:51:52 +0100 | [diff] [blame] | 205 | .datalength_bits = 24, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 206 | .datactrl_blocksz = 11, |
Linus Walleij | 5db3eee | 2016-10-25 11:06:05 +0200 | [diff] [blame] | 207 | .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN, |
Srinivas Kandagatla | c735413 | 2014-08-22 05:55:16 +0100 | [diff] [blame] | 208 | .st_sdio = true, |
Philippe Langlais | 1784b15 | 2011-03-25 08:51:52 +0100 | [diff] [blame] | 209 | .st_clkdiv = true, |
Ulf Hansson | 7d72a1d | 2011-12-13 16:54:55 +0100 | [diff] [blame] | 210 | .pwrreg_powerup = MCI_PWR_ON, |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 211 | .f_max = 100000000, |
Ulf Hansson | 4d1a3a0 | 2011-12-13 16:57:07 +0100 | [diff] [blame] | 212 | .signal_direction = true, |
Ulf Hansson | f4670da | 2013-01-09 17:19:54 +0100 | [diff] [blame] | 213 | .pwrreg_clkgate = true, |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 214 | .busy_detect = true, |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 215 | .busy_dpsm_flag = MCI_DPSM_ST_BUSYMODE, |
| 216 | .busy_detect_flag = MCI_ST_CARDBUSY, |
| 217 | .busy_detect_mask = MCI_ST_BUSYENDMASK, |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 218 | .pwrreg_nopower = true, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 219 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 220 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 221 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 222 | .opendrain = MCI_OD, |
Ludovic Barre | b3fb9d6 | 2019-03-27 10:05:29 +0100 | [diff] [blame] | 223 | .init = ux500v2_variant_init, |
Philippe Langlais | 1784b15 | 2011-03-25 08:51:52 +0100 | [diff] [blame] | 224 | }; |
| 225 | |
Patrice Chotard | 2a9d6c8 | 2018-01-18 15:34:21 +0100 | [diff] [blame] | 226 | static struct variant_data variant_stm32 = { |
| 227 | .fifosize = 32 * 4, |
| 228 | .fifohalfsize = 8 * 4, |
| 229 | .clkreg = MCI_CLK_ENABLE, |
| 230 | .clkreg_enable = MCI_ST_UX500_HWFCEN, |
| 231 | .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS, |
| 232 | .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 233 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 234 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 235 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 236 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 237 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 2a9d6c8 | 2018-01-18 15:34:21 +0100 | [diff] [blame] | 238 | .datalength_bits = 24, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 239 | .datactrl_blocksz = 11, |
Patrice Chotard | 2a9d6c8 | 2018-01-18 15:34:21 +0100 | [diff] [blame] | 240 | .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN, |
| 241 | .st_sdio = true, |
| 242 | .st_clkdiv = true, |
| 243 | .pwrreg_powerup = MCI_PWR_ON, |
| 244 | .f_max = 48000000, |
| 245 | .pwrreg_clkgate = true, |
| 246 | .pwrreg_nopower = true, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 247 | .init = mmci_variant_init, |
Patrice Chotard | 2a9d6c8 | 2018-01-18 15:34:21 +0100 | [diff] [blame] | 248 | }; |
| 249 | |
Ludovic Barre | 46b723d | 2018-10-08 14:08:55 +0200 | [diff] [blame] | 250 | static struct variant_data variant_stm32_sdmmc = { |
| 251 | .fifosize = 16 * 4, |
| 252 | .fifohalfsize = 8 * 4, |
| 253 | .f_max = 208000000, |
| 254 | .stm32_clkdiv = true, |
| 255 | .cmdreg_cpsm_enable = MCI_CPSM_STM32_ENABLE, |
| 256 | .cmdreg_lrsp_crc = MCI_CPSM_STM32_LRSP_CRC, |
| 257 | .cmdreg_srsp_crc = MCI_CPSM_STM32_SRSP_CRC, |
| 258 | .cmdreg_srsp = MCI_CPSM_STM32_SRSP, |
Ludovic Barre | c8073e5 | 2018-12-06 16:13:31 +0100 | [diff] [blame] | 259 | .cmdreg_stop = MCI_CPSM_STM32_CMDSTOP, |
Ludovic Barre | 46b723d | 2018-10-08 14:08:55 +0200 | [diff] [blame] | 260 | .data_cmd_enable = MCI_CPSM_STM32_CMDTRANS, |
| 261 | .irq_pio_mask = MCI_IRQ_PIO_STM32_MASK, |
| 262 | .datactrl_first = true, |
| 263 | .datacnt_useless = true, |
| 264 | .datalength_bits = 25, |
| 265 | .datactrl_blocksz = 14, |
| 266 | .stm32_idmabsize_mask = GENMASK(12, 5), |
| 267 | .init = sdmmc_variant_init, |
| 268 | }; |
| 269 | |
Srinivas Kandagatla | 55b604a | 2014-06-02 10:10:13 +0100 | [diff] [blame] | 270 | static struct variant_data variant_qcom = { |
| 271 | .fifosize = 16 * 4, |
| 272 | .fifohalfsize = 8 * 4, |
| 273 | .clkreg = MCI_CLK_ENABLE, |
| 274 | .clkreg_enable = MCI_QCOM_CLK_FLOWENA | |
| 275 | MCI_QCOM_CLK_SELECT_IN_FBCLK, |
| 276 | .clkreg_8bit_bus_enable = MCI_QCOM_CLK_WIDEBUS_8, |
| 277 | .datactrl_mask_ddrmode = MCI_QCOM_CLK_SELECT_IN_DDR_MODE, |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 278 | .cmdreg_cpsm_enable = MCI_CPSM_ENABLE, |
| 279 | .cmdreg_lrsp_crc = MCI_CPSM_RESPONSE | MCI_CPSM_LONGRSP, |
| 280 | .cmdreg_srsp_crc = MCI_CPSM_RESPONSE, |
| 281 | .cmdreg_srsp = MCI_CPSM_RESPONSE, |
Linus Walleij | 5db3eee | 2016-10-25 11:06:05 +0200 | [diff] [blame] | 282 | .data_cmd_enable = MCI_CPSM_QCOM_DATCMD, |
Srinivas Kandagatla | 55b604a | 2014-06-02 10:10:13 +0100 | [diff] [blame] | 283 | .datalength_bits = 24, |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 284 | .datactrl_blocksz = 11, |
Srinivas Kandagatla | 55b604a | 2014-06-02 10:10:13 +0100 | [diff] [blame] | 285 | .pwrreg_powerup = MCI_PWR_UP, |
| 286 | .f_max = 208000000, |
| 287 | .explicit_mclk_control = true, |
| 288 | .qcom_fifo = true, |
Srinivas Kandagatla | 9cb1514 | 2014-07-29 03:50:30 +0100 | [diff] [blame] | 289 | .qcom_dml = true, |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 290 | .mmcimask1 = true, |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 291 | .irq_pio_mask = MCI_IRQ_PIO_MASK, |
Patrice Chotard | 7f7b550 | 2018-01-18 15:34:18 +0100 | [diff] [blame] | 292 | .start_err = MCI_STARTBITERR, |
Patrice Chotard | 11dfb97 | 2018-01-18 15:34:19 +0100 | [diff] [blame] | 293 | .opendrain = MCI_ROD, |
Ulf Hansson | 29aba07 | 2018-07-16 13:08:18 +0200 | [diff] [blame] | 294 | .init = qcom_variant_init, |
Srinivas Kandagatla | 55b604a | 2014-06-02 10:10:13 +0100 | [diff] [blame] | 295 | }; |
| 296 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 297 | /* Busy detection for the ST Micro variant */ |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 298 | static int mmci_card_busy(struct mmc_host *mmc) |
| 299 | { |
| 300 | struct mmci_host *host = mmc_priv(mmc); |
| 301 | unsigned long flags; |
| 302 | int busy = 0; |
| 303 | |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 304 | spin_lock_irqsave(&host->lock, flags); |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 305 | if (readl(host->base + MMCISTATUS) & host->variant->busy_detect_flag) |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 306 | busy = 1; |
| 307 | spin_unlock_irqrestore(&host->lock, flags); |
| 308 | |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 309 | return busy; |
| 310 | } |
| 311 | |
Ulf Hansson | f829c04 | 2013-09-04 09:01:15 +0100 | [diff] [blame] | 312 | static void mmci_reg_delay(struct mmci_host *host) |
| 313 | { |
| 314 | /* |
| 315 | * According to the spec, at least three feedback clock cycles |
| 316 | * of max 52 MHz must pass between two writes to the MMCICLOCK reg. |
| 317 | * Three MCLK clock cycles must pass between two MMCIPOWER reg writes. |
| 318 | * Worst delay time during card init is at 100 kHz => 30 us. |
| 319 | * Worst delay time when up and running is at 25 MHz => 120 ns. |
| 320 | */ |
| 321 | if (host->cclk < 25000000) |
| 322 | udelay(30); |
| 323 | else |
| 324 | ndelay(120); |
| 325 | } |
| 326 | |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 327 | /* |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 328 | * This must be called with host->lock held |
| 329 | */ |
Ludovic Barre | cd3ee8c | 2018-10-08 14:08:42 +0200 | [diff] [blame] | 330 | void mmci_write_clkreg(struct mmci_host *host, u32 clk) |
Ulf Hansson | 7437cfa | 2012-01-18 09:17:27 +0100 | [diff] [blame] | 331 | { |
| 332 | if (host->clk_reg != clk) { |
| 333 | host->clk_reg = clk; |
| 334 | writel(clk, host->base + MMCICLOCK); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * This must be called with host->lock held |
| 340 | */ |
Ludovic Barre | cd3ee8c | 2018-10-08 14:08:42 +0200 | [diff] [blame] | 341 | void mmci_write_pwrreg(struct mmci_host *host, u32 pwr) |
Ulf Hansson | 7437cfa | 2012-01-18 09:17:27 +0100 | [diff] [blame] | 342 | { |
| 343 | if (host->pwr_reg != pwr) { |
| 344 | host->pwr_reg = pwr; |
| 345 | writel(pwr, host->base + MMCIPOWER); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * This must be called with host->lock held |
| 351 | */ |
Ulf Hansson | 9cc639a | 2013-05-15 20:48:23 +0100 | [diff] [blame] | 352 | static void mmci_write_datactrlreg(struct mmci_host *host, u32 datactrl) |
| 353 | { |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 354 | /* Keep busy mode in DPSM if enabled */ |
| 355 | datactrl |= host->datactrl_reg & host->variant->busy_dpsm_flag; |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 356 | |
Ulf Hansson | 9cc639a | 2013-05-15 20:48:23 +0100 | [diff] [blame] | 357 | if (host->datactrl_reg != datactrl) { |
| 358 | host->datactrl_reg = datactrl; |
| 359 | writel(datactrl, host->base + MMCIDATACTRL); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * This must be called with host->lock held |
| 365 | */ |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 366 | static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) |
| 367 | { |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 368 | struct variant_data *variant = host->variant; |
| 369 | u32 clk = variant->clkreg; |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 370 | |
Ulf Hansson | c58a850 | 2013-05-13 15:40:03 +0100 | [diff] [blame] | 371 | /* Make sure cclk reflects the current calculated clock */ |
| 372 | host->cclk = 0; |
| 373 | |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 374 | if (desired) { |
Srinivas Kandagatla | 3f4e6f7 | 2014-06-02 10:09:55 +0100 | [diff] [blame] | 375 | if (variant->explicit_mclk_control) { |
| 376 | host->cclk = host->mclk; |
| 377 | } else if (desired >= host->mclk) { |
Linus Walleij | 991a86e | 2010-12-10 09:35:53 +0100 | [diff] [blame] | 378 | clk = MCI_CLK_BYPASS; |
Linus Walleij | 399bc48 | 2011-04-01 07:59:17 +0100 | [diff] [blame] | 379 | if (variant->st_clkdiv) |
| 380 | clk |= MCI_ST_UX500_NEG_EDGE; |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 381 | host->cclk = host->mclk; |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame] | 382 | } else if (variant->st_clkdiv) { |
| 383 | /* |
| 384 | * DB8500 TRM says f = mclk / (clkdiv + 2) |
| 385 | * => clkdiv = (mclk / f) - 2 |
| 386 | * Round the divider up so we don't exceed the max |
| 387 | * frequency |
| 388 | */ |
| 389 | clk = DIV_ROUND_UP(host->mclk, desired) - 2; |
| 390 | if (clk >= 256) |
| 391 | clk = 255; |
| 392 | host->cclk = host->mclk / (clk + 2); |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 393 | } else { |
Linus Walleij | b70a67f | 2010-12-06 09:24:14 +0100 | [diff] [blame] | 394 | /* |
| 395 | * PL180 TRM says f = mclk / (2 * (clkdiv + 1)) |
| 396 | * => clkdiv = mclk / (2 * f) - 1 |
| 397 | */ |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 398 | clk = host->mclk / (2 * desired) - 1; |
| 399 | if (clk >= 256) |
| 400 | clk = 255; |
| 401 | host->cclk = host->mclk / (2 * (clk + 1)); |
| 402 | } |
Rabin Vincent | 4380c14 | 2010-07-21 12:55:18 +0100 | [diff] [blame] | 403 | |
| 404 | clk |= variant->clkreg_enable; |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 405 | clk |= MCI_CLK_ENABLE; |
| 406 | /* This hasn't proven to be worthwhile */ |
| 407 | /* clk |= MCI_CLK_PWRSAVE; */ |
| 408 | } |
| 409 | |
Ulf Hansson | c58a850 | 2013-05-13 15:40:03 +0100 | [diff] [blame] | 410 | /* Set actual clock for debug */ |
| 411 | host->mmc->actual_clock = host->cclk; |
| 412 | |
Linus Walleij | 9e6c82c | 2009-09-14 12:57:11 +0100 | [diff] [blame] | 413 | if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4) |
Linus Walleij | 771dc15 | 2010-04-08 07:38:52 +0100 | [diff] [blame] | 414 | clk |= MCI_4BIT_BUS; |
| 415 | if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8) |
Srinivas Kandagatla | e1412d8 | 2014-06-02 10:09:23 +0100 | [diff] [blame] | 416 | clk |= variant->clkreg_8bit_bus_enable; |
Linus Walleij | 9e6c82c | 2009-09-14 12:57:11 +0100 | [diff] [blame] | 417 | |
Seungwon Jeon | 6dad6c9 | 2014-03-14 21:12:13 +0900 | [diff] [blame] | 418 | if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 || |
| 419 | host->mmc->ios.timing == MMC_TIMING_MMC_DDR52) |
Srinivas Kandagatla | e874064 | 2014-06-02 10:09:30 +0100 | [diff] [blame] | 420 | clk |= variant->clkreg_neg_edge_enable; |
Ulf Hansson | 6dbb6ee | 2013-01-07 15:30:44 +0100 | [diff] [blame] | 421 | |
Ulf Hansson | 7437cfa | 2012-01-18 09:17:27 +0100 | [diff] [blame] | 422 | mmci_write_clkreg(host, clk); |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 425 | void mmci_dma_release(struct mmci_host *host) |
| 426 | { |
| 427 | if (host->ops && host->ops->dma_release) |
| 428 | host->ops->dma_release(host); |
| 429 | |
| 430 | host->use_dma = false; |
| 431 | } |
| 432 | |
| 433 | void mmci_dma_setup(struct mmci_host *host) |
| 434 | { |
| 435 | if (!host->ops || !host->ops->dma_setup) |
| 436 | return; |
| 437 | |
| 438 | if (host->ops->dma_setup(host)) |
| 439 | return; |
| 440 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 441 | /* initialize pre request cookie */ |
| 442 | host->next_cookie = 1; |
| 443 | |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 444 | host->use_dma = true; |
| 445 | } |
| 446 | |
Ludovic Barre | e0da172 | 2018-10-08 14:08:41 +0200 | [diff] [blame] | 447 | /* |
| 448 | * Validate mmc prerequisites |
| 449 | */ |
| 450 | static int mmci_validate_data(struct mmci_host *host, |
| 451 | struct mmc_data *data) |
| 452 | { |
| 453 | if (!data) |
| 454 | return 0; |
| 455 | |
| 456 | if (!is_power_of_2(data->blksz)) { |
| 457 | dev_err(mmc_dev(host->mmc), |
| 458 | "unsupported block size (%d bytes)\n", data->blksz); |
| 459 | return -EINVAL; |
| 460 | } |
| 461 | |
| 462 | if (host->ops && host->ops->validate_data) |
| 463 | return host->ops->validate_data(host, data); |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 468 | int mmci_prep_data(struct mmci_host *host, struct mmc_data *data, bool next) |
| 469 | { |
| 470 | int err; |
| 471 | |
| 472 | if (!host->ops || !host->ops->prep_data) |
| 473 | return 0; |
| 474 | |
| 475 | err = host->ops->prep_data(host, data, next); |
| 476 | |
| 477 | if (next && !err) |
| 478 | data->host_cookie = ++host->next_cookie < 0 ? |
| 479 | 1 : host->next_cookie; |
| 480 | |
| 481 | return err; |
| 482 | } |
| 483 | |
| 484 | void mmci_unprep_data(struct mmci_host *host, struct mmc_data *data, |
| 485 | int err) |
| 486 | { |
| 487 | if (host->ops && host->ops->unprep_data) |
| 488 | host->ops->unprep_data(host, data, err); |
| 489 | |
| 490 | data->host_cookie = 0; |
| 491 | } |
| 492 | |
Ludovic Barre | 0276996 | 2018-10-08 14:08:37 +0200 | [diff] [blame] | 493 | void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data) |
| 494 | { |
| 495 | WARN_ON(data->host_cookie && data->host_cookie != host->next_cookie); |
| 496 | |
| 497 | if (host->ops && host->ops->get_next_data) |
| 498 | host->ops->get_next_data(host, data); |
| 499 | } |
| 500 | |
Ludovic Barre | 135ea30 | 2018-10-08 14:08:38 +0200 | [diff] [blame] | 501 | int mmci_dma_start(struct mmci_host *host, unsigned int datactrl) |
| 502 | { |
| 503 | struct mmc_data *data = host->data; |
| 504 | int ret; |
| 505 | |
| 506 | if (!host->use_dma) |
| 507 | return -EINVAL; |
| 508 | |
| 509 | ret = mmci_prep_data(host, data, false); |
| 510 | if (ret) |
| 511 | return ret; |
| 512 | |
| 513 | if (!host->ops || !host->ops->dma_start) |
| 514 | return -EINVAL; |
| 515 | |
| 516 | /* Okay, go for it. */ |
| 517 | dev_vdbg(mmc_dev(host->mmc), |
| 518 | "Submit MMCI DMA job, sglen %d blksz %04x blks %04x flags %08x\n", |
| 519 | data->sg_len, data->blksz, data->blocks, data->flags); |
| 520 | |
| 521 | host->ops->dma_start(host, &datactrl); |
| 522 | |
| 523 | /* Trigger the DMA transfer */ |
| 524 | mmci_write_datactrlreg(host, datactrl); |
| 525 | |
| 526 | /* |
| 527 | * Let the MMCI say when the data is ended and it's time |
| 528 | * to fire next DMA request. When that happens, MMCI will |
| 529 | * call mmci_data_end() |
| 530 | */ |
| 531 | writel(readl(host->base + MMCIMASK0) | MCI_DATAENDMASK, |
| 532 | host->base + MMCIMASK0); |
| 533 | return 0; |
| 534 | } |
| 535 | |
Ludovic Barre | 5a9f10c | 2018-10-08 14:08:39 +0200 | [diff] [blame] | 536 | void mmci_dma_finalize(struct mmci_host *host, struct mmc_data *data) |
| 537 | { |
| 538 | if (!host->use_dma) |
| 539 | return; |
| 540 | |
| 541 | if (host->ops && host->ops->dma_finalize) |
| 542 | host->ops->dma_finalize(host, data); |
| 543 | } |
| 544 | |
Ludovic Barre | cfccc6a | 2018-10-08 14:08:40 +0200 | [diff] [blame] | 545 | void mmci_dma_error(struct mmci_host *host) |
| 546 | { |
| 547 | if (!host->use_dma) |
| 548 | return; |
| 549 | |
| 550 | if (host->ops && host->ops->dma_error) |
| 551 | host->ops->dma_error(host); |
| 552 | } |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | static void |
| 555 | mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) |
| 556 | { |
| 557 | writel(0, host->base + MMCICOMMAND); |
| 558 | |
Russell King | e47c222 | 2007-01-08 16:42:51 +0000 | [diff] [blame] | 559 | BUG_ON(host->data); |
| 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | host->mrq = NULL; |
| 562 | host->cmd = NULL; |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | mmc_request_done(host->mmc, mrq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 567 | static void mmci_set_mask1(struct mmci_host *host, unsigned int mask) |
| 568 | { |
| 569 | void __iomem *base = host->base; |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 570 | struct variant_data *variant = host->variant; |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 571 | |
| 572 | if (host->singleirq) { |
| 573 | unsigned int mask0 = readl(base + MMCIMASK0); |
| 574 | |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 575 | mask0 &= ~variant->irq_pio_mask; |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 576 | mask0 |= mask; |
| 577 | |
| 578 | writel(mask0, base + MMCIMASK0); |
| 579 | } |
| 580 | |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 581 | if (variant->mmcimask1) |
| 582 | writel(mask, base + MMCIMASK1); |
| 583 | |
| 584 | host->mask1_reg = mask; |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 585 | } |
| 586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | static void mmci_stop_data(struct mmci_host *host) |
| 588 | { |
Ulf Hansson | 9cc639a | 2013-05-15 20:48:23 +0100 | [diff] [blame] | 589 | mmci_write_datactrlreg(host, 0); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 590 | mmci_set_mask1(host, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | host->data = NULL; |
| 592 | } |
| 593 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 594 | static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data) |
| 595 | { |
| 596 | unsigned int flags = SG_MITER_ATOMIC; |
| 597 | |
| 598 | if (data->flags & MMC_DATA_READ) |
| 599 | flags |= SG_MITER_TO_SG; |
| 600 | else |
| 601 | flags |= SG_MITER_FROM_SG; |
| 602 | |
| 603 | sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); |
| 604 | } |
| 605 | |
Ludovic Barre | b3fb9d6 | 2019-03-27 10:05:29 +0100 | [diff] [blame] | 606 | static u32 mmci_get_dctrl_cfg(struct mmci_host *host) |
| 607 | { |
| 608 | return MCI_DPSM_ENABLE | mmci_dctrl_blksz(host); |
| 609 | } |
| 610 | |
| 611 | static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host) |
| 612 | { |
| 613 | return MCI_DPSM_ENABLE | (host->data->blksz << 16); |
| 614 | } |
| 615 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 616 | /* |
| 617 | * All the DMA operation mode stuff goes inside this ifdef. |
| 618 | * This assumes that you have a generic DMA device interface, |
| 619 | * no custom DMA interfaces are supported. |
| 620 | */ |
| 621 | #ifdef CONFIG_DMA_ENGINE |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 622 | struct mmci_dmae_next { |
| 623 | struct dma_async_tx_descriptor *desc; |
| 624 | struct dma_chan *chan; |
| 625 | }; |
| 626 | |
| 627 | struct mmci_dmae_priv { |
| 628 | struct dma_chan *cur; |
| 629 | struct dma_chan *rx_channel; |
| 630 | struct dma_chan *tx_channel; |
| 631 | struct dma_async_tx_descriptor *desc_current; |
| 632 | struct mmci_dmae_next next_data; |
| 633 | }; |
| 634 | |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 635 | int mmci_dmae_setup(struct mmci_host *host) |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 636 | { |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 637 | const char *rxname, *txname; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 638 | struct mmci_dmae_priv *dmae; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 639 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 640 | dmae = devm_kzalloc(mmc_dev(host->mmc), sizeof(*dmae), GFP_KERNEL); |
| 641 | if (!dmae) |
| 642 | return -ENOMEM; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 643 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 644 | host->dma_priv = dmae; |
| 645 | |
| 646 | dmae->rx_channel = dma_request_slave_channel(mmc_dev(host->mmc), |
| 647 | "rx"); |
| 648 | dmae->tx_channel = dma_request_slave_channel(mmc_dev(host->mmc), |
| 649 | "tx"); |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 650 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 651 | /* |
| 652 | * If only an RX channel is specified, the driver will |
| 653 | * attempt to use it bidirectionally, however if it is |
| 654 | * is specified but cannot be located, DMA will be disabled. |
| 655 | */ |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 656 | if (dmae->rx_channel && !dmae->tx_channel) |
| 657 | dmae->tx_channel = dmae->rx_channel; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 658 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 659 | if (dmae->rx_channel) |
| 660 | rxname = dma_chan_name(dmae->rx_channel); |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 661 | else |
| 662 | rxname = "none"; |
| 663 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 664 | if (dmae->tx_channel) |
| 665 | txname = dma_chan_name(dmae->tx_channel); |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 666 | else |
| 667 | txname = "none"; |
| 668 | |
| 669 | dev_info(mmc_dev(host->mmc), "DMA channels RX %s, TX %s\n", |
| 670 | rxname, txname); |
| 671 | |
| 672 | /* |
| 673 | * Limit the maximum segment size in any SG entry according to |
| 674 | * the parameters of the DMA engine device. |
| 675 | */ |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 676 | if (dmae->tx_channel) { |
| 677 | struct device *dev = dmae->tx_channel->device->dev; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 678 | unsigned int max_seg_size = dma_get_max_seg_size(dev); |
| 679 | |
| 680 | if (max_seg_size < host->mmc->max_seg_size) |
| 681 | host->mmc->max_seg_size = max_seg_size; |
| 682 | } |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 683 | if (dmae->rx_channel) { |
| 684 | struct device *dev = dmae->rx_channel->device->dev; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 685 | unsigned int max_seg_size = dma_get_max_seg_size(dev); |
| 686 | |
| 687 | if (max_seg_size < host->mmc->max_seg_size) |
| 688 | host->mmc->max_seg_size = max_seg_size; |
| 689 | } |
Srinivas Kandagatla | 9cb1514 | 2014-07-29 03:50:30 +0100 | [diff] [blame] | 690 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 691 | if (!dmae->tx_channel || !dmae->rx_channel) { |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 692 | mmci_dmae_release(host); |
| 693 | return -EINVAL; |
| 694 | } |
| 695 | |
| 696 | return 0; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /* |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 700 | * This is used in or so inline it |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 701 | * so it can be discarded. |
| 702 | */ |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 703 | void mmci_dmae_release(struct mmci_host *host) |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 704 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 705 | struct mmci_dmae_priv *dmae = host->dma_priv; |
| 706 | |
| 707 | if (dmae->rx_channel) |
| 708 | dma_release_channel(dmae->rx_channel); |
| 709 | if (dmae->tx_channel) |
| 710 | dma_release_channel(dmae->tx_channel); |
| 711 | dmae->rx_channel = dmae->tx_channel = NULL; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data) |
| 715 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 716 | struct mmci_dmae_priv *dmae = host->dma_priv; |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 717 | struct dma_chan *chan; |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 718 | |
Heiner Kallweit | feeef09 | 2017-03-26 20:45:56 +0200 | [diff] [blame] | 719 | if (data->flags & MMC_DATA_READ) |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 720 | chan = dmae->rx_channel; |
Heiner Kallweit | feeef09 | 2017-03-26 20:45:56 +0200 | [diff] [blame] | 721 | else |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 722 | chan = dmae->tx_channel; |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 723 | |
Heiner Kallweit | feeef09 | 2017-03-26 20:45:56 +0200 | [diff] [blame] | 724 | dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, |
| 725 | mmc_get_dma_dir(data)); |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 726 | } |
| 727 | |
Ludovic Barre | cfccc6a | 2018-10-08 14:08:40 +0200 | [diff] [blame] | 728 | void mmci_dmae_error(struct mmci_host *host) |
Ludovic Barre | 7b2a6d5 | 2018-09-21 11:45:55 +0200 | [diff] [blame] | 729 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 730 | struct mmci_dmae_priv *dmae = host->dma_priv; |
| 731 | |
Ludovic Barre | cfccc6a | 2018-10-08 14:08:40 +0200 | [diff] [blame] | 732 | if (!dma_inprogress(host)) |
Ludovic Barre | cdea194 | 2018-09-21 11:45:56 +0200 | [diff] [blame] | 733 | return; |
| 734 | |
Ludovic Barre | 7b2a6d5 | 2018-09-21 11:45:55 +0200 | [diff] [blame] | 735 | dev_err(mmc_dev(host->mmc), "error during DMA transfer!\n"); |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 736 | dmaengine_terminate_all(dmae->cur); |
Ludovic Barre | 7b2a6d5 | 2018-09-21 11:45:55 +0200 | [diff] [blame] | 737 | host->dma_in_progress = false; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 738 | dmae->cur = NULL; |
| 739 | dmae->desc_current = NULL; |
Ludovic Barre | 7b2a6d5 | 2018-09-21 11:45:55 +0200 | [diff] [blame] | 740 | host->data->host_cookie = 0; |
| 741 | |
| 742 | mmci_dma_unmap(host, host->data); |
| 743 | } |
| 744 | |
Ludovic Barre | 5a9f10c | 2018-10-08 14:08:39 +0200 | [diff] [blame] | 745 | void mmci_dmae_finalize(struct mmci_host *host, struct mmc_data *data) |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 746 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 747 | struct mmci_dmae_priv *dmae = host->dma_priv; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 748 | u32 status; |
| 749 | int i; |
| 750 | |
Ludovic Barre | 5a9f10c | 2018-10-08 14:08:39 +0200 | [diff] [blame] | 751 | if (!dma_inprogress(host)) |
Ludovic Barre | cdea194 | 2018-09-21 11:45:56 +0200 | [diff] [blame] | 752 | return; |
| 753 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 754 | /* Wait up to 1ms for the DMA to complete */ |
| 755 | for (i = 0; ; i++) { |
| 756 | status = readl(host->base + MMCISTATUS); |
| 757 | if (!(status & MCI_RXDATAAVLBLMASK) || i >= 100) |
| 758 | break; |
| 759 | udelay(10); |
| 760 | } |
| 761 | |
| 762 | /* |
| 763 | * Check to see whether we still have some data left in the FIFO - |
| 764 | * this catches DMA controllers which are unable to monitor the |
| 765 | * DMALBREQ and DMALSREQ signals while allowing us to DMA to non- |
| 766 | * contiguous buffers. On TX, we'll get a FIFO underrun error. |
| 767 | */ |
| 768 | if (status & MCI_RXDATAAVLBLMASK) { |
Ludovic Barre | cfccc6a | 2018-10-08 14:08:40 +0200 | [diff] [blame] | 769 | mmci_dma_error(host); |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 770 | if (!data->error) |
| 771 | data->error = -EIO; |
Ludovic Barre | 7b2a6d5 | 2018-09-21 11:45:55 +0200 | [diff] [blame] | 772 | } else if (!data->host_cookie) { |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 773 | mmci_dma_unmap(host, data); |
Ludovic Barre | 7b2a6d5 | 2018-09-21 11:45:55 +0200 | [diff] [blame] | 774 | } |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 775 | |
| 776 | /* |
| 777 | * Use of DMA with scatter-gather is impossible. |
| 778 | * Give up with DMA and switch back to PIO mode. |
| 779 | */ |
| 780 | if (status & MCI_RXDATAAVLBLMASK) { |
| 781 | dev_err(mmc_dev(host->mmc), "buggy DMA detected. Taking evasive action.\n"); |
| 782 | mmci_dma_release(host); |
| 783 | } |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 784 | |
Linus Walleij | e13934b | 2017-01-27 15:04:54 +0100 | [diff] [blame] | 785 | host->dma_in_progress = false; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 786 | dmae->cur = NULL; |
| 787 | dmae->desc_current = NULL; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 790 | /* prepares DMA channel and DMA descriptor, returns non-zero on failure */ |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 791 | static int _mmci_dmae_prep_data(struct mmci_host *host, struct mmc_data *data, |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 792 | struct dma_chan **dma_chan, |
| 793 | struct dma_async_tx_descriptor **dma_desc) |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 794 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 795 | struct mmci_dmae_priv *dmae = host->dma_priv; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 796 | struct variant_data *variant = host->variant; |
| 797 | struct dma_slave_config conf = { |
| 798 | .src_addr = host->phybase + MMCIFIFO, |
| 799 | .dst_addr = host->phybase + MMCIFIFO, |
| 800 | .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, |
| 801 | .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, |
| 802 | .src_maxburst = variant->fifohalfsize >> 2, /* # of words */ |
| 803 | .dst_maxburst = variant->fifohalfsize >> 2, /* # of words */ |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 804 | .device_fc = false, |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 805 | }; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 806 | struct dma_chan *chan; |
| 807 | struct dma_device *device; |
| 808 | struct dma_async_tx_descriptor *desc; |
| 809 | int nr_sg; |
Srinivas Kandagatla | 9cb1514 | 2014-07-29 03:50:30 +0100 | [diff] [blame] | 810 | unsigned long flags = DMA_CTRL_ACK; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 811 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 812 | if (data->flags & MMC_DATA_READ) { |
Vinod Koul | 05f5799 | 2011-10-14 10:45:11 +0530 | [diff] [blame] | 813 | conf.direction = DMA_DEV_TO_MEM; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 814 | chan = dmae->rx_channel; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 815 | } else { |
Vinod Koul | 05f5799 | 2011-10-14 10:45:11 +0530 | [diff] [blame] | 816 | conf.direction = DMA_MEM_TO_DEV; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 817 | chan = dmae->tx_channel; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /* If there's no DMA channel, fall back to PIO */ |
| 821 | if (!chan) |
| 822 | return -EINVAL; |
| 823 | |
| 824 | /* If less than or equal to the fifo size, don't bother with DMA */ |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 825 | if (data->blksz * data->blocks <= variant->fifosize) |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 826 | return -EINVAL; |
| 827 | |
| 828 | device = chan->device; |
Heiner Kallweit | feeef09 | 2017-03-26 20:45:56 +0200 | [diff] [blame] | 829 | nr_sg = dma_map_sg(device->dev, data->sg, data->sg_len, |
| 830 | mmc_get_dma_dir(data)); |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 831 | if (nr_sg == 0) |
| 832 | return -EINVAL; |
| 833 | |
Srinivas Kandagatla | 9cb1514 | 2014-07-29 03:50:30 +0100 | [diff] [blame] | 834 | if (host->variant->qcom_dml) |
| 835 | flags |= DMA_PREP_INTERRUPT; |
| 836 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 837 | dmaengine_slave_config(chan, &conf); |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 838 | desc = dmaengine_prep_slave_sg(chan, data->sg, nr_sg, |
Srinivas Kandagatla | 9cb1514 | 2014-07-29 03:50:30 +0100 | [diff] [blame] | 839 | conf.direction, flags); |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 840 | if (!desc) |
| 841 | goto unmap_exit; |
| 842 | |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 843 | *dma_chan = chan; |
| 844 | *dma_desc = desc; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 845 | |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 846 | return 0; |
| 847 | |
| 848 | unmap_exit: |
Heiner Kallweit | feeef09 | 2017-03-26 20:45:56 +0200 | [diff] [blame] | 849 | dma_unmap_sg(device->dev, data->sg, data->sg_len, |
| 850 | mmc_get_dma_dir(data)); |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 851 | return -ENOMEM; |
| 852 | } |
| 853 | |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 854 | int mmci_dmae_prep_data(struct mmci_host *host, |
| 855 | struct mmc_data *data, |
| 856 | bool next) |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 857 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 858 | struct mmci_dmae_priv *dmae = host->dma_priv; |
Ludovic Barre | ad7b891 | 2018-10-08 14:08:35 +0200 | [diff] [blame] | 859 | struct mmci_dmae_next *nd = &dmae->next_data; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 860 | |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 861 | if (!host->use_dma) |
| 862 | return -EINVAL; |
| 863 | |
Ludovic Barre | ad7b891 | 2018-10-08 14:08:35 +0200 | [diff] [blame] | 864 | if (next) |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 865 | return _mmci_dmae_prep_data(host, data, &nd->chan, &nd->desc); |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 866 | /* Check if next job is already prepared. */ |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 867 | if (dmae->cur && dmae->desc_current) |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 868 | return 0; |
| 869 | |
| 870 | /* No job were prepared thus do it now. */ |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 871 | return _mmci_dmae_prep_data(host, data, &dmae->cur, |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 872 | &dmae->desc_current); |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 873 | } |
| 874 | |
Ludovic Barre | 135ea30 | 2018-10-08 14:08:38 +0200 | [diff] [blame] | 875 | int mmci_dmae_start(struct mmci_host *host, unsigned int *datactrl) |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 876 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 877 | struct mmci_dmae_priv *dmae = host->dma_priv; |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 878 | |
Linus Walleij | e13934b | 2017-01-27 15:04:54 +0100 | [diff] [blame] | 879 | host->dma_in_progress = true; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 880 | dmaengine_submit(dmae->desc_current); |
| 881 | dma_async_issue_pending(dmae->cur); |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 882 | |
Ludovic Barre | 135ea30 | 2018-10-08 14:08:38 +0200 | [diff] [blame] | 883 | *datactrl |= MCI_DPSM_DMAENABLE; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 884 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 885 | return 0; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 886 | } |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 887 | |
Ludovic Barre | 0276996 | 2018-10-08 14:08:37 +0200 | [diff] [blame] | 888 | void mmci_dmae_get_next_data(struct mmci_host *host, struct mmc_data *data) |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 889 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 890 | struct mmci_dmae_priv *dmae = host->dma_priv; |
| 891 | struct mmci_dmae_next *next = &dmae->next_data; |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 892 | |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 893 | if (!host->use_dma) |
| 894 | return; |
| 895 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 896 | WARN_ON(!data->host_cookie && (next->desc || next->chan)); |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 897 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 898 | dmae->desc_current = next->desc; |
| 899 | dmae->cur = next->chan; |
| 900 | next->desc = NULL; |
| 901 | next->chan = NULL; |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 902 | } |
| 903 | |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 904 | void mmci_dmae_unprep_data(struct mmci_host *host, |
| 905 | struct mmc_data *data, int err) |
| 906 | |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 907 | { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 908 | struct mmci_dmae_priv *dmae = host->dma_priv; |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 909 | |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 910 | if (!host->use_dma) |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 911 | return; |
| 912 | |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 913 | mmci_dma_unmap(host, data); |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 914 | |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 915 | if (err) { |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 916 | struct mmci_dmae_next *next = &dmae->next_data; |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 917 | struct dma_chan *chan; |
| 918 | if (data->flags & MMC_DATA_READ) |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 919 | chan = dmae->rx_channel; |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 920 | else |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 921 | chan = dmae->tx_channel; |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 922 | dmaengine_terminate_all(chan); |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 923 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 924 | if (dmae->desc_current == next->desc) |
| 925 | dmae->desc_current = NULL; |
Srinivas Kandagatla | b5c16a6 | 2014-10-08 12:25:17 +0100 | [diff] [blame] | 926 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 927 | if (dmae->cur == next->chan) { |
Linus Walleij | e13934b | 2017-01-27 15:04:54 +0100 | [diff] [blame] | 928 | host->dma_in_progress = false; |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 929 | dmae->cur = NULL; |
Linus Walleij | e13934b | 2017-01-27 15:04:54 +0100 | [diff] [blame] | 930 | } |
Srinivas Kandagatla | b5c16a6 | 2014-10-08 12:25:17 +0100 | [diff] [blame] | 931 | |
Ludovic Barre | a813f2a | 2018-10-08 14:08:34 +0200 | [diff] [blame] | 932 | next->desc = NULL; |
| 933 | next->chan = NULL; |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 937 | static struct mmci_host_ops mmci_variant_ops = { |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 938 | .prep_data = mmci_dmae_prep_data, |
| 939 | .unprep_data = mmci_dmae_unprep_data, |
Ludovic Barre | b3fb9d6 | 2019-03-27 10:05:29 +0100 | [diff] [blame] | 940 | .get_datactrl_cfg = mmci_get_dctrl_cfg, |
Ludovic Barre | 0276996 | 2018-10-08 14:08:37 +0200 | [diff] [blame] | 941 | .get_next_data = mmci_dmae_get_next_data, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 942 | .dma_setup = mmci_dmae_setup, |
| 943 | .dma_release = mmci_dmae_release, |
Ludovic Barre | 135ea30 | 2018-10-08 14:08:38 +0200 | [diff] [blame] | 944 | .dma_start = mmci_dmae_start, |
Ludovic Barre | 5a9f10c | 2018-10-08 14:08:39 +0200 | [diff] [blame] | 945 | .dma_finalize = mmci_dmae_finalize, |
Ludovic Barre | cfccc6a | 2018-10-08 14:08:40 +0200 | [diff] [blame] | 946 | .dma_error = mmci_dmae_error, |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 947 | }; |
Ludovic Barre | b3fb9d6 | 2019-03-27 10:05:29 +0100 | [diff] [blame] | 948 | #else |
| 949 | static struct mmci_host_ops mmci_variant_ops = { |
| 950 | .get_datactrl_cfg = mmci_get_dctrl_cfg, |
| 951 | }; |
| 952 | #endif |
Ludovic Barre | c3647fd | 2018-10-08 14:08:33 +0200 | [diff] [blame] | 953 | |
| 954 | void mmci_variant_init(struct mmci_host *host) |
| 955 | { |
| 956 | host->ops = &mmci_variant_ops; |
| 957 | } |
Ludovic Barre | b3fb9d6 | 2019-03-27 10:05:29 +0100 | [diff] [blame] | 958 | |
| 959 | void ux500v2_variant_init(struct mmci_host *host) |
| 960 | { |
| 961 | host->ops = &mmci_variant_ops; |
| 962 | host->ops->get_datactrl_cfg = ux500v2_get_dctrl_cfg; |
| 963 | } |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 964 | |
Ludovic Barre | 4798351 | 2018-10-08 14:08:36 +0200 | [diff] [blame] | 965 | static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 966 | { |
| 967 | struct mmci_host *host = mmc_priv(mmc); |
| 968 | struct mmc_data *data = mrq->data; |
| 969 | |
| 970 | if (!data) |
| 971 | return; |
| 972 | |
| 973 | WARN_ON(data->host_cookie); |
| 974 | |
| 975 | if (mmci_validate_data(host, data)) |
| 976 | return; |
| 977 | |
| 978 | mmci_prep_data(host, data, true); |
| 979 | } |
| 980 | |
| 981 | static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq, |
| 982 | int err) |
| 983 | { |
| 984 | struct mmci_host *host = mmc_priv(mmc); |
| 985 | struct mmc_data *data = mrq->data; |
| 986 | |
| 987 | if (!data || !data->host_cookie) |
| 988 | return; |
| 989 | |
| 990 | mmci_unprep_data(host, data, err); |
| 991 | } |
| 992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) |
| 994 | { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 995 | struct variant_data *variant = host->variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | unsigned int datactrl, timeout, irqmask; |
Russell King | 7b09cda | 2005-07-01 12:02:59 +0100 | [diff] [blame] | 997 | unsigned long long clks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | void __iomem *base; |
| 999 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 1000 | dev_dbg(mmc_dev(host->mmc), "blksz %04x blks %04x flags %08x\n", |
| 1001 | data->blksz, data->blocks, data->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | host->data = data; |
Rabin Vincent | 528320d | 2010-07-21 12:49:49 +0100 | [diff] [blame] | 1004 | host->size = data->blksz * data->blocks; |
Russell King | 51d4375 | 2011-01-27 10:56:52 +0000 | [diff] [blame] | 1005 | data->bytes_xfered = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Russell King | 7b09cda | 2005-07-01 12:02:59 +0100 | [diff] [blame] | 1007 | clks = (unsigned long long)data->timeout_ns * host->cclk; |
Srinivas Kandagatla | c4a3576 | 2014-06-02 10:08:39 +0100 | [diff] [blame] | 1008 | do_div(clks, NSEC_PER_SEC); |
Russell King | 7b09cda | 2005-07-01 12:02:59 +0100 | [diff] [blame] | 1009 | |
| 1010 | timeout = data->timeout_clks + (unsigned int)clks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
| 1012 | base = host->base; |
| 1013 | writel(timeout, base + MMCIDATATIMER); |
| 1014 | writel(host->size, base + MMCIDATALENGTH); |
| 1015 | |
Ludovic Barre | 41ed65e | 2019-03-27 10:05:32 +0100 | [diff] [blame] | 1016 | datactrl = host->ops->get_datactrl_cfg(host); |
| 1017 | datactrl |= host->data->flags & MMC_DATA_READ ? MCI_DPSM_DIRECTION : 0; |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 1018 | |
Srinivas Kandagatla | c735413 | 2014-08-22 05:55:16 +0100 | [diff] [blame] | 1019 | if (host->mmc->card && mmc_card_sdio(host->mmc->card)) { |
| 1020 | u32 clk; |
Ulf Hansson | 7258db7 | 2011-12-13 17:05:28 +0100 | [diff] [blame] | 1021 | |
Srinivas Kandagatla | c735413 | 2014-08-22 05:55:16 +0100 | [diff] [blame] | 1022 | datactrl |= variant->datactrl_mask_sdio; |
Ulf Hansson | 06c1a12 | 2012-10-12 14:01:50 +0100 | [diff] [blame] | 1023 | |
Srinivas Kandagatla | c735413 | 2014-08-22 05:55:16 +0100 | [diff] [blame] | 1024 | /* |
| 1025 | * The ST Micro variant for SDIO small write transfers |
| 1026 | * needs to have clock H/W flow control disabled, |
| 1027 | * otherwise the transfer will not start. The threshold |
| 1028 | * depends on the rate of MCLK. |
| 1029 | */ |
| 1030 | if (variant->st_sdio && data->flags & MMC_DATA_WRITE && |
| 1031 | (host->size < 8 || |
| 1032 | (host->size <= 8 && host->mclk > 50000000))) |
| 1033 | clk = host->clk_reg & ~variant->clkreg_enable; |
| 1034 | else |
| 1035 | clk = host->clk_reg | variant->clkreg_enable; |
| 1036 | |
| 1037 | mmci_write_clkreg(host, clk); |
| 1038 | } |
Ulf Hansson | 06c1a12 | 2012-10-12 14:01:50 +0100 | [diff] [blame] | 1039 | |
Seungwon Jeon | 6dad6c9 | 2014-03-14 21:12:13 +0900 | [diff] [blame] | 1040 | if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 || |
| 1041 | host->mmc->ios.timing == MMC_TIMING_MMC_DDR52) |
Srinivas Kandagatla | e17dca2 | 2014-06-02 10:09:15 +0100 | [diff] [blame] | 1042 | datactrl |= variant->datactrl_mask_ddrmode; |
Ulf Hansson | 6dbb6ee | 2013-01-07 15:30:44 +0100 | [diff] [blame] | 1043 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 1044 | /* |
| 1045 | * Attempt to use DMA operation mode, if this |
| 1046 | * should fail, fall back to PIO mode |
| 1047 | */ |
Ludovic Barre | 135ea30 | 2018-10-08 14:08:38 +0200 | [diff] [blame] | 1048 | if (!mmci_dma_start(host, datactrl)) |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 1049 | return; |
| 1050 | |
| 1051 | /* IRQ mode, map the SG list for CPU reading/writing */ |
| 1052 | mmci_init_sg(host, data); |
| 1053 | |
| 1054 | if (data->flags & MMC_DATA_READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | irqmask = MCI_RXFIFOHALFFULLMASK; |
Russell King | 0425a14 | 2006-02-16 16:48:31 +0000 | [diff] [blame] | 1056 | |
| 1057 | /* |
Russell King | c4d877c | 2011-01-27 09:50:13 +0000 | [diff] [blame] | 1058 | * If we have less than the fifo 'half-full' threshold to |
| 1059 | * transfer, trigger a PIO interrupt as soon as any data |
| 1060 | * is available. |
Russell King | 0425a14 | 2006-02-16 16:48:31 +0000 | [diff] [blame] | 1061 | */ |
Russell King | c4d877c | 2011-01-27 09:50:13 +0000 | [diff] [blame] | 1062 | if (host->size < variant->fifohalfsize) |
Russell King | 0425a14 | 2006-02-16 16:48:31 +0000 | [diff] [blame] | 1063 | irqmask |= MCI_RXDATAAVLBLMASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | } else { |
| 1065 | /* |
| 1066 | * We don't actually need to include "FIFO empty" here |
| 1067 | * since its implicit in "FIFO half empty". |
| 1068 | */ |
| 1069 | irqmask = MCI_TXFIFOHALFEMPTYMASK; |
| 1070 | } |
| 1071 | |
Ulf Hansson | 9cc639a | 2013-05-15 20:48:23 +0100 | [diff] [blame] | 1072 | mmci_write_datactrlreg(host, datactrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 1074 | mmci_set_mask1(host, irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static void |
| 1078 | mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) |
| 1079 | { |
| 1080 | void __iomem *base = host->base; |
| 1081 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 1082 | dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | cmd->opcode, cmd->arg, cmd->flags); |
| 1084 | |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 1085 | if (readl(base + MMCICOMMAND) & host->variant->cmdreg_cpsm_enable) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | writel(0, base + MMCICOMMAND); |
Srinivas Kandagatla | 6adb2a8 | 2014-06-02 10:08:57 +0100 | [diff] [blame] | 1087 | mmci_reg_delay(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Ludovic Barre | c8073e5 | 2018-12-06 16:13:31 +0100 | [diff] [blame] | 1090 | if (host->variant->cmdreg_stop && |
| 1091 | cmd->opcode == MMC_STOP_TRANSMISSION) |
| 1092 | c |= host->variant->cmdreg_stop; |
| 1093 | |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 1094 | c |= cmd->opcode | host->variant->cmdreg_cpsm_enable; |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 1095 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 1096 | if (cmd->flags & MMC_RSP_136) |
Ludovic Barre | 0f24480 | 2018-10-08 14:08:45 +0200 | [diff] [blame] | 1097 | c |= host->variant->cmdreg_lrsp_crc; |
| 1098 | else if (cmd->flags & MMC_RSP_CRC) |
| 1099 | c |= host->variant->cmdreg_srsp_crc; |
| 1100 | else |
| 1101 | c |= host->variant->cmdreg_srsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | if (/*interrupt*/0) |
| 1104 | c |= MCI_CPSM_INTERRUPT; |
| 1105 | |
Srinivas Kandagatla | ae7b006 | 2014-06-02 10:09:39 +0100 | [diff] [blame] | 1106 | if (mmc_cmd_type(cmd) == MMC_CMD_ADTC) |
| 1107 | c |= host->variant->data_cmd_enable; |
| 1108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | host->cmd = cmd; |
| 1110 | |
| 1111 | writel(cmd->arg, base + MMCIARGUMENT); |
| 1112 | writel(c, base + MMCICOMMAND); |
| 1113 | } |
| 1114 | |
Ulf Hansson | e9968c6 | 2019-01-29 15:35:56 +0100 | [diff] [blame] | 1115 | static void mmci_stop_command(struct mmci_host *host) |
| 1116 | { |
| 1117 | host->stop_abort.error = 0; |
| 1118 | mmci_start_command(host, &host->stop_abort, 0); |
| 1119 | } |
| 1120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | static void |
| 1122 | mmci_data_irq(struct mmci_host *host, struct mmc_data *data, |
| 1123 | unsigned int status) |
| 1124 | { |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 1125 | unsigned int status_err; |
| 1126 | |
Ulf Hansson | 1cb9da5 | 2014-06-12 14:42:23 +0200 | [diff] [blame] | 1127 | /* Make sure we have data to handle */ |
| 1128 | if (!data) |
| 1129 | return; |
| 1130 | |
Linus Walleij | f20f8f21 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 1131 | /* First check for errors */ |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 1132 | status_err = status & (host->variant->start_err | |
| 1133 | MCI_DATACRCFAIL | MCI_DATATIMEOUT | |
| 1134 | MCI_TXUNDERRUN | MCI_RXOVERRUN); |
| 1135 | |
| 1136 | if (status_err) { |
Linus Walleij | 8cb2815 | 2011-01-24 15:22:13 +0100 | [diff] [blame] | 1137 | u32 remain, success; |
Linus Walleij | f20f8f21 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 1138 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 1139 | /* Terminate the DMA transfer */ |
Ludovic Barre | cfccc6a | 2018-10-08 14:08:40 +0200 | [diff] [blame] | 1140 | mmci_dma_error(host); |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 1141 | |
Russell King | c8afc9d | 2011-02-04 09:19:46 +0000 | [diff] [blame] | 1142 | /* |
| 1143 | * Calculate how far we are into the transfer. Note that |
| 1144 | * the data counter gives the number of bytes transferred |
| 1145 | * on the MMC bus, not on the host side. On reads, this |
| 1146 | * can be as much as a FIFO-worth of data ahead. This |
| 1147 | * matters for FIFO overruns only. |
| 1148 | */ |
Ludovic Barre | b79220b | 2018-10-08 14:08:49 +0200 | [diff] [blame] | 1149 | if (!host->variant->datacnt_useless) { |
| 1150 | remain = readl(host->base + MMCIDATACNT); |
| 1151 | success = data->blksz * data->blocks - remain; |
| 1152 | } else { |
| 1153 | success = 0; |
| 1154 | } |
Linus Walleij | 8cb2815 | 2011-01-24 15:22:13 +0100 | [diff] [blame] | 1155 | |
Russell King | c8afc9d | 2011-02-04 09:19:46 +0000 | [diff] [blame] | 1156 | dev_dbg(mmc_dev(host->mmc), "MCI ERROR IRQ, status 0x%08x at 0x%08x\n", |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 1157 | status_err, success); |
| 1158 | if (status_err & MCI_DATACRCFAIL) { |
Linus Walleij | 8cb2815 | 2011-01-24 15:22:13 +0100 | [diff] [blame] | 1159 | /* Last block was not successful */ |
Russell King | c8afc9d | 2011-02-04 09:19:46 +0000 | [diff] [blame] | 1160 | success -= 1; |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1161 | data->error = -EILSEQ; |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 1162 | } else if (status_err & MCI_DATATIMEOUT) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1163 | data->error = -ETIMEDOUT; |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 1164 | } else if (status_err & MCI_STARTBITERR) { |
Linus Walleij | 757df74 | 2011-06-30 15:10:21 +0100 | [diff] [blame] | 1165 | data->error = -ECOMM; |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 1166 | } else if (status_err & MCI_TXUNDERRUN) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1167 | data->error = -EIO; |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 1168 | } else if (status_err & MCI_RXOVERRUN) { |
Russell King | c8afc9d | 2011-02-04 09:19:46 +0000 | [diff] [blame] | 1169 | if (success > host->variant->fifosize) |
| 1170 | success -= host->variant->fifosize; |
| 1171 | else |
| 1172 | success = 0; |
Linus Walleij | 8cb2815 | 2011-01-24 15:22:13 +0100 | [diff] [blame] | 1173 | data->error = -EIO; |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 1174 | } |
Russell King | 51d4375 | 2011-01-27 10:56:52 +0000 | [diff] [blame] | 1175 | data->bytes_xfered = round_down(success, data->blksz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |
Linus Walleij | f20f8f21 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 1177 | |
Linus Walleij | 8cb2815 | 2011-01-24 15:22:13 +0100 | [diff] [blame] | 1178 | if (status & MCI_DATABLOCKEND) |
| 1179 | dev_err(mmc_dev(host->mmc), "stray MCI_DATABLOCKEND interrupt\n"); |
Linus Walleij | f20f8f21 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 1180 | |
Russell King | ccff9b5 | 2011-01-30 21:03:50 +0000 | [diff] [blame] | 1181 | if (status & MCI_DATAEND || data->error) { |
Ludovic Barre | cdea194 | 2018-09-21 11:45:56 +0200 | [diff] [blame] | 1182 | mmci_dma_finalize(host, data); |
| 1183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | mmci_stop_data(host); |
| 1185 | |
Linus Walleij | 8cb2815 | 2011-01-24 15:22:13 +0100 | [diff] [blame] | 1186 | if (!data->error) |
| 1187 | /* The error clause is handled above, success! */ |
Russell King | 51d4375 | 2011-01-27 10:56:52 +0000 | [diff] [blame] | 1188 | data->bytes_xfered = data->blksz * data->blocks; |
Linus Walleij | f20f8f21 | 2010-10-19 13:41:24 +0100 | [diff] [blame] | 1189 | |
Ulf Hansson | e9968c6 | 2019-01-29 15:35:56 +0100 | [diff] [blame] | 1190 | if (!data->stop) { |
| 1191 | if (host->variant->cmdreg_stop && data->error) |
| 1192 | mmci_stop_command(host); |
| 1193 | else |
| 1194 | mmci_request_end(host, data->mrq); |
| 1195 | } else if (host->mrq->sbc && !data->error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | mmci_request_end(host, data->mrq); |
Ulf Hansson | e9968c6 | 2019-01-29 15:35:56 +0100 | [diff] [blame] | 1197 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | mmci_start_command(host, data->stop, 0); |
Ulf Hansson | e9968c6 | 2019-01-29 15:35:56 +0100 | [diff] [blame] | 1199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | static void |
| 1204 | mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, |
| 1205 | unsigned int status) |
| 1206 | { |
| 1207 | void __iomem *base = host->base; |
Ludovic Barre | 812513c | 2019-04-26 09:46:34 +0200 | [diff] [blame] | 1208 | bool sbc, busy_resp; |
Ulf Hansson | ad82bfe | 2014-06-12 15:01:57 +0200 | [diff] [blame] | 1209 | |
| 1210 | if (!cmd) |
| 1211 | return; |
| 1212 | |
| 1213 | sbc = (cmd == host->mrq->sbc); |
Ludovic Barre | 812513c | 2019-04-26 09:46:34 +0200 | [diff] [blame] | 1214 | busy_resp = !!(cmd->flags & MMC_RSP_BUSY); |
Ulf Hansson | ad82bfe | 2014-06-12 15:01:57 +0200 | [diff] [blame] | 1215 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1216 | /* |
| 1217 | * We need to be one of these interrupts to be considered worth |
| 1218 | * handling. Note that we tag on any latent IRQs postponed |
| 1219 | * due to waiting for busy status. |
| 1220 | */ |
| 1221 | if (!((status|host->busy_status) & |
| 1222 | (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND))) |
Ulf Hansson | ad82bfe | 2014-06-12 15:01:57 +0200 | [diff] [blame] | 1223 | return; |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1224 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1225 | /* |
| 1226 | * ST Micro variant: handle busy detection. |
| 1227 | */ |
Ludovic Barre | 812513c | 2019-04-26 09:46:34 +0200 | [diff] [blame] | 1228 | if (busy_resp && host->variant->busy_detect) { |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1229 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1230 | /* We are busy with a command, return */ |
| 1231 | if (host->busy_status && |
| 1232 | (status & host->variant->busy_detect_flag)) |
| 1233 | return; |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1234 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1235 | /* |
| 1236 | * We were not busy, but we now got a busy response on |
| 1237 | * something that was not an error, and we double-check |
| 1238 | * that the special busy status bit is still set before |
| 1239 | * proceeding. |
| 1240 | */ |
Ludovic Barre | 812513c | 2019-04-26 09:46:34 +0200 | [diff] [blame] | 1241 | if (!host->busy_status && |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1242 | !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) && |
| 1243 | (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) { |
Jean-Nicolas Graux | 5cad24d | 2017-02-07 12:12:41 +0100 | [diff] [blame] | 1244 | |
| 1245 | /* Clear the busy start IRQ */ |
| 1246 | writel(host->variant->busy_detect_mask, |
| 1247 | host->base + MMCICLEAR); |
| 1248 | |
| 1249 | /* Unmask the busy end IRQ */ |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1250 | writel(readl(base + MMCIMASK0) | |
| 1251 | host->variant->busy_detect_mask, |
| 1252 | base + MMCIMASK0); |
| 1253 | /* |
| 1254 | * Now cache the last response status code (until |
| 1255 | * the busy bit goes low), and return. |
| 1256 | */ |
| 1257 | host->busy_status = |
| 1258 | status & (MCI_CMDSENT|MCI_CMDRESPEND); |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | /* |
| 1263 | * At this point we are not busy with a command, we have |
Jean-Nicolas Graux | 5cad24d | 2017-02-07 12:12:41 +0100 | [diff] [blame] | 1264 | * not received a new busy request, clear and mask the busy |
| 1265 | * end IRQ and fall through to process the IRQ. |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1266 | */ |
| 1267 | if (host->busy_status) { |
Jean-Nicolas Graux | 5cad24d | 2017-02-07 12:12:41 +0100 | [diff] [blame] | 1268 | |
| 1269 | writel(host->variant->busy_detect_mask, |
| 1270 | host->base + MMCICLEAR); |
| 1271 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1272 | writel(readl(base + MMCIMASK0) & |
| 1273 | ~host->variant->busy_detect_mask, |
| 1274 | base + MMCIMASK0); |
| 1275 | host->busy_status = 0; |
| 1276 | } |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1277 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
| 1279 | host->cmd = NULL; |
| 1280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | if (status & MCI_CMDTIMEOUT) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1282 | cmd->error = -ETIMEDOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) { |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 1284 | cmd->error = -EILSEQ; |
Russell King - ARM Linux | 9047b43 | 2011-01-11 16:35:56 +0000 | [diff] [blame] | 1285 | } else { |
| 1286 | cmd->resp[0] = readl(base + MMCIRESPONSE0); |
| 1287 | cmd->resp[1] = readl(base + MMCIRESPONSE1); |
| 1288 | cmd->resp[2] = readl(base + MMCIRESPONSE2); |
| 1289 | cmd->resp[3] = readl(base + MMCIRESPONSE3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Ulf Hansson | 024629c | 2013-05-13 15:40:56 +0100 | [diff] [blame] | 1292 | if ((!sbc && !cmd->data) || cmd->error) { |
Ulf Hansson | 3b6e3c7 | 2011-12-13 16:58:43 +0100 | [diff] [blame] | 1293 | if (host->data) { |
| 1294 | /* Terminate the DMA transfer */ |
Ludovic Barre | cfccc6a | 2018-10-08 14:08:40 +0200 | [diff] [blame] | 1295 | mmci_dma_error(host); |
Ludovic Barre | 7b2a6d5 | 2018-09-21 11:45:55 +0200 | [diff] [blame] | 1296 | |
Russell King | e47c222 | 2007-01-08 16:42:51 +0000 | [diff] [blame] | 1297 | mmci_stop_data(host); |
Ulf Hansson | e9968c6 | 2019-01-29 15:35:56 +0100 | [diff] [blame] | 1298 | if (host->variant->cmdreg_stop && cmd->error) { |
| 1299 | mmci_stop_command(host); |
| 1300 | return; |
| 1301 | } |
Ulf Hansson | 3b6e3c7 | 2011-12-13 16:58:43 +0100 | [diff] [blame] | 1302 | } |
Ulf Hansson | 024629c | 2013-05-13 15:40:56 +0100 | [diff] [blame] | 1303 | mmci_request_end(host, host->mrq); |
| 1304 | } else if (sbc) { |
| 1305 | mmci_start_command(host, host->mrq->cmd, 0); |
Ludovic Barre | d214154 | 2018-10-08 14:08:48 +0200 | [diff] [blame] | 1306 | } else if (!host->variant->datactrl_first && |
| 1307 | !(cmd->data->flags & MMC_DATA_READ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | mmci_start_data(host, cmd->data); |
| 1309 | } |
| 1310 | } |
| 1311 | |
Srinivas Kandagatla | 9c34b73 | 2014-06-02 10:10:04 +0100 | [diff] [blame] | 1312 | static int mmci_get_rx_fifocnt(struct mmci_host *host, u32 status, int remain) |
| 1313 | { |
| 1314 | return remain - (readl(host->base + MMCIFIFOCNT) << 2); |
| 1315 | } |
| 1316 | |
| 1317 | static int mmci_qcom_get_rx_fifocnt(struct mmci_host *host, u32 status, int r) |
| 1318 | { |
| 1319 | /* |
| 1320 | * on qcom SDCC4 only 8 words are used in each burst so only 8 addresses |
| 1321 | * from the fifo range should be used |
| 1322 | */ |
| 1323 | if (status & MCI_RXFIFOHALFFULL) |
| 1324 | return host->variant->fifohalfsize; |
| 1325 | else if (status & MCI_RXDATAAVLBL) |
| 1326 | return 4; |
| 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int remain) |
| 1332 | { |
| 1333 | void __iomem *base = host->base; |
| 1334 | char *ptr = buffer; |
Srinivas Kandagatla | 9c34b73 | 2014-06-02 10:10:04 +0100 | [diff] [blame] | 1335 | u32 status = readl(host->base + MMCISTATUS); |
Linus Walleij | 26eed9a | 2008-04-26 23:39:44 +0100 | [diff] [blame] | 1336 | int host_remain = host->size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
| 1338 | do { |
Srinivas Kandagatla | 9c34b73 | 2014-06-02 10:10:04 +0100 | [diff] [blame] | 1339 | int count = host->get_rx_fifocnt(host, status, host_remain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
| 1341 | if (count > remain) |
| 1342 | count = remain; |
| 1343 | |
| 1344 | if (count <= 0) |
| 1345 | break; |
| 1346 | |
Ulf Hansson | 393e5e2 | 2011-12-13 17:08:04 +0100 | [diff] [blame] | 1347 | /* |
| 1348 | * SDIO especially may want to send something that is |
| 1349 | * not divisible by 4 (as opposed to card sectors |
| 1350 | * etc). Therefore make sure to always read the last bytes |
| 1351 | * while only doing full 32-bit reads towards the FIFO. |
| 1352 | */ |
| 1353 | if (unlikely(count & 0x3)) { |
| 1354 | if (count < 4) { |
| 1355 | unsigned char buf[4]; |
Davide Ciminaghi | 4b85da0 | 2012-12-10 14:47:21 +0100 | [diff] [blame] | 1356 | ioread32_rep(base + MMCIFIFO, buf, 1); |
Ulf Hansson | 393e5e2 | 2011-12-13 17:08:04 +0100 | [diff] [blame] | 1357 | memcpy(ptr, buf, count); |
| 1358 | } else { |
Davide Ciminaghi | 4b85da0 | 2012-12-10 14:47:21 +0100 | [diff] [blame] | 1359 | ioread32_rep(base + MMCIFIFO, ptr, count >> 2); |
Ulf Hansson | 393e5e2 | 2011-12-13 17:08:04 +0100 | [diff] [blame] | 1360 | count &= ~0x3; |
| 1361 | } |
| 1362 | } else { |
Davide Ciminaghi | 4b85da0 | 2012-12-10 14:47:21 +0100 | [diff] [blame] | 1363 | ioread32_rep(base + MMCIFIFO, ptr, count >> 2); |
Ulf Hansson | 393e5e2 | 2011-12-13 17:08:04 +0100 | [diff] [blame] | 1364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
| 1366 | ptr += count; |
| 1367 | remain -= count; |
Linus Walleij | 26eed9a | 2008-04-26 23:39:44 +0100 | [diff] [blame] | 1368 | host_remain -= count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | if (remain == 0) |
| 1371 | break; |
| 1372 | |
| 1373 | status = readl(base + MMCISTATUS); |
| 1374 | } while (status & MCI_RXDATAAVLBL); |
| 1375 | |
| 1376 | return ptr - buffer; |
| 1377 | } |
| 1378 | |
| 1379 | static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status) |
| 1380 | { |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 1381 | struct variant_data *variant = host->variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | void __iomem *base = host->base; |
| 1383 | char *ptr = buffer; |
| 1384 | |
| 1385 | do { |
| 1386 | unsigned int count, maxcnt; |
| 1387 | |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 1388 | maxcnt = status & MCI_TXFIFOEMPTY ? |
| 1389 | variant->fifosize : variant->fifohalfsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | count = min(remain, maxcnt); |
| 1391 | |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 1392 | /* |
Linus Walleij | 3417780 | 2010-10-19 12:43:58 +0100 | [diff] [blame] | 1393 | * SDIO especially may want to send something that is |
| 1394 | * not divisible by 4 (as opposed to card sectors |
| 1395 | * etc), and the FIFO only accept full 32-bit writes. |
| 1396 | * So compensate by adding +3 on the count, a single |
| 1397 | * byte become a 32bit write, 7 bytes will be two |
| 1398 | * 32bit writes etc. |
| 1399 | */ |
Davide Ciminaghi | 4b85da0 | 2012-12-10 14:47:21 +0100 | [diff] [blame] | 1400 | iowrite32_rep(base + MMCIFIFO, ptr, (count + 3) >> 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | |
| 1402 | ptr += count; |
| 1403 | remain -= count; |
| 1404 | |
| 1405 | if (remain == 0) |
| 1406 | break; |
| 1407 | |
| 1408 | status = readl(base + MMCISTATUS); |
| 1409 | } while (status & MCI_TXFIFOHALFEMPTY); |
| 1410 | |
| 1411 | return ptr - buffer; |
| 1412 | } |
| 1413 | |
| 1414 | /* |
| 1415 | * PIO data transfer IRQ handler. |
| 1416 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1417 | static irqreturn_t mmci_pio_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | { |
| 1419 | struct mmci_host *host = dev_id; |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 1420 | struct sg_mapping_iter *sg_miter = &host->sg_miter; |
Rabin Vincent | 8301bb6 | 2010-08-09 12:57:30 +0100 | [diff] [blame] | 1421 | struct variant_data *variant = host->variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | void __iomem *base = host->base; |
| 1423 | u32 status; |
| 1424 | |
| 1425 | status = readl(base + MMCISTATUS); |
| 1426 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 1427 | dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | |
| 1429 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | unsigned int remain, len; |
| 1431 | char *buffer; |
| 1432 | |
| 1433 | /* |
| 1434 | * For write, we only need to test the half-empty flag |
| 1435 | * here - if the FIFO is completely empty, then by |
| 1436 | * definition it is more than half empty. |
| 1437 | * |
| 1438 | * For read, check for data available. |
| 1439 | */ |
| 1440 | if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL))) |
| 1441 | break; |
| 1442 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 1443 | if (!sg_miter_next(sg_miter)) |
| 1444 | break; |
| 1445 | |
| 1446 | buffer = sg_miter->addr; |
| 1447 | remain = sg_miter->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
| 1449 | len = 0; |
| 1450 | if (status & MCI_RXACTIVE) |
| 1451 | len = mmci_pio_read(host, buffer, remain); |
| 1452 | if (status & MCI_TXACTIVE) |
| 1453 | len = mmci_pio_write(host, buffer, remain, status); |
| 1454 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 1455 | sg_miter->consumed = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | host->size -= len; |
| 1458 | remain -= len; |
| 1459 | |
| 1460 | if (remain) |
| 1461 | break; |
| 1462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | status = readl(base + MMCISTATUS); |
| 1464 | } while (1); |
| 1465 | |
Rabin Vincent | 4ce1d6c | 2010-07-21 12:44:58 +0100 | [diff] [blame] | 1466 | sg_miter_stop(sg_miter); |
| 1467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | /* |
Russell King | c4d877c | 2011-01-27 09:50:13 +0000 | [diff] [blame] | 1469 | * If we have less than the fifo 'half-full' threshold to transfer, |
| 1470 | * trigger a PIO interrupt as soon as any data is available. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | */ |
Russell King | c4d877c | 2011-01-27 09:50:13 +0000 | [diff] [blame] | 1472 | if (status & MCI_RXACTIVE && host->size < variant->fifohalfsize) |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 1473 | mmci_set_mask1(host, MCI_RXDATAAVLBLMASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
| 1475 | /* |
| 1476 | * If we run out of data, disable the data IRQs; this |
| 1477 | * prevents a race where the FIFO becomes empty before |
| 1478 | * the chip itself has disabled the data path, and |
| 1479 | * stops us racing with our data end IRQ. |
| 1480 | */ |
| 1481 | if (host->size == 0) { |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 1482 | mmci_set_mask1(host, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | writel(readl(base + MMCIMASK0) | MCI_DATAENDMASK, base + MMCIMASK0); |
| 1484 | } |
| 1485 | |
| 1486 | return IRQ_HANDLED; |
| 1487 | } |
| 1488 | |
| 1489 | /* |
| 1490 | * Handle completion of command and data transfers. |
| 1491 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1492 | static irqreturn_t mmci_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | { |
| 1494 | struct mmci_host *host = dev_id; |
| 1495 | u32 status; |
| 1496 | int ret = 0; |
| 1497 | |
| 1498 | spin_lock(&host->lock); |
| 1499 | |
| 1500 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | status = readl(host->base + MMCISTATUS); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 1502 | |
| 1503 | if (host->singleirq) { |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 1504 | if (status & host->mask1_reg) |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 1505 | mmci_pio_irq(irq, dev_id); |
| 1506 | |
Ludovic Barre | 59db5e2 | 2018-10-08 14:08:47 +0200 | [diff] [blame] | 1507 | status &= ~host->variant->irq_pio_mask; |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1510 | /* |
Jean-Nicolas Graux | 5cad24d | 2017-02-07 12:12:41 +0100 | [diff] [blame] | 1511 | * We intentionally clear the MCI_ST_CARDBUSY IRQ (if it's |
| 1512 | * enabled) in mmci_cmd_irq() function where ST Micro busy |
| 1513 | * detection variant is handled. Considering the HW seems to be |
| 1514 | * triggering the IRQ on both edges while monitoring DAT0 for |
| 1515 | * busy completion and that same status bit is used to monitor |
| 1516 | * start and end of busy detection, special care must be taken |
| 1517 | * to make sure that both start and end interrupts are always |
| 1518 | * cleared one after the other. |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1519 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | status &= readl(host->base + MMCIMASK0); |
Jean-Nicolas Graux | 5cad24d | 2017-02-07 12:12:41 +0100 | [diff] [blame] | 1521 | if (host->variant->busy_detect) |
| 1522 | writel(status & ~host->variant->busy_detect_mask, |
| 1523 | host->base + MMCICLEAR); |
| 1524 | else |
| 1525 | writel(status, host->base + MMCICLEAR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 1527 | dev_dbg(mmc_dev(host->mmc), "irq0 (data+cmd) %08x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | |
Ulf Hansson | 7878289 | 2014-06-13 13:21:38 +0200 | [diff] [blame] | 1529 | if (host->variant->reversed_irq_handling) { |
| 1530 | mmci_data_irq(host, host->data, status); |
| 1531 | mmci_cmd_irq(host, host->cmd, status); |
| 1532 | } else { |
| 1533 | mmci_cmd_irq(host, host->cmd, status); |
| 1534 | mmci_data_irq(host, host->data, status); |
| 1535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1537 | /* |
Ludovic Barre | 8520ce1 | 2019-04-26 09:46:35 +0200 | [diff] [blame] | 1538 | * Busy detection has been handled by mmci_cmd_irq() above. |
| 1539 | * Clear the status bit to prevent polling in IRQ context. |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1540 | */ |
Ludovic Barre | 8520ce1 | 2019-04-26 09:46:35 +0200 | [diff] [blame] | 1541 | if (host->variant->busy_detect_flag) |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1542 | status &= ~host->variant->busy_detect_flag; |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | ret = 1; |
| 1545 | } while (status); |
| 1546 | |
| 1547 | spin_unlock(&host->lock); |
| 1548 | |
| 1549 | return IRQ_RETVAL(ret); |
| 1550 | } |
| 1551 | |
| 1552 | static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 1553 | { |
| 1554 | struct mmci_host *host = mmc_priv(mmc); |
Linus Walleij | 9e94302 | 2008-10-24 21:17:50 +0100 | [diff] [blame] | 1555 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
| 1557 | WARN_ON(host->mrq != NULL); |
| 1558 | |
Ulf Hansson | 653a761 | 2013-01-21 21:29:34 +0100 | [diff] [blame] | 1559 | mrq->cmd->error = mmci_validate_data(host, mrq->data); |
| 1560 | if (mrq->cmd->error) { |
Pierre Ossman | 255d01a | 2007-07-24 20:38:53 +0200 | [diff] [blame] | 1561 | mmc_request_done(mmc, mrq); |
| 1562 | return; |
| 1563 | } |
| 1564 | |
Linus Walleij | 9e94302 | 2008-10-24 21:17:50 +0100 | [diff] [blame] | 1565 | spin_lock_irqsave(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
| 1567 | host->mrq = mrq; |
| 1568 | |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 1569 | if (mrq->data) |
| 1570 | mmci_get_next_data(host, mrq->data); |
| 1571 | |
Ludovic Barre | d214154 | 2018-10-08 14:08:48 +0200 | [diff] [blame] | 1572 | if (mrq->data && |
| 1573 | (host->variant->datactrl_first || mrq->data->flags & MMC_DATA_READ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | mmci_start_data(host, mrq->data); |
| 1575 | |
Ulf Hansson | 024629c | 2013-05-13 15:40:56 +0100 | [diff] [blame] | 1576 | if (mrq->sbc) |
| 1577 | mmci_start_command(host, mrq->sbc, 0); |
| 1578 | else |
| 1579 | mmci_start_command(host, mrq->cmd, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | |
Linus Walleij | 9e94302 | 2008-10-24 21:17:50 +0100 | [diff] [blame] | 1581 | spin_unlock_irqrestore(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 1585 | { |
| 1586 | struct mmci_host *host = mmc_priv(mmc); |
Ulf Hansson | 7d72a1d | 2011-12-13 16:54:55 +0100 | [diff] [blame] | 1587 | struct variant_data *variant = host->variant; |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 1588 | u32 pwr = 0; |
| 1589 | unsigned long flags; |
Lee Jones | db90f91 | 2013-05-03 12:52:12 +0100 | [diff] [blame] | 1590 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | |
Ulf Hansson | bc52181 | 2011-12-13 16:57:55 +0100 | [diff] [blame] | 1592 | if (host->plat->ios_handler && |
| 1593 | host->plat->ios_handler(mmc_dev(mmc), ios)) |
| 1594 | dev_err(mmc_dev(mmc), "platform ios_handler failed\n"); |
| 1595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | switch (ios->power_mode) { |
| 1597 | case MMC_POWER_OFF: |
Ulf Hansson | 599c1d5 | 2013-01-07 16:22:50 +0100 | [diff] [blame] | 1598 | if (!IS_ERR(mmc->supply.vmmc)) |
| 1599 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); |
Lee Jones | 237fb5e | 2013-01-31 11:27:52 +0000 | [diff] [blame] | 1600 | |
Ulf Hansson | 7c0136e | 2013-05-14 13:53:10 +0100 | [diff] [blame] | 1601 | if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) { |
Lee Jones | 237fb5e | 2013-01-31 11:27:52 +0000 | [diff] [blame] | 1602 | regulator_disable(mmc->supply.vqmmc); |
Ulf Hansson | 7c0136e | 2013-05-14 13:53:10 +0100 | [diff] [blame] | 1603 | host->vqmmc_enabled = false; |
| 1604 | } |
Lee Jones | 237fb5e | 2013-01-31 11:27:52 +0000 | [diff] [blame] | 1605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | break; |
| 1607 | case MMC_POWER_UP: |
Ulf Hansson | 599c1d5 | 2013-01-07 16:22:50 +0100 | [diff] [blame] | 1608 | if (!IS_ERR(mmc->supply.vmmc)) |
| 1609 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd); |
| 1610 | |
Ulf Hansson | 7d72a1d | 2011-12-13 16:54:55 +0100 | [diff] [blame] | 1611 | /* |
| 1612 | * The ST Micro variant doesn't have the PL180s MCI_PWR_UP |
| 1613 | * and instead uses MCI_PWR_ON so apply whatever value is |
| 1614 | * configured in the variant data. |
| 1615 | */ |
| 1616 | pwr |= variant->pwrreg_powerup; |
| 1617 | |
| 1618 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | case MMC_POWER_ON: |
Ulf Hansson | 7c0136e | 2013-05-14 13:53:10 +0100 | [diff] [blame] | 1620 | if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) { |
Lee Jones | db90f91 | 2013-05-03 12:52:12 +0100 | [diff] [blame] | 1621 | ret = regulator_enable(mmc->supply.vqmmc); |
| 1622 | if (ret < 0) |
| 1623 | dev_err(mmc_dev(mmc), |
| 1624 | "failed to enable vqmmc regulator\n"); |
Ulf Hansson | 7c0136e | 2013-05-14 13:53:10 +0100 | [diff] [blame] | 1625 | else |
| 1626 | host->vqmmc_enabled = true; |
Lee Jones | db90f91 | 2013-05-03 12:52:12 +0100 | [diff] [blame] | 1627 | } |
Lee Jones | 237fb5e | 2013-01-31 11:27:52 +0000 | [diff] [blame] | 1628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | pwr |= MCI_PWR_ON; |
| 1630 | break; |
| 1631 | } |
| 1632 | |
Ulf Hansson | 4d1a3a0 | 2011-12-13 16:57:07 +0100 | [diff] [blame] | 1633 | if (variant->signal_direction && ios->power_mode != MMC_POWER_OFF) { |
| 1634 | /* |
| 1635 | * The ST Micro variant has some additional bits |
| 1636 | * indicating signal direction for the signals in |
| 1637 | * the SD/MMC bus and feedback-clock usage. |
| 1638 | */ |
Ulf Hansson | 4593df2 | 2014-03-21 10:13:05 +0100 | [diff] [blame] | 1639 | pwr |= host->pwr_reg_add; |
Ulf Hansson | 4d1a3a0 | 2011-12-13 16:57:07 +0100 | [diff] [blame] | 1640 | |
| 1641 | if (ios->bus_width == MMC_BUS_WIDTH_4) |
| 1642 | pwr &= ~MCI_ST_DATA74DIREN; |
| 1643 | else if (ios->bus_width == MMC_BUS_WIDTH_1) |
| 1644 | pwr &= (~MCI_ST_DATA74DIREN & |
| 1645 | ~MCI_ST_DATA31DIREN & |
| 1646 | ~MCI_ST_DATA2DIREN); |
| 1647 | } |
| 1648 | |
Patrice Chotard | f9bb304 | 2018-01-18 15:34:20 +0100 | [diff] [blame] | 1649 | if (variant->opendrain) { |
| 1650 | if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) |
| 1651 | pwr |= variant->opendrain; |
| 1652 | } else { |
| 1653 | /* |
| 1654 | * If the variant cannot configure the pads by its own, then we |
| 1655 | * expect the pinctrl to be able to do that for us |
| 1656 | */ |
| 1657 | if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) |
| 1658 | pinctrl_select_state(host->pinctrl, host->pins_opendrain); |
| 1659 | else |
| 1660 | pinctrl_select_state(host->pinctrl, host->pins_default); |
| 1661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | |
Ulf Hansson | f4670da | 2013-01-09 17:19:54 +0100 | [diff] [blame] | 1663 | /* |
| 1664 | * If clock = 0 and the variant requires the MMCIPOWER to be used for |
| 1665 | * gating the clock, the MCI_PWR_ON bit is cleared. |
| 1666 | */ |
| 1667 | if (!ios->clock && variant->pwrreg_clkgate) |
| 1668 | pwr &= ~MCI_PWR_ON; |
| 1669 | |
Srinivas Kandagatla | 3f4e6f7 | 2014-06-02 10:09:55 +0100 | [diff] [blame] | 1670 | if (host->variant->explicit_mclk_control && |
| 1671 | ios->clock != host->clock_cache) { |
| 1672 | ret = clk_set_rate(host->clk, ios->clock); |
| 1673 | if (ret < 0) |
| 1674 | dev_err(mmc_dev(host->mmc), |
| 1675 | "Error setting clock rate (%d)\n", ret); |
| 1676 | else |
| 1677 | host->mclk = clk_get_rate(host->clk); |
| 1678 | } |
| 1679 | host->clock_cache = ios->clock; |
| 1680 | |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 1681 | spin_lock_irqsave(&host->lock, flags); |
| 1682 | |
Ludovic Barre | cd3ee8c | 2018-10-08 14:08:42 +0200 | [diff] [blame] | 1683 | if (host->ops && host->ops->set_clkreg) |
| 1684 | host->ops->set_clkreg(host, ios->clock); |
| 1685 | else |
| 1686 | mmci_set_clkreg(host, ios->clock); |
| 1687 | |
| 1688 | if (host->ops && host->ops->set_pwrreg) |
| 1689 | host->ops->set_pwrreg(host, pwr); |
| 1690 | else |
| 1691 | mmci_write_pwrreg(host, pwr); |
| 1692 | |
Ulf Hansson | f829c04 | 2013-09-04 09:01:15 +0100 | [diff] [blame] | 1693 | mmci_reg_delay(host); |
Linus Walleij | a6a6464 | 2009-09-14 12:56:14 +0100 | [diff] [blame] | 1694 | |
| 1695 | spin_unlock_irqrestore(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 1698 | static int mmci_get_cd(struct mmc_host *mmc) |
| 1699 | { |
| 1700 | struct mmci_host *host = mmc_priv(mmc); |
Rabin Vincent | 2971944 | 2010-08-09 12:54:43 +0100 | [diff] [blame] | 1701 | struct mmci_platform_data *plat = host->plat; |
Ulf Hansson | d276209 | 2014-03-17 13:56:19 +0100 | [diff] [blame] | 1702 | unsigned int status = mmc_gpio_get_cd(mmc); |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 1703 | |
Ulf Hansson | d276209 | 2014-03-17 13:56:19 +0100 | [diff] [blame] | 1704 | if (status == -ENOSYS) { |
Rabin Vincent | 4b8caec | 2010-08-09 12:56:40 +0100 | [diff] [blame] | 1705 | if (!plat->status) |
| 1706 | return 1; /* Assume always present */ |
| 1707 | |
Rabin Vincent | 2971944 | 2010-08-09 12:54:43 +0100 | [diff] [blame] | 1708 | status = plat->status(mmc_dev(host->mmc)); |
Ulf Hansson | d276209 | 2014-03-17 13:56:19 +0100 | [diff] [blame] | 1709 | } |
Russell King | 74bc809 | 2010-07-29 15:58:59 +0100 | [diff] [blame] | 1710 | return status; |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 1711 | } |
| 1712 | |
Ulf Hansson | 0f3ed7f | 2013-05-15 20:47:33 +0100 | [diff] [blame] | 1713 | static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios) |
| 1714 | { |
| 1715 | int ret = 0; |
| 1716 | |
| 1717 | if (!IS_ERR(mmc->supply.vqmmc)) { |
| 1718 | |
Ulf Hansson | 0f3ed7f | 2013-05-15 20:47:33 +0100 | [diff] [blame] | 1719 | switch (ios->signal_voltage) { |
| 1720 | case MMC_SIGNAL_VOLTAGE_330: |
| 1721 | ret = regulator_set_voltage(mmc->supply.vqmmc, |
| 1722 | 2700000, 3600000); |
| 1723 | break; |
| 1724 | case MMC_SIGNAL_VOLTAGE_180: |
| 1725 | ret = regulator_set_voltage(mmc->supply.vqmmc, |
| 1726 | 1700000, 1950000); |
| 1727 | break; |
| 1728 | case MMC_SIGNAL_VOLTAGE_120: |
| 1729 | ret = regulator_set_voltage(mmc->supply.vqmmc, |
| 1730 | 1100000, 1300000); |
| 1731 | break; |
| 1732 | } |
| 1733 | |
| 1734 | if (ret) |
| 1735 | dev_warn(mmc_dev(mmc), "Voltage switch failed\n"); |
Ulf Hansson | 0f3ed7f | 2013-05-15 20:47:33 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | return ret; |
| 1739 | } |
| 1740 | |
Ulf Hansson | 0125962 | 2013-05-15 20:53:22 +0100 | [diff] [blame] | 1741 | static struct mmc_host_ops mmci_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | .request = mmci_request, |
Per Forlin | 58c7ccb | 2011-07-01 18:55:24 +0200 | [diff] [blame] | 1743 | .pre_req = mmci_pre_request, |
| 1744 | .post_req = mmci_post_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | .set_ios = mmci_set_ios, |
Ulf Hansson | d276209 | 2014-03-17 13:56:19 +0100 | [diff] [blame] | 1746 | .get_ro = mmc_gpio_get_ro, |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 1747 | .get_cd = mmci_get_cd, |
Ulf Hansson | 0f3ed7f | 2013-05-15 20:47:33 +0100 | [diff] [blame] | 1748 | .start_signal_voltage_switch = mmci_sig_volt_switch, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | }; |
| 1750 | |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1751 | static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc) |
| 1752 | { |
Ulf Hansson | 4593df2 | 2014-03-21 10:13:05 +0100 | [diff] [blame] | 1753 | struct mmci_host *host = mmc_priv(mmc); |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1754 | int ret = mmc_of_parse(mmc); |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1755 | |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1756 | if (ret) |
| 1757 | return ret; |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1758 | |
Ulf Hansson | 4593df2 | 2014-03-21 10:13:05 +0100 | [diff] [blame] | 1759 | if (of_get_property(np, "st,sig-dir-dat0", NULL)) |
| 1760 | host->pwr_reg_add |= MCI_ST_DATA0DIREN; |
| 1761 | if (of_get_property(np, "st,sig-dir-dat2", NULL)) |
| 1762 | host->pwr_reg_add |= MCI_ST_DATA2DIREN; |
| 1763 | if (of_get_property(np, "st,sig-dir-dat31", NULL)) |
| 1764 | host->pwr_reg_add |= MCI_ST_DATA31DIREN; |
| 1765 | if (of_get_property(np, "st,sig-dir-dat74", NULL)) |
| 1766 | host->pwr_reg_add |= MCI_ST_DATA74DIREN; |
| 1767 | if (of_get_property(np, "st,sig-dir-cmd", NULL)) |
| 1768 | host->pwr_reg_add |= MCI_ST_CMDDIREN; |
| 1769 | if (of_get_property(np, "st,sig-pin-fbclk", NULL)) |
| 1770 | host->pwr_reg_add |= MCI_ST_FBCLKEN; |
Ludovic Barre | 46b723d | 2018-10-08 14:08:55 +0200 | [diff] [blame] | 1771 | if (of_get_property(np, "st,sig-dir", NULL)) |
| 1772 | host->pwr_reg_add |= MCI_STM32_DIRPOL; |
| 1773 | if (of_get_property(np, "st,neg-edge", NULL)) |
| 1774 | host->clk_reg_add |= MCI_STM32_CLK_NEGEDGE; |
| 1775 | if (of_get_property(np, "st,use-ckin", NULL)) |
| 1776 | host->clk_reg_add |= MCI_STM32_CLK_SELCKIN; |
Ulf Hansson | 4593df2 | 2014-03-21 10:13:05 +0100 | [diff] [blame] | 1777 | |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1778 | if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL)) |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1779 | mmc->caps |= MMC_CAP_MMC_HIGHSPEED; |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1780 | if (of_get_property(np, "mmc-cap-sd-highspeed", NULL)) |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1781 | mmc->caps |= MMC_CAP_SD_HIGHSPEED; |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1782 | |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1783 | return 0; |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1784 | } |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1785 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 1786 | static int mmci_probe(struct amba_device *dev, |
Russell King | aa25afa | 2011-02-19 15:55:00 +0000 | [diff] [blame] | 1787 | const struct amba_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | { |
Linus Walleij | 6ef297f | 2009-09-22 14:29:36 +0100 | [diff] [blame] | 1789 | struct mmci_platform_data *plat = dev->dev.platform_data; |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1790 | struct device_node *np = dev->dev.of_node; |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 1791 | struct variant_data *variant = id->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | struct mmci_host *host; |
| 1793 | struct mmc_host *mmc; |
| 1794 | int ret; |
| 1795 | |
Lee Jones | 000bc9d | 2012-04-16 10:18:43 +0100 | [diff] [blame] | 1796 | /* Must have platform data or Device Tree. */ |
| 1797 | if (!plat && !np) { |
| 1798 | dev_err(&dev->dev, "No plat data or DT found\n"); |
| 1799 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Lee Jones | b9b5291 | 2012-06-12 10:49:51 +0100 | [diff] [blame] | 1802 | if (!plat) { |
| 1803 | plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL); |
| 1804 | if (!plat) |
| 1805 | return -ENOMEM; |
| 1806 | } |
| 1807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev); |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 1809 | if (!mmc) |
| 1810 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1812 | ret = mmci_of_parse(np, mmc); |
| 1813 | if (ret) |
| 1814 | goto host_free; |
| 1815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | host = mmc_priv(mmc); |
Rabin Vincent | 4ea580f | 2009-04-17 08:44:19 +0530 | [diff] [blame] | 1817 | host->mmc = mmc; |
Russell King | 012b7d3 | 2009-07-09 15:13:56 +0100 | [diff] [blame] | 1818 | |
Patrice Chotard | f9bb304 | 2018-01-18 15:34:20 +0100 | [diff] [blame] | 1819 | /* |
| 1820 | * Some variant (STM32) doesn't have opendrain bit, nevertheless |
| 1821 | * pins can be set accordingly using pinctrl |
| 1822 | */ |
| 1823 | if (!variant->opendrain) { |
| 1824 | host->pinctrl = devm_pinctrl_get(&dev->dev); |
| 1825 | if (IS_ERR(host->pinctrl)) { |
| 1826 | dev_err(&dev->dev, "failed to get pinctrl"); |
Wei Yongjun | 310eb25 | 2018-01-23 02:09:13 +0000 | [diff] [blame] | 1827 | ret = PTR_ERR(host->pinctrl); |
Patrice Chotard | f9bb304 | 2018-01-18 15:34:20 +0100 | [diff] [blame] | 1828 | goto host_free; |
| 1829 | } |
| 1830 | |
| 1831 | host->pins_default = pinctrl_lookup_state(host->pinctrl, |
| 1832 | PINCTRL_STATE_DEFAULT); |
| 1833 | if (IS_ERR(host->pins_default)) { |
| 1834 | dev_err(mmc_dev(mmc), "Can't select default pins\n"); |
Wei Yongjun | 310eb25 | 2018-01-23 02:09:13 +0000 | [diff] [blame] | 1835 | ret = PTR_ERR(host->pins_default); |
Patrice Chotard | f9bb304 | 2018-01-18 15:34:20 +0100 | [diff] [blame] | 1836 | goto host_free; |
| 1837 | } |
| 1838 | |
| 1839 | host->pins_opendrain = pinctrl_lookup_state(host->pinctrl, |
| 1840 | MMCI_PINCTRL_STATE_OPENDRAIN); |
| 1841 | if (IS_ERR(host->pins_opendrain)) { |
| 1842 | dev_err(mmc_dev(mmc), "Can't select opendrain pins\n"); |
Wei Yongjun | 310eb25 | 2018-01-23 02:09:13 +0000 | [diff] [blame] | 1843 | ret = PTR_ERR(host->pins_opendrain); |
Patrice Chotard | f9bb304 | 2018-01-18 15:34:20 +0100 | [diff] [blame] | 1844 | goto host_free; |
| 1845 | } |
| 1846 | } |
| 1847 | |
Russell King | 012b7d3 | 2009-07-09 15:13:56 +0100 | [diff] [blame] | 1848 | host->hw_designer = amba_manf(dev); |
| 1849 | host->hw_revision = amba_rev(dev); |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 1850 | dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer); |
| 1851 | dev_dbg(mmc_dev(mmc), "revision = 0x%01x\n", host->hw_revision); |
Russell King | 012b7d3 | 2009-07-09 15:13:56 +0100 | [diff] [blame] | 1852 | |
Ulf Hansson | 665ba56 | 2013-05-13 15:39:17 +0100 | [diff] [blame] | 1853 | host->clk = devm_clk_get(&dev->dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | if (IS_ERR(host->clk)) { |
| 1855 | ret = PTR_ERR(host->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | goto host_free; |
| 1857 | } |
| 1858 | |
Julia Lawall | ac94093 | 2012-08-26 16:00:59 +0000 | [diff] [blame] | 1859 | ret = clk_prepare_enable(host->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | if (ret) |
Ulf Hansson | 665ba56 | 2013-05-13 15:39:17 +0100 | [diff] [blame] | 1861 | goto host_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Srinivas Kandagatla | 9c34b73 | 2014-06-02 10:10:04 +0100 | [diff] [blame] | 1863 | if (variant->qcom_fifo) |
| 1864 | host->get_rx_fifocnt = mmci_qcom_get_rx_fifocnt; |
| 1865 | else |
| 1866 | host->get_rx_fifocnt = mmci_get_rx_fifocnt; |
| 1867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | host->plat = plat; |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 1869 | host->variant = variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | host->mclk = clk_get_rate(host->clk); |
Linus Walleij | c8df9a5 | 2008-04-29 09:34:07 +0100 | [diff] [blame] | 1871 | /* |
| 1872 | * According to the spec, mclk is max 100 MHz, |
| 1873 | * so we try to adjust the clock down to this, |
| 1874 | * (if possible). |
| 1875 | */ |
Srinivas Kandagatla | dc6500b | 2014-06-02 10:09:47 +0100 | [diff] [blame] | 1876 | if (host->mclk > variant->f_max) { |
| 1877 | ret = clk_set_rate(host->clk, variant->f_max); |
Linus Walleij | c8df9a5 | 2008-04-29 09:34:07 +0100 | [diff] [blame] | 1878 | if (ret < 0) |
| 1879 | goto clk_disable; |
| 1880 | host->mclk = clk_get_rate(host->clk); |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 1881 | dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n", |
| 1882 | host->mclk); |
Linus Walleij | c8df9a5 | 2008-04-29 09:34:07 +0100 | [diff] [blame] | 1883 | } |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 1884 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 1885 | host->phybase = dev->res.start; |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 1886 | host->base = devm_ioremap_resource(&dev->dev, &dev->res); |
| 1887 | if (IS_ERR(host->base)) { |
| 1888 | ret = PTR_ERR(host->base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | goto clk_disable; |
| 1890 | } |
| 1891 | |
Ulf Hansson | ed9067f | 2018-07-13 13:15:23 +0200 | [diff] [blame] | 1892 | if (variant->init) |
| 1893 | variant->init(host); |
| 1894 | |
Linus Walleij | 7f294e4 | 2011-07-08 09:57:15 +0100 | [diff] [blame] | 1895 | /* |
| 1896 | * The ARM and ST versions of the block have slightly different |
| 1897 | * clock divider equations which means that the minimum divider |
| 1898 | * differs too. |
Srinivas Kandagatla | 3f4e6f7 | 2014-06-02 10:09:55 +0100 | [diff] [blame] | 1899 | * on Qualcomm like controllers get the nearest minimum clock to 100Khz |
Linus Walleij | 7f294e4 | 2011-07-08 09:57:15 +0100 | [diff] [blame] | 1900 | */ |
| 1901 | if (variant->st_clkdiv) |
| 1902 | mmc->f_min = DIV_ROUND_UP(host->mclk, 257); |
Ludovic Barre | 00e930d | 2018-10-08 14:08:52 +0200 | [diff] [blame] | 1903 | else if (variant->stm32_clkdiv) |
| 1904 | mmc->f_min = DIV_ROUND_UP(host->mclk, 2046); |
Srinivas Kandagatla | 3f4e6f7 | 2014-06-02 10:09:55 +0100 | [diff] [blame] | 1905 | else if (variant->explicit_mclk_control) |
| 1906 | mmc->f_min = clk_round_rate(host->clk, 100000); |
Linus Walleij | 7f294e4 | 2011-07-08 09:57:15 +0100 | [diff] [blame] | 1907 | else |
| 1908 | mmc->f_min = DIV_ROUND_UP(host->mclk, 512); |
Linus Walleij | 808d97c | 2010-04-08 07:39:38 +0100 | [diff] [blame] | 1909 | /* |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1910 | * If no maximum operating frequency is supplied, fall back to use |
| 1911 | * the module parameter, which has a (low) default value in case it |
| 1912 | * is not specified. Either value must not exceed the clock rate into |
Ulf Hansson | 5080a08 | 2014-03-21 10:46:39 +0100 | [diff] [blame] | 1913 | * the block, of course. |
Linus Walleij | 808d97c | 2010-04-08 07:39:38 +0100 | [diff] [blame] | 1914 | */ |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1915 | if (mmc->f_max) |
Srinivas Kandagatla | 3f4e6f7 | 2014-06-02 10:09:55 +0100 | [diff] [blame] | 1916 | mmc->f_max = variant->explicit_mclk_control ? |
| 1917 | min(variant->f_max, mmc->f_max) : |
| 1918 | min(host->mclk, mmc->f_max); |
Linus Walleij | 808d97c | 2010-04-08 07:39:38 +0100 | [diff] [blame] | 1919 | else |
Srinivas Kandagatla | 3f4e6f7 | 2014-06-02 10:09:55 +0100 | [diff] [blame] | 1920 | mmc->f_max = variant->explicit_mclk_control ? |
| 1921 | fmax : min(host->mclk, fmax); |
| 1922 | |
| 1923 | |
Linus Walleij | 64de028 | 2010-02-19 01:09:10 +0100 | [diff] [blame] | 1924 | dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max); |
| 1925 | |
Ludovic Barre | 15878e5 | 2018-10-08 14:08:51 +0200 | [diff] [blame] | 1926 | host->rst = devm_reset_control_get_optional_exclusive(&dev->dev, NULL); |
| 1927 | if (IS_ERR(host->rst)) { |
| 1928 | ret = PTR_ERR(host->rst); |
| 1929 | goto clk_disable; |
| 1930 | } |
| 1931 | |
Ulf Hansson | 599c1d5 | 2013-01-07 16:22:50 +0100 | [diff] [blame] | 1932 | /* Get regulators and the supported OCR mask */ |
Bjorn Andersson | 9369c97 | 2015-03-24 18:39:49 -0700 | [diff] [blame] | 1933 | ret = mmc_regulator_get_supply(mmc); |
Wolfram Sang | 5100695 | 2017-10-14 21:17:14 +0200 | [diff] [blame] | 1934 | if (ret) |
Bjorn Andersson | 9369c97 | 2015-03-24 18:39:49 -0700 | [diff] [blame] | 1935 | goto clk_disable; |
| 1936 | |
Ulf Hansson | 599c1d5 | 2013-01-07 16:22:50 +0100 | [diff] [blame] | 1937 | if (!mmc->ocr_avail) |
Linus Walleij | 34e84f3 | 2009-09-22 14:41:40 +0100 | [diff] [blame] | 1938 | mmc->ocr_avail = plat->ocr_mask; |
Ulf Hansson | 599c1d5 | 2013-01-07 16:22:50 +0100 | [diff] [blame] | 1939 | else if (plat->ocr_mask) |
| 1940 | dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n"); |
| 1941 | |
Ulf Hansson | 9dd8a8b | 2014-03-19 13:54:18 +0100 | [diff] [blame] | 1942 | /* We support these capabilities. */ |
| 1943 | mmc->caps |= MMC_CAP_CMD23; |
| 1944 | |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1945 | /* |
| 1946 | * Enable busy detection. |
| 1947 | */ |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1948 | if (variant->busy_detect) { |
| 1949 | mmci_ops.card_busy = mmci_card_busy; |
Linus Walleij | 49adc0c | 2016-10-25 11:06:06 +0200 | [diff] [blame] | 1950 | /* |
| 1951 | * Not all variants have a flag to enable busy detection |
| 1952 | * in the DPSM, but if they do, set it here. |
| 1953 | */ |
| 1954 | if (variant->busy_dpsm_flag) |
| 1955 | mmci_write_datactrlreg(host, |
| 1956 | host->variant->busy_dpsm_flag); |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1957 | mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; |
| 1958 | mmc->max_busy_timeout = 0; |
| 1959 | } |
| 1960 | |
Ulf Hansson | e9968c6 | 2019-01-29 15:35:56 +0100 | [diff] [blame] | 1961 | /* Prepare a CMD12 - needed to clear the DPSM on some variants. */ |
| 1962 | host->stop_abort.opcode = MMC_STOP_TRANSMISSION; |
| 1963 | host->stop_abort.arg = 0; |
| 1964 | host->stop_abort.flags = MMC_RSP_R1B | MMC_CMD_AC; |
| 1965 | |
Ulf Hansson | 8d94b54 | 2014-01-13 16:49:31 +0100 | [diff] [blame] | 1966 | mmc->ops = &mmci_ops; |
| 1967 | |
Ulf Hansson | 70be208 | 2013-01-07 15:35:06 +0100 | [diff] [blame] | 1968 | /* We support these PM capabilities. */ |
Ulf Hansson | 78f87df | 2014-03-17 15:53:07 +0100 | [diff] [blame] | 1969 | mmc->pm_caps |= MMC_PM_KEEP_POWER; |
Ulf Hansson | 70be208 | 2013-01-07 15:35:06 +0100 | [diff] [blame] | 1970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | /* |
| 1972 | * We can do SGIO |
| 1973 | */ |
Martin K. Petersen | a36274e | 2010-09-10 01:33:59 -0400 | [diff] [blame] | 1974 | mmc->max_segs = NR_SG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | |
| 1976 | /* |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 1977 | * Since only a certain number of bits are valid in the data length |
| 1978 | * register, we must ensure that we don't exceed 2^num-1 bytes in a |
| 1979 | * single request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | */ |
Rabin Vincent | 08458ef | 2010-07-21 12:55:59 +0100 | [diff] [blame] | 1981 | mmc->max_req_size = (1 << variant->datalength_bits) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | |
| 1983 | /* |
| 1984 | * Set the maximum segment size. Since we aren't doing DMA |
| 1985 | * (yet) we are only limited by the data length register. |
| 1986 | */ |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 1987 | mmc->max_seg_size = mmc->max_req_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 1989 | /* |
| 1990 | * Block size can be up to 2048 bytes, but must be a power of two. |
| 1991 | */ |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 1992 | mmc->max_blk_size = 1 << variant->datactrl_blocksz; |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 1993 | |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 1994 | /* |
Will Deacon | 8f7f6b7e | 2012-02-24 11:25:21 +0000 | [diff] [blame] | 1995 | * Limit the number of blocks transferred so that we don't overflow |
| 1996 | * the maximum request size. |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 1997 | */ |
Ludovic Barre | c931d49 | 2018-10-08 14:08:43 +0200 | [diff] [blame] | 1998 | mmc->max_blk_count = mmc->max_req_size >> variant->datactrl_blocksz; |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 1999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | spin_lock_init(&host->lock); |
| 2001 | |
| 2002 | writel(0, host->base + MMCIMASK0); |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 2003 | |
| 2004 | if (variant->mmcimask1) |
| 2005 | writel(0, host->base + MMCIMASK1); |
| 2006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | writel(0xfff, host->base + MMCICLEAR); |
| 2008 | |
Linus Walleij | ce437aa | 2014-08-27 15:13:54 +0200 | [diff] [blame] | 2009 | /* |
| 2010 | * If: |
| 2011 | * - not using DT but using a descriptor table, or |
| 2012 | * - using a table of descriptors ALONGSIDE DT, or |
| 2013 | * look up these descriptors named "cd" and "wp" right here, fail |
Linus Walleij | 9ef986a | 2018-09-20 16:01:10 -0700 | [diff] [blame] | 2014 | * silently of these do not exist |
Linus Walleij | ce437aa | 2014-08-27 15:13:54 +0200 | [diff] [blame] | 2015 | */ |
| 2016 | if (!np) { |
Linus Walleij | 89168b4 | 2014-10-02 09:08:46 +0200 | [diff] [blame] | 2017 | ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0, NULL); |
Linus Walleij | 9ef986a | 2018-09-20 16:01:10 -0700 | [diff] [blame] | 2018 | if (ret == -EPROBE_DEFER) |
| 2019 | goto clk_disable; |
Linus Walleij | ce437aa | 2014-08-27 15:13:54 +0200 | [diff] [blame] | 2020 | |
Linus Walleij | a2b760a | 2019-02-05 10:30:22 +0100 | [diff] [blame] | 2021 | ret = mmc_gpiod_request_ro(mmc, "wp", 0, 0, NULL); |
Linus Walleij | 9ef986a | 2018-09-20 16:01:10 -0700 | [diff] [blame] | 2022 | if (ret == -EPROBE_DEFER) |
| 2023 | goto clk_disable; |
Russell King | 8900144 | 2009-07-09 15:16:07 +0100 | [diff] [blame] | 2024 | } |
| 2025 | |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 2026 | ret = devm_request_irq(&dev->dev, dev->irq[0], mmci_irq, IRQF_SHARED, |
| 2027 | DRIVER_NAME " (cmd)", host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | if (ret) |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 2029 | goto clk_disable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
Russell King | dfb8518 | 2012-05-03 11:33:15 +0100 | [diff] [blame] | 2031 | if (!dev->irq[1]) |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 2032 | host->singleirq = true; |
| 2033 | else { |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 2034 | ret = devm_request_irq(&dev->dev, dev->irq[1], mmci_pio_irq, |
| 2035 | IRQF_SHARED, DRIVER_NAME " (pio)", host); |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 2036 | if (ret) |
Ulf Hansson | ef28998 | 2014-03-17 13:56:32 +0100 | [diff] [blame] | 2037 | goto clk_disable; |
Linus Walleij | 2686b4b | 2010-10-19 12:39:48 +0100 | [diff] [blame] | 2038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 2040 | writel(MCI_IRQENABLE | variant->start_err, host->base + MMCIMASK0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | |
| 2042 | amba_set_drvdata(dev, mmc); |
| 2043 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 2044 | dev_info(&dev->dev, "%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d (pio)\n", |
| 2045 | mmc_hostname(mmc), amba_part(dev), amba_manf(dev), |
| 2046 | amba_rev(dev), (unsigned long long)dev->res.start, |
| 2047 | dev->irq[0], dev->irq[1]); |
| 2048 | |
| 2049 | mmci_dma_setup(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
Ulf Hansson | 2cd976c | 2011-12-13 17:01:11 +0100 | [diff] [blame] | 2051 | pm_runtime_set_autosuspend_delay(&dev->dev, 50); |
| 2052 | pm_runtime_use_autosuspend(&dev->dev); |
Russell King | 1c3be36 | 2011-08-14 09:17:05 +0100 | [diff] [blame] | 2053 | |
Russell King | 8c11a94 | 2010-12-28 19:40:40 +0000 | [diff] [blame] | 2054 | mmc_add_host(mmc); |
| 2055 | |
Ulf Hansson | 6f2d3c8 | 2014-12-11 14:35:55 +0100 | [diff] [blame] | 2056 | pm_runtime_put(&dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | return 0; |
| 2058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | clk_disable: |
Julia Lawall | ac94093 | 2012-08-26 16:00:59 +0000 | [diff] [blame] | 2060 | clk_disable_unprepare(host->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | host_free: |
| 2062 | mmc_free_host(mmc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | return ret; |
| 2064 | } |
| 2065 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 2066 | static int mmci_remove(struct amba_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | { |
| 2068 | struct mmc_host *mmc = amba_get_drvdata(dev); |
| 2069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | if (mmc) { |
| 2071 | struct mmci_host *host = mmc_priv(mmc); |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 2072 | struct variant_data *variant = host->variant; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | |
Russell King | 1c3be36 | 2011-08-14 09:17:05 +0100 | [diff] [blame] | 2074 | /* |
| 2075 | * Undo pm_runtime_put() in probe. We use the _sync |
| 2076 | * version here so that we can access the primecell. |
| 2077 | */ |
| 2078 | pm_runtime_get_sync(&dev->dev); |
| 2079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | mmc_remove_host(mmc); |
| 2081 | |
| 2082 | writel(0, host->base + MMCIMASK0); |
Patrice Chotard | 6ea9cdf | 2018-01-18 15:34:17 +0100 | [diff] [blame] | 2083 | |
| 2084 | if (variant->mmcimask1) |
| 2085 | writel(0, host->base + MMCIMASK1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | |
| 2087 | writel(0, host->base + MMCICOMMAND); |
| 2088 | writel(0, host->base + MMCIDATACTRL); |
| 2089 | |
Russell King | c8ebae3 | 2011-01-11 19:35:53 +0000 | [diff] [blame] | 2090 | mmci_dma_release(host); |
Julia Lawall | ac94093 | 2012-08-26 16:00:59 +0000 | [diff] [blame] | 2091 | clk_disable_unprepare(host->clk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | mmc_free_host(mmc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | return 0; |
| 2096 | } |
| 2097 | |
Ulf Hansson | 571dce4 | 2014-01-23 00:38:00 +0100 | [diff] [blame] | 2098 | #ifdef CONFIG_PM |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2099 | static void mmci_save(struct mmci_host *host) |
| 2100 | { |
| 2101 | unsigned long flags; |
| 2102 | |
Ulf Hansson | 42dcc89a | 2014-01-23 00:19:38 +0100 | [diff] [blame] | 2103 | spin_lock_irqsave(&host->lock, flags); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2104 | |
Ulf Hansson | 42dcc89a | 2014-01-23 00:19:38 +0100 | [diff] [blame] | 2105 | writel(0, host->base + MMCIMASK0); |
| 2106 | if (host->variant->pwrreg_nopower) { |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2107 | writel(0, host->base + MMCIDATACTRL); |
| 2108 | writel(0, host->base + MMCIPOWER); |
| 2109 | writel(0, host->base + MMCICLOCK); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2110 | } |
Ulf Hansson | 42dcc89a | 2014-01-23 00:19:38 +0100 | [diff] [blame] | 2111 | mmci_reg_delay(host); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2112 | |
Ulf Hansson | 42dcc89a | 2014-01-23 00:19:38 +0100 | [diff] [blame] | 2113 | spin_unlock_irqrestore(&host->lock, flags); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | static void mmci_restore(struct mmci_host *host) |
| 2117 | { |
| 2118 | unsigned long flags; |
| 2119 | |
Ulf Hansson | 42dcc89a | 2014-01-23 00:19:38 +0100 | [diff] [blame] | 2120 | spin_lock_irqsave(&host->lock, flags); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2121 | |
Ulf Hansson | 42dcc89a | 2014-01-23 00:19:38 +0100 | [diff] [blame] | 2122 | if (host->variant->pwrreg_nopower) { |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2123 | writel(host->clk_reg, host->base + MMCICLOCK); |
| 2124 | writel(host->datactrl_reg, host->base + MMCIDATACTRL); |
| 2125 | writel(host->pwr_reg, host->base + MMCIPOWER); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2126 | } |
Ludovic Barre | daf9713 | 2018-10-08 14:08:44 +0200 | [diff] [blame] | 2127 | writel(MCI_IRQENABLE | host->variant->start_err, |
| 2128 | host->base + MMCIMASK0); |
Ulf Hansson | 42dcc89a | 2014-01-23 00:19:38 +0100 | [diff] [blame] | 2129 | mmci_reg_delay(host); |
| 2130 | |
| 2131 | spin_unlock_irqrestore(&host->lock, flags); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2132 | } |
| 2133 | |
Ulf Hansson | 8259293 | 2013-01-09 11:15:26 +0100 | [diff] [blame] | 2134 | static int mmci_runtime_suspend(struct device *dev) |
| 2135 | { |
| 2136 | struct amba_device *adev = to_amba_device(dev); |
| 2137 | struct mmc_host *mmc = amba_get_drvdata(adev); |
| 2138 | |
| 2139 | if (mmc) { |
| 2140 | struct mmci_host *host = mmc_priv(mmc); |
Ulf Hansson | e36bd9c6 | 2013-09-04 09:00:37 +0100 | [diff] [blame] | 2141 | pinctrl_pm_select_sleep_state(dev); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2142 | mmci_save(host); |
Ulf Hansson | 8259293 | 2013-01-09 11:15:26 +0100 | [diff] [blame] | 2143 | clk_disable_unprepare(host->clk); |
| 2144 | } |
| 2145 | |
| 2146 | return 0; |
| 2147 | } |
| 2148 | |
| 2149 | static int mmci_runtime_resume(struct device *dev) |
| 2150 | { |
| 2151 | struct amba_device *adev = to_amba_device(dev); |
| 2152 | struct mmc_host *mmc = amba_get_drvdata(adev); |
| 2153 | |
| 2154 | if (mmc) { |
| 2155 | struct mmci_host *host = mmc_priv(mmc); |
| 2156 | clk_prepare_enable(host->clk); |
Ulf Hansson | 1ff4443 | 2013-09-04 09:05:17 +0100 | [diff] [blame] | 2157 | mmci_restore(host); |
Ulf Hansson | e36bd9c6 | 2013-09-04 09:00:37 +0100 | [diff] [blame] | 2158 | pinctrl_pm_select_default_state(dev); |
Ulf Hansson | 8259293 | 2013-01-09 11:15:26 +0100 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | return 0; |
| 2162 | } |
| 2163 | #endif |
| 2164 | |
Ulf Hansson | 48fa700 | 2011-12-13 16:59:34 +0100 | [diff] [blame] | 2165 | static const struct dev_pm_ops mmci_dev_pm_ops = { |
Ulf Hansson | f3737fa | 2014-01-23 01:11:33 +0100 | [diff] [blame] | 2166 | SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, |
| 2167 | pm_runtime_force_resume) |
Rafael J. Wysocki | 6ed23b8 | 2014-12-04 00:34:11 +0100 | [diff] [blame] | 2168 | SET_RUNTIME_PM_OPS(mmci_runtime_suspend, mmci_runtime_resume, NULL) |
Ulf Hansson | 48fa700 | 2011-12-13 16:59:34 +0100 | [diff] [blame] | 2169 | }; |
| 2170 | |
Arvind Yadav | 88411de | 2017-08-23 22:00:49 +0530 | [diff] [blame] | 2171 | static const struct amba_id mmci_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | { |
| 2173 | .id = 0x00041180, |
Pawel Moll | 768fbc1 | 2011-03-11 17:18:07 +0000 | [diff] [blame] | 2174 | .mask = 0xff0fffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 2175 | .data = &variant_arm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | }, |
| 2177 | { |
Pawel Moll | 768fbc1 | 2011-03-11 17:18:07 +0000 | [diff] [blame] | 2178 | .id = 0x01041180, |
| 2179 | .mask = 0xff0fffff, |
| 2180 | .data = &variant_arm_extended_fifo, |
| 2181 | }, |
| 2182 | { |
Pawel Moll | 3a37298 | 2013-01-24 14:12:45 +0100 | [diff] [blame] | 2183 | .id = 0x02041180, |
| 2184 | .mask = 0xff0fffff, |
| 2185 | .data = &variant_arm_extended_fifo_hwfc, |
| 2186 | }, |
| 2187 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | .id = 0x00041181, |
| 2189 | .mask = 0x000fffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 2190 | .data = &variant_arm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | }, |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 2192 | /* ST Micro variants */ |
| 2193 | { |
| 2194 | .id = 0x00180180, |
| 2195 | .mask = 0x00ffffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 2196 | .data = &variant_u300, |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 2197 | }, |
| 2198 | { |
Linus Walleij | 34fd421 | 2012-04-10 17:43:59 +0100 | [diff] [blame] | 2199 | .id = 0x10180180, |
| 2200 | .mask = 0xf0ffffff, |
| 2201 | .data = &variant_nomadik, |
| 2202 | }, |
| 2203 | { |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 2204 | .id = 0x00280180, |
| 2205 | .mask = 0x00ffffff, |
Linus Walleij | 0bcb7ef | 2016-01-04 02:21:55 +0100 | [diff] [blame] | 2206 | .data = &variant_nomadik, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 2207 | }, |
| 2208 | { |
| 2209 | .id = 0x00480180, |
Philippe Langlais | 1784b15 | 2011-03-25 08:51:52 +0100 | [diff] [blame] | 2210 | .mask = 0xf0ffffff, |
Rabin Vincent | 4956e10 | 2010-07-21 12:54:40 +0100 | [diff] [blame] | 2211 | .data = &variant_ux500, |
Linus Walleij | cc30d60 | 2009-01-04 15:18:54 +0100 | [diff] [blame] | 2212 | }, |
Philippe Langlais | 1784b15 | 2011-03-25 08:51:52 +0100 | [diff] [blame] | 2213 | { |
| 2214 | .id = 0x10480180, |
| 2215 | .mask = 0xf0ffffff, |
| 2216 | .data = &variant_ux500v2, |
| 2217 | }, |
Patrice Chotard | 2a9d6c8 | 2018-01-18 15:34:21 +0100 | [diff] [blame] | 2218 | { |
| 2219 | .id = 0x00880180, |
| 2220 | .mask = 0x00ffffff, |
| 2221 | .data = &variant_stm32, |
| 2222 | }, |
Ludovic Barre | 46b723d | 2018-10-08 14:08:55 +0200 | [diff] [blame] | 2223 | { |
| 2224 | .id = 0x10153180, |
| 2225 | .mask = 0xf0ffffff, |
| 2226 | .data = &variant_stm32_sdmmc, |
| 2227 | }, |
Srinivas Kandagatla | 55b604a | 2014-06-02 10:10:13 +0100 | [diff] [blame] | 2228 | /* Qualcomm variants */ |
| 2229 | { |
| 2230 | .id = 0x00051180, |
| 2231 | .mask = 0x000fffff, |
| 2232 | .data = &variant_qcom, |
| 2233 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | { 0, 0 }, |
| 2235 | }; |
| 2236 | |
Dave Martin | 9f99835 | 2011-10-05 15:15:21 +0100 | [diff] [blame] | 2237 | MODULE_DEVICE_TABLE(amba, mmci_ids); |
| 2238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | static struct amba_driver mmci_driver = { |
| 2240 | .drv = { |
| 2241 | .name = DRIVER_NAME, |
Ulf Hansson | 48fa700 | 2011-12-13 16:59:34 +0100 | [diff] [blame] | 2242 | .pm = &mmci_dev_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | }, |
| 2244 | .probe = mmci_probe, |
Bill Pemberton | 0433c14 | 2012-11-19 13:20:26 -0500 | [diff] [blame] | 2245 | .remove = mmci_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | .id_table = mmci_ids, |
| 2247 | }; |
| 2248 | |
viresh kumar | 9e5ed09 | 2012-03-15 10:40:38 +0100 | [diff] [blame] | 2249 | module_amba_driver(mmci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | module_param(fmax, uint, 0444); |
| 2252 | |
| 2253 | MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver"); |
| 2254 | MODULE_LICENSE("GPL"); |