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

mmc: dw_mmc: Use core to handle absent write protect line

Use the new MMC_CAP2_NO_WRITE_PROTECT to let the core handle the case where
no write protect line is present instead of having custom driver code to
handle it.

dw_mci_of_get_slot_quirks() is slightly refactored to directly modify the
mmc_host capabilities instead of returning a quirk mask.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Lars-Peter Clausen and committed by
Ulf Hansson
eff8f2f5 0293efdd

+17 -45
+17 -36
drivers/mmc/host/dw_mmc.c
··· 1282 1282 int gpio_ro = mmc_gpio_get_ro(mmc); 1283 1283 1284 1284 /* Use platform get_ro function, else try on board write protect */ 1285 - if ((slot->quirks & DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT) || 1286 - (slot->host->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT)) 1287 - read_only = 0; 1288 - else if (!IS_ERR_VALUE(gpio_ro)) 1285 + if (!IS_ERR_VALUE(gpio_ro)) 1289 1286 read_only = gpio_ro; 1290 1287 else 1291 1288 read_only = ··· 2281 2284 } 2282 2285 2283 2286 #ifdef CONFIG_OF 2284 - /* given a slot id, find out the device node representing that slot */ 2285 - static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot) 2287 + /* given a slot, find out the device node representing that slot */ 2288 + static struct device_node *dw_mci_of_find_slot_node(struct dw_mci_slot *slot) 2286 2289 { 2290 + struct device *dev = slot->mmc->parent; 2287 2291 struct device_node *np; 2288 2292 const __be32 *addr; 2289 2293 int len; ··· 2296 2298 addr = of_get_property(np, "reg", &len); 2297 2299 if (!addr || (len < sizeof(int))) 2298 2300 continue; 2299 - if (be32_to_cpup(addr) == slot) 2301 + if (be32_to_cpup(addr) == slot->id) 2300 2302 return np; 2301 2303 } 2302 2304 return NULL; 2303 2305 } 2304 2306 2305 - static struct dw_mci_of_slot_quirks { 2306 - char *quirk; 2307 - int id; 2308 - } of_slot_quirks[] = { 2309 - { 2310 - .quirk = "disable-wp", 2311 - .id = DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT, 2312 - }, 2313 - }; 2314 - 2315 - static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) 2307 + static void dw_mci_slot_of_parse(struct dw_mci_slot *slot) 2316 2308 { 2317 - struct device_node *np = dw_mci_of_find_slot_node(dev, slot); 2318 - int quirks = 0; 2319 - int idx; 2309 + struct device_node *np = dw_mci_of_find_slot_node(slot); 2320 2310 2321 - /* get quirks */ 2322 - for (idx = 0; idx < ARRAY_SIZE(of_slot_quirks); idx++) 2323 - if (of_get_property(np, of_slot_quirks[idx].quirk, NULL)) { 2324 - dev_warn(dev, "Slot quirk %s is deprecated\n", 2325 - of_slot_quirks[idx].quirk); 2326 - quirks |= of_slot_quirks[idx].id; 2327 - } 2311 + if (!np) 2312 + return; 2328 2313 2329 - return quirks; 2314 + if (of_property_read_bool(np, "disable-wp")) { 2315 + slot->mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; 2316 + dev_warn(slot->mmc->parent, 2317 + "Slot quirk 'disable-wp' is deprecated\n"); 2318 + } 2330 2319 } 2331 2320 #else /* CONFIG_OF */ 2332 - static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot) 2321 + static void dw_mci_slot_of_parse(struct dw_mci_slot *slot) 2333 2322 { 2334 - return 0; 2335 2323 } 2336 2324 #endif /* CONFIG_OF */ 2337 2325 ··· 2339 2355 slot->mmc = mmc; 2340 2356 slot->host = host; 2341 2357 host->slot[id] = slot; 2342 - 2343 - slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id); 2344 2358 2345 2359 mmc->ops = &dw_mci_ops; 2346 2360 if (of_property_read_u32_array(host->dev->of_node, ··· 2376 2394 2377 2395 if (host->pdata->caps2) 2378 2396 mmc->caps2 = host->pdata->caps2; 2397 + 2398 + dw_mci_slot_of_parse(slot); 2379 2399 2380 2400 ret = mmc_of_parse(mmc); 2381 2401 if (ret) ··· 2606 2622 { 2607 2623 .quirk = "broken-cd", 2608 2624 .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION, 2609 - }, { 2610 - .quirk = "disable-wp", 2611 - .id = DW_MCI_QUIRK_NO_WRITE_PROTECT, 2612 2625 }, 2613 2626 }; 2614 2627
-3
drivers/mmc/host/dw_mmc.h
··· 227 227 * struct dw_mci_slot - MMC slot state 228 228 * @mmc: The mmc_host representing this slot. 229 229 * @host: The MMC controller this slot is using. 230 - * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX) 231 230 * @ctype: Card type for this slot. 232 231 * @mrq: mmc_request currently being processed or waiting to be 233 232 * processed, or NULL when the slot is idle. ··· 243 244 struct dw_mci_slot { 244 245 struct mmc_host *mmc; 245 246 struct dw_mci *host; 246 - 247 - int quirks; 248 247 249 248 u32 ctype; 250 249
-6
include/linux/mmc/dw_mmc.h
··· 226 226 #define DW_MCI_QUIRK_HIGHSPEED BIT(2) 227 227 /* Unreliable card detection */ 228 228 #define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3) 229 - /* No write protect */ 230 - #define DW_MCI_QUIRK_NO_WRITE_PROTECT BIT(4) 231 - 232 - /* Slot level quirks */ 233 - /* This slot has no write protect */ 234 - #define DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT BIT(0) 235 229 236 230 struct dma_pdata; 237 231