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

mmc: davinci: use mmc_of_parse to parse common mmc configuration

Card detect and write protect are currently not working on a DT
boot, and the driver relies on polling to get the state
of the card. The current code depends on platform data callbacks
to register and get the state of the gpios.

mmc core provides a generic way to parse device tree configuration,
which will take care of registering the gpios for us, lets use it
so that we don't need to poll, and parse the same properties.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: David Lechner <david@lechnology.com>

authored by

ahaslam@baylibre.com and committed by
Ulf Hansson
c8301e79 e726e8c9

+53 -62
+53 -62
drivers/mmc/host/davinci_mmc.c
··· 35 35 #include <linux/mmc/mmc.h> 36 36 #include <linux/of.h> 37 37 #include <linux/of_device.h> 38 + #include <linux/mmc/slot-gpio.h> 38 39 39 40 #include <linux/platform_data/mmc-davinci.h> 40 41 ··· 1030 1029 struct platform_device *pdev = to_platform_device(mmc->parent); 1031 1030 struct davinci_mmc_config *config = pdev->dev.platform_data; 1032 1031 1033 - if (!config || !config->get_cd) 1034 - return -ENOSYS; 1035 - return config->get_cd(pdev->id); 1032 + if (config && config->get_cd) 1033 + return config->get_cd(pdev->id); 1034 + 1035 + return mmc_gpio_get_cd(mmc); 1036 1036 } 1037 1037 1038 1038 static int mmc_davinci_get_ro(struct mmc_host *mmc) ··· 1041 1039 struct platform_device *pdev = to_platform_device(mmc->parent); 1042 1040 struct davinci_mmc_config *config = pdev->dev.platform_data; 1043 1041 1044 - if (!config || !config->get_ro) 1045 - return -ENOSYS; 1046 - return config->get_ro(pdev->id); 1042 + if (config && config->get_ro) 1043 + return config->get_ro(pdev->id); 1044 + 1045 + return mmc_gpio_get_ro(mmc); 1047 1046 } 1048 1047 1049 1048 static void mmc_davinci_enable_sdio_irq(struct mmc_host *mmc, int enable) ··· 1162 1159 }; 1163 1160 MODULE_DEVICE_TABLE(of, davinci_mmc_dt_ids); 1164 1161 1165 - static struct davinci_mmc_config 1166 - *mmc_parse_pdata(struct platform_device *pdev) 1162 + static int mmc_davinci_parse_pdata(struct mmc_host *mmc) 1167 1163 { 1168 - struct device_node *np; 1164 + struct platform_device *pdev = to_platform_device(mmc->parent); 1169 1165 struct davinci_mmc_config *pdata = pdev->dev.platform_data; 1170 - const struct of_device_id *match = 1171 - of_match_device(davinci_mmc_dt_ids, &pdev->dev); 1172 - u32 data; 1166 + struct mmc_davinci_host *host; 1173 1167 1174 - np = pdev->dev.of_node; 1175 - if (!np) 1176 - return pdata; 1168 + if (!pdata) 1169 + return -EINVAL; 1177 1170 1178 - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1179 - if (!pdata) { 1180 - dev_err(&pdev->dev, "Failed to allocate memory for struct davinci_mmc_config\n"); 1181 - goto nodata; 1182 - } 1171 + host = mmc_priv(mmc); 1172 + if (!host) 1173 + return -EINVAL; 1183 1174 1184 - if (match) 1185 - pdev->id_entry = match->data; 1175 + if (pdata && pdata->nr_sg) 1176 + host->nr_sg = pdata->nr_sg - 1; 1186 1177 1187 - if (of_property_read_u32(np, "max-frequency", &pdata->max_freq)) 1188 - dev_info(&pdev->dev, "'max-frequency' property not specified, defaulting to 25MHz\n"); 1178 + if (pdata && (pdata->wires == 4 || pdata->wires == 0)) 1179 + mmc->caps |= MMC_CAP_4_BIT_DATA; 1189 1180 1190 - of_property_read_u32(np, "bus-width", &data); 1191 - switch (data) { 1192 - case 1: 1193 - case 4: 1194 - case 8: 1195 - pdata->wires = data; 1196 - break; 1197 - default: 1198 - pdata->wires = 1; 1199 - dev_info(&pdev->dev, "Unsupported buswidth, defaulting to 1 bit\n"); 1200 - } 1201 - nodata: 1202 - return pdata; 1181 + if (pdata && (pdata->wires == 8)) 1182 + mmc->caps |= (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA); 1183 + 1184 + mmc->caps |= MMC_CAP_NEEDS_POLL; 1185 + mmc->f_min = 312500; 1186 + mmc->f_max = 25000000; 1187 + if (pdata && pdata->max_freq) 1188 + mmc->f_max = pdata->max_freq; 1189 + if (pdata && pdata->caps) 1190 + mmc->caps |= pdata->caps; 1191 + 1192 + return 0; 1203 1193 } 1204 1194 1205 1195 static int __init davinci_mmcsd_probe(struct platform_device *pdev) 1206 1196 { 1207 - struct davinci_mmc_config *pdata = NULL; 1197 + const struct of_device_id *match; 1208 1198 struct mmc_davinci_host *host = NULL; 1209 1199 struct mmc_host *mmc = NULL; 1210 1200 struct resource *r, *mem = NULL; 1211 1201 int ret, irq; 1212 1202 size_t mem_size; 1213 1203 const struct platform_device_id *id_entry; 1214 - 1215 - pdata = mmc_parse_pdata(pdev); 1216 - if (pdata == NULL) { 1217 - dev_err(&pdev->dev, "Couldn't get platform data\n"); 1218 - return -ENOENT; 1219 - } 1220 1204 1221 1205 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1222 1206 if (!r) ··· 1243 1253 1244 1254 host->mmc_input_clk = clk_get_rate(host->clk); 1245 1255 1246 - init_mmcsd_host(host); 1247 - 1248 - if (pdata->nr_sg) 1249 - host->nr_sg = pdata->nr_sg - 1; 1256 + match = of_match_device(davinci_mmc_dt_ids, &pdev->dev); 1257 + if (match) { 1258 + pdev->id_entry = match->data; 1259 + ret = mmc_of_parse(mmc); 1260 + if (ret) { 1261 + dev_err(&pdev->dev, 1262 + "could not parse of data: %d\n", ret); 1263 + goto parse_fail; 1264 + } 1265 + } else { 1266 + ret = mmc_davinci_parse_pdata(mmc); 1267 + if (ret) { 1268 + dev_err(&pdev->dev, 1269 + "could not parse platform data: %d\n", ret); 1270 + goto parse_fail; 1271 + } } 1250 1272 1251 1273 if (host->nr_sg > MAX_NR_SG || !host->nr_sg) 1252 1274 host->nr_sg = MAX_NR_SG; 1275 + 1276 + init_mmcsd_host(host); 1253 1277 1254 1278 host->use_dma = use_dma; 1255 1279 host->mmc_irq = irq; ··· 1277 1273 host->use_dma = 0; 1278 1274 } 1279 1275 1280 - /* REVISIT: someday, support IRQ-driven card detection. */ 1281 - mmc->caps |= MMC_CAP_NEEDS_POLL; 1282 1276 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; 1283 - 1284 - if (pdata && (pdata->wires == 4 || pdata->wires == 0)) 1285 - mmc->caps |= MMC_CAP_4_BIT_DATA; 1286 - 1287 - if (pdata && (pdata->wires == 8)) 1288 - mmc->caps |= (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA); 1289 1277 1290 1278 id_entry = platform_get_device_id(pdev); 1291 1279 if (id_entry) 1292 1280 host->version = id_entry->driver_data; 1293 1281 1294 1282 mmc->ops = &mmc_davinci_ops; 1295 - mmc->f_min = 312500; 1296 - mmc->f_max = 25000000; 1297 - if (pdata && pdata->max_freq) 1298 - mmc->f_max = pdata->max_freq; 1299 - if (pdata && pdata->caps) 1300 - mmc->caps |= pdata->caps; 1301 1283 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 1302 1284 1303 1285 /* With no iommu coalescing pages, each phys_seg is a hw_seg. ··· 1344 1354 mmc_davinci_cpufreq_deregister(host); 1345 1355 cpu_freq_fail: 1346 1356 davinci_release_dma_channels(host); 1357 + parse_fail: 1347 1358 dma_probe_defer: 1348 1359 clk_disable_unprepare(host->clk); 1349 1360 clk_prepare_enable_fail: