diff options
author | Thomas Abraham <thomas.abraham@linaro.org> | 2012-08-23 13:10:09 -0400 |
---|---|---|
committer | Chris Ball <cjb@laptop.org> | 2012-10-03 10:05:20 -0400 |
commit | cd1b00eb24b0b204303211df7ffd1a77a1005824 (patch) | |
tree | 25a53a69d00105217aa7485d42ffb099a9f08151 /drivers/mmc/host/sdhci-s3c.c | |
parent | c3665006eccd7d2326b7dc2c1d5ff2f545dee6c5 (diff) |
mmc: sdhci-s3c: Add device tree support
Add device tree based discovery support for Samsung's sdhci controller.
Cc: Ben Dooks <ben-linux@fluff.org>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Signed-off-by: Thomas Abraham <thomas.abraham@linaro.org>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc/host/sdhci-s3c.c')
-rw-r--r-- | drivers/mmc/host/sdhci-s3c.c | 158 |
1 files changed, 152 insertions, 6 deletions
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c index 00969ba03277..0c77b10d2619 100644 --- a/drivers/mmc/host/sdhci-s3c.c +++ b/drivers/mmc/host/sdhci-s3c.c | |||
@@ -34,6 +34,9 @@ | |||
34 | 34 | ||
35 | #define MAX_BUS_CLK (4) | 35 | #define MAX_BUS_CLK (4) |
36 | 36 | ||
37 | /* Number of gpio's used is max data bus width + command and clock lines */ | ||
38 | #define NUM_GPIOS(x) (x + 2) | ||
39 | |||
37 | /** | 40 | /** |
38 | * struct sdhci_s3c - S3C SDHCI instance | 41 | * struct sdhci_s3c - S3C SDHCI instance |
39 | * @host: The SDHCI host created | 42 | * @host: The SDHCI host created |
@@ -41,6 +44,7 @@ | |||
41 | * @ioarea: The resource created when we claimed the IO area. | 44 | * @ioarea: The resource created when we claimed the IO area. |
42 | * @pdata: The platform data for this controller. | 45 | * @pdata: The platform data for this controller. |
43 | * @cur_clk: The index of the current bus clock. | 46 | * @cur_clk: The index of the current bus clock. |
47 | * @gpios: List of gpio numbers parsed from device tree. | ||
44 | * @clk_io: The clock for the internal bus interface. | 48 | * @clk_io: The clock for the internal bus interface. |
45 | * @clk_bus: The clocks that are available for the SD/MMC bus clock. | 49 | * @clk_bus: The clocks that are available for the SD/MMC bus clock. |
46 | */ | 50 | */ |
@@ -52,6 +56,7 @@ struct sdhci_s3c { | |||
52 | unsigned int cur_clk; | 56 | unsigned int cur_clk; |
53 | int ext_cd_irq; | 57 | int ext_cd_irq; |
54 | int ext_cd_gpio; | 58 | int ext_cd_gpio; |
59 | int *gpios; | ||
55 | 60 | ||
56 | struct clk *clk_io; | 61 | struct clk *clk_io; |
57 | struct clk *clk_bus[MAX_BUS_CLK]; | 62 | struct clk *clk_bus[MAX_BUS_CLK]; |
@@ -422,9 +427,121 @@ static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc) | |||
422 | } | 427 | } |
423 | } | 428 | } |
424 | 429 | ||
430 | #ifdef CONFIG_OF | ||
431 | static int __devinit sdhci_s3c_parse_dt(struct device *dev, | ||
432 | struct sdhci_host *host, struct s3c_sdhci_platdata *pdata) | ||
433 | { | ||
434 | struct device_node *node = dev->of_node; | ||
435 | struct sdhci_s3c *ourhost = to_s3c(host); | ||
436 | u32 max_width; | ||
437 | int gpio, cnt, ret; | ||
438 | |||
439 | /* if the bus-width property is not specified, assume width as 1 */ | ||
440 | if (of_property_read_u32(node, "bus-width", &max_width)) | ||
441 | max_width = 1; | ||
442 | pdata->max_width = max_width; | ||
443 | |||
444 | ourhost->gpios = devm_kzalloc(dev, NUM_GPIOS(pdata->max_width) * | ||
445 | sizeof(int), GFP_KERNEL); | ||
446 | if (!ourhost->gpios) | ||
447 | return -ENOMEM; | ||
448 | |||
449 | /* get the card detection method */ | ||
450 | if (of_get_property(node, "broken-cd", 0)) { | ||
451 | pdata->cd_type = S3C_SDHCI_CD_NONE; | ||
452 | goto setup_bus; | ||
453 | } | ||
454 | |||
455 | if (of_get_property(node, "non-removable", 0)) { | ||
456 | pdata->cd_type = S3C_SDHCI_CD_PERMANENT; | ||
457 | goto setup_bus; | ||
458 | } | ||
459 | |||
460 | gpio = of_get_named_gpio(node, "cd-gpios", 0); | ||
461 | if (gpio_is_valid(gpio)) { | ||
462 | pdata->cd_type = S3C_SDHCI_CD_GPIO; | ||
463 | goto found_cd; | ||
464 | } else if (gpio != -ENOENT) { | ||
465 | dev_err(dev, "invalid card detect gpio specified\n"); | ||
466 | return -EINVAL; | ||
467 | } | ||
468 | |||
469 | gpio = of_get_named_gpio(node, "samsung,cd-pinmux-gpio", 0); | ||
470 | if (gpio_is_valid(gpio)) { | ||
471 | pdata->cd_type = S3C_SDHCI_CD_INTERNAL; | ||
472 | goto found_cd; | ||
473 | } else if (gpio != -ENOENT) { | ||
474 | dev_err(dev, "invalid card detect gpio specified\n"); | ||
475 | return -EINVAL; | ||
476 | } | ||
477 | |||
478 | dev_info(dev, "assuming no card detect line available\n"); | ||
479 | pdata->cd_type = S3C_SDHCI_CD_NONE; | ||
480 | |||
481 | found_cd: | ||
482 | if (pdata->cd_type == S3C_SDHCI_CD_GPIO) { | ||
483 | pdata->ext_cd_gpio = gpio; | ||
484 | ourhost->ext_cd_gpio = -1; | ||
485 | if (of_get_property(node, "cd-inverted", NULL)) | ||
486 | pdata->ext_cd_gpio_invert = 1; | ||
487 | } else if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) { | ||
488 | ret = gpio_request(gpio, "sdhci-cd"); | ||
489 | if (ret) { | ||
490 | dev_err(dev, "card detect gpio request failed\n"); | ||
491 | return -EINVAL; | ||
492 | } | ||
493 | ourhost->ext_cd_gpio = gpio; | ||
494 | } | ||
495 | |||
496 | setup_bus: | ||
497 | /* get the gpios for command, clock and data lines */ | ||
498 | for (cnt = 0; cnt < NUM_GPIOS(pdata->max_width); cnt++) { | ||
499 | gpio = of_get_gpio(node, cnt); | ||
500 | if (!gpio_is_valid(gpio)) { | ||
501 | dev_err(dev, "invalid gpio[%d]\n", cnt); | ||
502 | goto err_free_dt_cd_gpio; | ||
503 | } | ||
504 | ourhost->gpios[cnt] = gpio; | ||
505 | } | ||
506 | |||
507 | for (cnt = 0; cnt < NUM_GPIOS(pdata->max_width); cnt++) { | ||
508 | ret = gpio_request(ourhost->gpios[cnt], "sdhci-gpio"); | ||
509 | if (ret) { | ||
510 | dev_err(dev, "gpio[%d] request failed\n", cnt); | ||
511 | goto err_free_dt_gpios; | ||
512 | } | ||
513 | } | ||
514 | |||
515 | return 0; | ||
516 | |||
517 | err_free_dt_gpios: | ||
518 | while (--cnt >= 0) | ||
519 | gpio_free(ourhost->gpios[cnt]); | ||
520 | err_free_dt_cd_gpio: | ||
521 | if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) | ||
522 | gpio_free(ourhost->ext_cd_gpio); | ||
523 | return -EINVAL; | ||
524 | } | ||
525 | #else | ||
526 | static int __devinit sdhci_s3c_parse_dt(struct device *dev, | ||
527 | struct sdhci_host *host, struct s3c_sdhci_platdata *pdata) | ||
528 | { | ||
529 | return -EINVAL; | ||
530 | } | ||
531 | #endif | ||
532 | |||
533 | static const struct of_device_id sdhci_s3c_dt_match[]; | ||
534 | |||
425 | static inline struct sdhci_s3c_drv_data *sdhci_s3c_get_driver_data( | 535 | static inline struct sdhci_s3c_drv_data *sdhci_s3c_get_driver_data( |
426 | struct platform_device *pdev) | 536 | struct platform_device *pdev) |
427 | { | 537 | { |
538 | #ifdef CONFIG_OF | ||
539 | if (pdev->dev.of_node) { | ||
540 | const struct of_device_id *match; | ||
541 | match = of_match_node(sdhci_s3c_dt_match, pdev->dev.of_node); | ||
542 | return (struct sdhci_s3c_drv_data *)match->data; | ||
543 | } | ||
544 | #endif | ||
428 | return (struct sdhci_s3c_drv_data *) | 545 | return (struct sdhci_s3c_drv_data *) |
429 | platform_get_device_id(pdev)->driver_data; | 546 | platform_get_device_id(pdev)->driver_data; |
430 | } | 547 | } |
@@ -439,7 +556,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
439 | struct resource *res; | 556 | struct resource *res; |
440 | int ret, irq, ptr, clks; | 557 | int ret, irq, ptr, clks; |
441 | 558 | ||
442 | if (!pdev->dev.platform_data) { | 559 | if (!pdev->dev.platform_data && !pdev->dev.of_node) { |
443 | dev_err(dev, "no device data specified\n"); | 560 | dev_err(dev, "no device data specified\n"); |
444 | return -ENOENT; | 561 | return -ENOENT; |
445 | } | 562 | } |
@@ -455,21 +572,28 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
455 | dev_err(dev, "sdhci_alloc_host() failed\n"); | 572 | dev_err(dev, "sdhci_alloc_host() failed\n"); |
456 | return PTR_ERR(host); | 573 | return PTR_ERR(host); |
457 | } | 574 | } |
575 | sc = sdhci_priv(host); | ||
458 | 576 | ||
459 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | 577 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
460 | if (!pdata) { | 578 | if (!pdata) { |
461 | ret = -ENOMEM; | 579 | ret = -ENOMEM; |
462 | goto err_io_clk; | 580 | goto err_pdata; |
581 | } | ||
582 | |||
583 | if (pdev->dev.of_node) { | ||
584 | ret = sdhci_s3c_parse_dt(&pdev->dev, host, pdata); | ||
585 | if (ret) | ||
586 | goto err_pdata; | ||
587 | } else { | ||
588 | memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); | ||
589 | sc->ext_cd_gpio = -1; /* invalid gpio number */ | ||
463 | } | 590 | } |
464 | memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); | ||
465 | 591 | ||
466 | drv_data = sdhci_s3c_get_driver_data(pdev); | 592 | drv_data = sdhci_s3c_get_driver_data(pdev); |
467 | sc = sdhci_priv(host); | ||
468 | 593 | ||
469 | sc->host = host; | 594 | sc->host = host; |
470 | sc->pdev = pdev; | 595 | sc->pdev = pdev; |
471 | sc->pdata = pdata; | 596 | sc->pdata = pdata; |
472 | sc->ext_cd_gpio = -1; /* invalid gpio number */ | ||
473 | 597 | ||
474 | platform_set_drvdata(pdev, host); | 598 | platform_set_drvdata(pdev, host); |
475 | 599 | ||
@@ -633,6 +757,12 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
633 | clk_put(sc->clk_io); | 757 | clk_put(sc->clk_io); |
634 | 758 | ||
635 | err_io_clk: | 759 | err_io_clk: |
760 | for (ptr = 0; ptr < NUM_GPIOS(sc->pdata->max_width); ptr++) | ||
761 | gpio_free(sc->gpios[ptr]); | ||
762 | if (pdata->cd_type == S3C_SDHCI_CD_INTERNAL) | ||
763 | gpio_free(sc->ext_cd_gpio); | ||
764 | |||
765 | err_pdata: | ||
636 | sdhci_free_host(host); | 766 | sdhci_free_host(host); |
637 | 767 | ||
638 | return ret; | 768 | return ret; |
@@ -640,9 +770,9 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev) | |||
640 | 770 | ||
641 | static int __devexit sdhci_s3c_remove(struct platform_device *pdev) | 771 | static int __devexit sdhci_s3c_remove(struct platform_device *pdev) |
642 | { | 772 | { |
643 | struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; | ||
644 | struct sdhci_host *host = platform_get_drvdata(pdev); | 773 | struct sdhci_host *host = platform_get_drvdata(pdev); |
645 | struct sdhci_s3c *sc = sdhci_priv(host); | 774 | struct sdhci_s3c *sc = sdhci_priv(host); |
775 | struct s3c_sdhci_platdata *pdata = sc->pdata; | ||
646 | int ptr; | 776 | int ptr; |
647 | 777 | ||
648 | if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup) | 778 | if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup) |
@@ -667,6 +797,11 @@ static int __devexit sdhci_s3c_remove(struct platform_device *pdev) | |||
667 | clk_disable(sc->clk_io); | 797 | clk_disable(sc->clk_io); |
668 | clk_put(sc->clk_io); | 798 | clk_put(sc->clk_io); |
669 | 799 | ||
800 | if (pdev->dev.of_node) { | ||
801 | for (ptr = 0; ptr < NUM_GPIOS(sc->pdata->max_width); ptr++) | ||
802 | gpio_free(sc->gpios[ptr]); | ||
803 | } | ||
804 | |||
670 | sdhci_free_host(host); | 805 | sdhci_free_host(host); |
671 | platform_set_drvdata(pdev, NULL); | 806 | platform_set_drvdata(pdev, NULL); |
672 | 807 | ||
@@ -739,6 +874,16 @@ static struct platform_device_id sdhci_s3c_driver_ids[] = { | |||
739 | }; | 874 | }; |
740 | MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids); | 875 | MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids); |
741 | 876 | ||
877 | #ifdef CONFIG_OF | ||
878 | static const struct of_device_id sdhci_s3c_dt_match[] = { | ||
879 | { .compatible = "samsung,s3c6410-sdhci", }, | ||
880 | { .compatible = "samsung,exynos4210-sdhci", | ||
881 | .data = (void *)EXYNOS4_SDHCI_DRV_DATA }, | ||
882 | {}, | ||
883 | }; | ||
884 | MODULE_DEVICE_TABLE(of, sdhci_s3c_dt_match); | ||
885 | #endif | ||
886 | |||
742 | static struct platform_driver sdhci_s3c_driver = { | 887 | static struct platform_driver sdhci_s3c_driver = { |
743 | .probe = sdhci_s3c_probe, | 888 | .probe = sdhci_s3c_probe, |
744 | .remove = __devexit_p(sdhci_s3c_remove), | 889 | .remove = __devexit_p(sdhci_s3c_remove), |
@@ -746,6 +891,7 @@ static struct platform_driver sdhci_s3c_driver = { | |||
746 | .driver = { | 891 | .driver = { |
747 | .owner = THIS_MODULE, | 892 | .owner = THIS_MODULE, |
748 | .name = "s3c-sdhci", | 893 | .name = "s3c-sdhci", |
894 | .of_match_table = of_match_ptr(sdhci_s3c_dt_match), | ||
749 | .pm = SDHCI_S3C_PMOPS, | 895 | .pm = SDHCI_S3C_PMOPS, |
750 | }, | 896 | }, |
751 | }; | 897 | }; |