Skip to content

Commit 5f10e84

Browse files
andy-shevtiwai
authored andcommitted
ALSA: atmel: convert AC97c driver to GPIO descriptor API
Convert the driver to use GPIO descriptor API. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent b84e843 commit 5f10e84

File tree

1 file changed

+10
-60
lines changed

1 file changed

+10
-60
lines changed

sound/atmel/ac97c.c

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,22 @@
1212
#include <linux/bitmap.h>
1313
#include <linux/device.h>
1414
#include <linux/atmel_pdc.h>
15+
#include <linux/gpio/consumer.h>
1516
#include <linux/init.h>
1617
#include <linux/interrupt.h>
1718
#include <linux/module.h>
1819
#include <linux/platform_device.h>
1920
#include <linux/mutex.h>
20-
#include <linux/gpio.h>
2121
#include <linux/types.h>
2222
#include <linux/io.h>
2323
#include <linux/of.h>
24-
#include <linux/of_gpio.h>
2524
#include <linux/of_device.h>
2625

2726
#include <sound/core.h>
2827
#include <sound/initval.h>
2928
#include <sound/pcm.h>
3029
#include <sound/pcm_params.h>
3130
#include <sound/ac97_codec.h>
32-
#include <sound/atmel-ac97c.h>
3331
#include <sound/memalloc.h>
3432

3533
#include "ac97c.h"
@@ -56,7 +54,7 @@ struct atmel_ac97c {
5654
void __iomem *regs;
5755
int irq;
5856
int opened;
59-
int reset_pin;
57+
struct gpio_desc *reset_pin;
6058
};
6159

6260
#define get_chip(card) ((struct atmel_ac97c *)(card)->private_data)
@@ -700,57 +698,30 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip)
700698
ac97c_writel(chip, CAMR, 0);
701699
ac97c_writel(chip, COMR, 0);
702700

703-
if (gpio_is_valid(chip->reset_pin)) {
704-
gpio_set_value(chip->reset_pin, 0);
701+
if (!IS_ERR(chip->reset_pin)) {
702+
gpiod_set_value(chip->reset_pin, 0);
705703
/* AC97 v2.2 specifications says minimum 1 us. */
706704
udelay(2);
707-
gpio_set_value(chip->reset_pin, 1);
705+
gpiod_set_value(chip->reset_pin, 1);
708706
} else {
709707
ac97c_writel(chip, MR, AC97C_MR_WRST | AC97C_MR_ENA);
710708
udelay(2);
711709
ac97c_writel(chip, MR, AC97C_MR_ENA);
712710
}
713711
}
714712

715-
#ifdef CONFIG_OF
716713
static const struct of_device_id atmel_ac97c_dt_ids[] = {
717714
{ .compatible = "atmel,at91sam9263-ac97c", },
718715
{ }
719716
};
720717
MODULE_DEVICE_TABLE(of, atmel_ac97c_dt_ids);
721718

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-
748719
static int atmel_ac97c_probe(struct platform_device *pdev)
749720
{
721+
struct device *dev = &pdev->dev;
750722
struct snd_card *card;
751723
struct atmel_ac97c *chip;
752724
struct resource *regs;
753-
struct ac97c_platform_data *pdata;
754725
struct clk *pclk;
755726
static struct snd_ac97_bus_ops ops = {
756727
.write = atmel_ac97c_write,
@@ -765,13 +736,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
765736
return -ENXIO;
766737
}
767738

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-
775739
irq = platform_get_irq(pdev, 0);
776740
if (irq < 0) {
777741
dev_dbg(&pdev->dev, "could not get irq: %d\n", irq);
@@ -819,17 +783,9 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
819783
goto err_ioremap;
820784
}
821785

822-
if (gpio_is_valid(pdata->reset_pin)) {
823-
if (gpio_request(pdata->reset_pin, "reset_pin")) {
824-
dev_dbg(&pdev->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-
}
786+
chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH);
787+
if (IS_ERR(chip->reset_pin))
788+
dev_dbg(dev, "reset pin not available\n");
833789

834790
atmel_ac97c_reset(chip);
835791

@@ -869,9 +825,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
869825
return 0;
870826

871827
err_ac97_bus:
872-
if (gpio_is_valid(chip->reset_pin))
873-
gpio_free(chip->reset_pin);
874-
875828
iounmap(chip->regs);
876829
err_ioremap:
877830
free_irq(irq, chip);
@@ -913,9 +866,6 @@ static int atmel_ac97c_remove(struct platform_device *pdev)
913866
struct snd_card *card = platform_get_drvdata(pdev);
914867
struct atmel_ac97c *chip = get_chip(card);
915868

916-
if (gpio_is_valid(chip->reset_pin))
917-
gpio_free(chip->reset_pin);
918-
919869
ac97c_writel(chip, CAMR, 0);
920870
ac97c_writel(chip, COMR, 0);
921871
ac97c_writel(chip, MR, 0);
@@ -936,7 +886,7 @@ static struct platform_driver atmel_ac97c_driver = {
936886
.driver = {
937887
.name = "atmel_ac97c",
938888
.pm = ATMEL_AC97C_PM_OPS,
939-
.of_match_table = of_match_ptr(atmel_ac97c_dt_ids),
889+
.of_match_table = atmel_ac97c_dt_ids,
940890
},
941891
};
942892
module_platform_driver(atmel_ac97c_driver);

0 commit comments

Comments
 (0)