diff options
| -rw-r--r-- | sound/atmel/ac97c.c | 70 |
1 files changed, 10 insertions, 60 deletions
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c index 24623c790773..31914912c0ba 100644 --- a/sound/atmel/ac97c.c +++ b/sound/atmel/ac97c.c | |||
| @@ -12,16 +12,15 @@ | |||
| 12 | #include <linux/bitmap.h> | 12 | #include <linux/bitmap.h> |
| 13 | #include <linux/device.h> | 13 | #include <linux/device.h> |
| 14 | #include <linux/atmel_pdc.h> | 14 | #include <linux/atmel_pdc.h> |
| 15 | #include <linux/gpio/consumer.h> | ||
| 15 | #include <linux/init.h> | 16 | #include <linux/init.h> |
| 16 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
| 17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
| 18 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
| 19 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
| 20 | #include <linux/gpio.h> | ||
| 21 | #include <linux/types.h> | 21 | #include <linux/types.h> |
| 22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
| 23 | #include <linux/of.h> | 23 | #include <linux/of.h> |
| 24 | #include <linux/of_gpio.h> | ||
| 25 | #include <linux/of_device.h> | 24 | #include <linux/of_device.h> |
| 26 | 25 | ||
| 27 | #include <sound/core.h> | 26 | #include <sound/core.h> |
| @@ -29,7 +28,6 @@ | |||
| 29 | #include <sound/pcm.h> | 28 | #include <sound/pcm.h> |
| 30 | #include <sound/pcm_params.h> | 29 | #include <sound/pcm_params.h> |
| 31 | #include <sound/ac97_codec.h> | 30 | #include <sound/ac97_codec.h> |
| 32 | #include <sound/atmel-ac97c.h> | ||
| 33 | #include <sound/memalloc.h> | 31 | #include <sound/memalloc.h> |
| 34 | 32 | ||
| 35 | #include "ac97c.h" | 33 | #include "ac97c.h" |
| @@ -56,7 +54,7 @@ struct atmel_ac97c { | |||
| 56 | void __iomem *regs; | 54 | void __iomem *regs; |
| 57 | int irq; | 55 | int irq; |
| 58 | int opened; | 56 | int opened; |
| 59 | int reset_pin; | 57 | struct gpio_desc *reset_pin; |
| 60 | }; | 58 | }; |
| 61 | 59 | ||
| 62 | #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data) | 60 | #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data) |
| @@ -700,11 +698,11 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip) | |||
| 700 | ac97c_writel(chip, CAMR, 0); | 698 | ac97c_writel(chip, CAMR, 0); |
| 701 | ac97c_writel(chip, COMR, 0); | 699 | ac97c_writel(chip, COMR, 0); |
| 702 | 700 | ||
| 703 | if (gpio_is_valid(chip->reset_pin)) { | 701 | if (!IS_ERR(chip->reset_pin)) { |
| 704 | gpio_set_value(chip->reset_pin, 0); | 702 | gpiod_set_value(chip->reset_pin, 0); |
| 705 | /* AC97 v2.2 specifications says minimum 1 us. */ | 703 | /* AC97 v2.2 specifications says minimum 1 us. */ |
| 706 | udelay(2); | 704 | udelay(2); |
| 707 | gpio_set_value(chip->reset_pin, 1); | 705 | gpiod_set_value(chip->reset_pin, 1); |
| 708 | } else { | 706 | } else { |
| 709 | ac97c_writel(chip, MR, AC97C_MR_WRST | AC97C_MR_ENA); | 707 | ac97c_writel(chip, MR, AC97C_MR_WRST | AC97C_MR_ENA); |
| 710 | udelay(2); | 708 | udelay(2); |
| @@ -712,45 +710,18 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip) | |||
| 712 | } | 710 | } |
| 713 | } | 711 | } |
| 714 | 712 | ||
| 715 | #ifdef CONFIG_OF | ||
| 716 | static const struct of_device_id atmel_ac97c_dt_ids[] = { | 713 | static const struct of_device_id atmel_ac97c_dt_ids[] = { |
| 717 | { .compatible = "atmel,at91sam9263-ac97c", }, | 714 | { .compatible = "atmel,at91sam9263-ac97c", }, |
| 718 | { } | 715 | { } |
| 719 | }; | 716 | }; |
| 720 | MODULE_DEVICE_TABLE(of, atmel_ac97c_dt_ids); | 717 | MODULE_DEVICE_TABLE(of, atmel_ac97c_dt_ids); |
| 721 | 718 | ||
| 722 | static struct ac97c_platform_data *atmel_ac97c_probe_dt(struct device *dev) | ||
| 723 | { | ||
| 724 | struct ac97c_platform_data *pdata; | ||
| 725 | struct device_node *node = dev->of_node; | ||
| 726 | |||
| 727 | if (!node) { | ||
| 728 | dev_err(dev, "Device does not have associated DT data\n"); | ||
| 729 | return ERR_PTR(-EINVAL); | ||
| 730 | } | ||
| 731 | |||
| 732 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
| 733 | if (!pdata) | ||
| 734 | return ERR_PTR(-ENOMEM); | ||
| 735 | |||
| 736 | pdata->reset_pin = of_get_named_gpio(dev->of_node, "ac97-gpios", 2); | ||
| 737 | |||
| 738 | return pdata; | ||
| 739 | } | ||
| 740 | #else | ||
| 741 | static struct ac97c_platform_data *atmel_ac97c_probe_dt(struct device *dev) | ||
| 742 | { | ||
| 743 | dev_err(dev, "no platform data defined\n"); | ||
| 744 | return ERR_PTR(-ENXIO); | ||
| 745 | } | ||
| 746 | #endif | ||
| 747 | |||
| 748 | static int atmel_ac97c_probe(struct platform_device *pdev) | 719 | static int atmel_ac97c_probe(struct platform_device *pdev) |
| 749 | { | 720 | { |
| 721 | struct device *dev = &pdev->dev; | ||
| 750 | struct snd_card *card; | 722 | struct snd_card *card; |
| 751 | struct atmel_ac97c *chip; | 723 | struct atmel_ac97c *chip; |
| 752 | struct resource *regs; | 724 | struct resource *regs; |
| 753 | struct ac97c_platform_data *pdata; | ||
| 754 | struct clk *pclk; | 725 | struct clk *pclk; |
| 755 | static struct snd_ac97_bus_ops ops = { | 726 | static struct snd_ac97_bus_ops ops = { |
| 756 | .write = atmel_ac97c_write, | 727 | .write = atmel_ac97c_write, |
| @@ -765,13 +736,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev) | |||
| 765 | return -ENXIO; | 736 | return -ENXIO; |
| 766 | } | 737 | } |
| 767 | 738 | ||
| 768 | pdata = dev_get_platdata(&pdev->dev); | ||
| 769 | if (!pdata) { | ||
| 770 | pdata = atmel_ac97c_probe_dt(&pdev->dev); | ||
| 771 | if (IS_ERR(pdata)) | ||
| 772 | return PTR_ERR(pdata); | ||
| 773 | } | ||
| 774 | |||
| 775 | irq = platform_get_irq(pdev, 0); | 739 | irq = platform_get_irq(pdev, 0); |
| 776 | if (irq < 0) { | 740 | if (irq < 0) { |
| 777 | dev_dbg(&pdev->dev, "could not get irq: %d\n", irq); | 741 | dev_dbg(&pdev->dev, "could not get irq: %d\n", irq); |
| @@ -819,17 +783,9 @@ static int atmel_ac97c_probe(struct platform_device *pdev) | |||
| 819 | goto err_ioremap; | 783 | goto err_ioremap; |
| 820 | } | 784 | } |
| 821 | 785 | ||
| 822 | if (gpio_is_valid(pdata->reset_pin)) { | 786 | chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH); |
| 823 | if (gpio_request(pdata->reset_pin, "reset_pin")) { | 787 | if (IS_ERR(chip->reset_pin)) |
| 824 | dev_dbg(&pdev->dev, "reset pin not available\n"); | 788 | dev_dbg(dev, "reset pin not available\n"); |
| 825 | chip->reset_pin = -ENODEV; | ||
| 826 | } else { | ||
| 827 | gpio_direction_output(pdata->reset_pin, 1); | ||
| 828 | chip->reset_pin = pdata->reset_pin; | ||
| 829 | } | ||
| 830 | } else { | ||
| 831 | chip->reset_pin = -EINVAL; | ||
| 832 | } | ||
| 833 | 789 | ||
| 834 | atmel_ac97c_reset(chip); | 790 | atmel_ac97c_reset(chip); |
| 835 | 791 | ||
| @@ -869,9 +825,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev) | |||
| 869 | return 0; | 825 | return 0; |
| 870 | 826 | ||
| 871 | err_ac97_bus: | 827 | err_ac97_bus: |
| 872 | if (gpio_is_valid(chip->reset_pin)) | ||
| 873 | gpio_free(chip->reset_pin); | ||
| 874 | |||
| 875 | iounmap(chip->regs); | 828 | iounmap(chip->regs); |
| 876 | err_ioremap: | 829 | err_ioremap: |
| 877 | free_irq(irq, chip); | 830 | free_irq(irq, chip); |
| @@ -913,9 +866,6 @@ static int atmel_ac97c_remove(struct platform_device *pdev) | |||
| 913 | struct snd_card *card = platform_get_drvdata(pdev); | 866 | struct snd_card *card = platform_get_drvdata(pdev); |
| 914 | struct atmel_ac97c *chip = get_chip(card); | 867 | struct atmel_ac97c *chip = get_chip(card); |
| 915 | 868 | ||
| 916 | if (gpio_is_valid(chip->reset_pin)) | ||
| 917 | gpio_free(chip->reset_pin); | ||
| 918 | |||
| 919 | ac97c_writel(chip, CAMR, 0); | 869 | ac97c_writel(chip, CAMR, 0); |
| 920 | ac97c_writel(chip, COMR, 0); | 870 | ac97c_writel(chip, COMR, 0); |
| 921 | ac97c_writel(chip, MR, 0); | 871 | ac97c_writel(chip, MR, 0); |
| @@ -936,7 +886,7 @@ static struct platform_driver atmel_ac97c_driver = { | |||
| 936 | .driver = { | 886 | .driver = { |
| 937 | .name = "atmel_ac97c", | 887 | .name = "atmel_ac97c", |
| 938 | .pm = ATMEL_AC97C_PM_OPS, | 888 | .pm = ATMEL_AC97C_PM_OPS, |
| 939 | .of_match_table = of_match_ptr(atmel_ac97c_dt_ids), | 889 | .of_match_table = atmel_ac97c_dt_ids, |
| 940 | }, | 890 | }, |
| 941 | }; | 891 | }; |
| 942 | module_platform_driver(atmel_ac97c_driver); | 892 | module_platform_driver(atmel_ac97c_driver); |
