diff options
Diffstat (limited to 'sound/atmel/ac97c.c')
-rw-r--r-- | sound/atmel/ac97c.c | 87 |
1 files changed, 20 insertions, 67 deletions
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c index 9d2c9d9af688..380025887aef 100644 --- a/sound/atmel/ac97c.c +++ b/sound/atmel/ac97c.c @@ -12,16 +12,15 @@ #include <linux/bitmap.h> #include <linux/device.h> #include <linux/atmel_pdc.h> +#include <linux/gpio/consumer.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/mutex.h> -#include <linux/gpio.h> #include <linux/types.h> #include <linux/io.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/of_device.h> #include <sound/core.h> @@ -29,7 +28,6 @@ #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/ac97_codec.h> -#include <sound/atmel-ac97c.h> #include <sound/memalloc.h> #include "ac97c.h" @@ -56,7 +54,7 @@ struct atmel_ac97c { void __iomem *regs; int irq; int opened; - int reset_pin; + struct gpio_desc *reset_pin; }; #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data) @@ -66,7 +64,7 @@ struct atmel_ac97c { #define ac97c_readl(chip, reg) \ __raw_readl((chip)->regs + AC97C_##reg) -static struct snd_pcm_hardware atmel_ac97c_hw = { +static const struct snd_pcm_hardware atmel_ac97c_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED @@ -461,7 +459,7 @@ atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream) return frames; } -static struct snd_pcm_ops atmel_ac97_playback_ops = { +static const struct snd_pcm_ops atmel_ac97_playback_ops = { .open = atmel_ac97c_playback_open, .close = atmel_ac97c_playback_close, .ioctl = snd_pcm_lib_ioctl, @@ -472,7 +470,7 @@ static struct snd_pcm_ops atmel_ac97_playback_ops = { .pointer = atmel_ac97c_playback_pointer, }; -static struct snd_pcm_ops atmel_ac97_capture_ops = { +static const struct snd_pcm_ops atmel_ac97_capture_ops = { .open = atmel_ac97c_capture_open, .close = atmel_ac97c_capture_close, .ioctl = snd_pcm_lib_ioctl, @@ -558,7 +556,7 @@ static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev) return retval; } -static struct ac97_pcm at91_ac97_pcm_defs[] = { +static const struct ac97_pcm at91_ac97_pcm_defs[] = { /* Playback */ { .exclusive = 1, @@ -700,11 +698,11 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip) ac97c_writel(chip, CAMR, 0); ac97c_writel(chip, COMR, 0); - if (gpio_is_valid(chip->reset_pin)) { - gpio_set_value(chip->reset_pin, 0); + if (!IS_ERR(chip->reset_pin)) { + gpiod_set_value(chip->reset_pin, 0); /* AC97 v2.2 specifications says minimum 1 us. */ udelay(2); - gpio_set_value(chip->reset_pin, 1); + gpiod_set_value(chip->reset_pin, 1); } else { ac97c_writel(chip, MR, AC97C_MR_WRST | AC97C_MR_ENA); udelay(2); @@ -712,45 +710,18 @@ static void atmel_ac97c_reset(struct atmel_ac97c *chip) } } -#ifdef CONFIG_OF static const struct of_device_id atmel_ac97c_dt_ids[] = { { .compatible = "atmel,at91sam9263-ac97c", }, { } }; MODULE_DEVICE_TABLE(of, atmel_ac97c_dt_ids); -static struct ac97c_platform_data *atmel_ac97c_probe_dt(struct device *dev) -{ - struct ac97c_platform_data *pdata; - struct device_node *node = dev->of_node; - - if (!node) { - dev_err(dev, "Device does not have associated DT data\n"); - return ERR_PTR(-EINVAL); - } - - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) - return ERR_PTR(-ENOMEM); - - pdata->reset_pin = of_get_named_gpio(dev->of_node, "ac97-gpios", 2); - - return pdata; -} -#else -static struct ac97c_platform_data *atmel_ac97c_probe_dt(struct device *dev) -{ - dev_err(dev, "no platform data defined\n"); - return ERR_PTR(-ENXIO); -} -#endif - static int atmel_ac97c_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct snd_card *card; struct atmel_ac97c *chip; struct resource *regs; - struct ac97c_platform_data *pdata; struct clk *pclk; static struct snd_ac97_bus_ops ops = { .write = atmel_ac97c_write, @@ -765,13 +736,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev) return -ENXIO; } - pdata = dev_get_platdata(&pdev->dev); - if (!pdata) { - pdata = atmel_ac97c_probe_dt(&pdev->dev); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } - irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_dbg(&pdev->dev, "could not get irq: %d\n", irq); @@ -783,7 +747,9 @@ static int atmel_ac97c_probe(struct platform_device *pdev) dev_dbg(&pdev->dev, "no peripheral clock\n"); return PTR_ERR(pclk); } - clk_prepare_enable(pclk); + retval = clk_prepare_enable(pclk); + if (retval) + goto err_prepare_enable; retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, THIS_MODULE, @@ -819,17 +785,9 @@ static int atmel_ac97c_probe(struct platform_device *pdev) goto err_ioremap; } - if (gpio_is_valid(pdata->reset_pin)) { - if (gpio_request(pdata->reset_pin, "reset_pin")) { - dev_dbg(&pdev->dev, "reset pin not available\n"); - chip->reset_pin = -ENODEV; - } else { - gpio_direction_output(pdata->reset_pin, 1); - chip->reset_pin = pdata->reset_pin; - } - } else { - chip->reset_pin = -EINVAL; - } + chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH); + if (IS_ERR(chip->reset_pin)) + dev_dbg(dev, "reset pin not available\n"); atmel_ac97c_reset(chip); @@ -869,9 +827,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev) return 0; err_ac97_bus: - if (gpio_is_valid(chip->reset_pin)) - gpio_free(chip->reset_pin); - iounmap(chip->regs); err_ioremap: free_irq(irq, chip); @@ -879,6 +834,7 @@ err_request_irq: snd_card_free(card); err_snd_card_new: clk_disable_unprepare(pclk); +err_prepare_enable: clk_put(pclk); return retval; } @@ -897,9 +853,9 @@ static int atmel_ac97c_resume(struct device *pdev) { struct snd_card *card = dev_get_drvdata(pdev); struct atmel_ac97c *chip = card->private_data; + int ret = clk_prepare_enable(chip->pclk); - clk_prepare_enable(chip->pclk); - return 0; + return ret; } static SIMPLE_DEV_PM_OPS(atmel_ac97c_pm, atmel_ac97c_suspend, atmel_ac97c_resume); @@ -913,9 +869,6 @@ static int atmel_ac97c_remove(struct platform_device *pdev) struct snd_card *card = platform_get_drvdata(pdev); struct atmel_ac97c *chip = get_chip(card); - if (gpio_is_valid(chip->reset_pin)) - gpio_free(chip->reset_pin); - ac97c_writel(chip, CAMR, 0); ac97c_writel(chip, COMR, 0); ac97c_writel(chip, MR, 0); @@ -936,7 +889,7 @@ static struct platform_driver atmel_ac97c_driver = { .driver = { .name = "atmel_ac97c", .pm = ATMEL_AC97C_PM_OPS, - .of_match_table = of_match_ptr(atmel_ac97c_dt_ids), + .of_match_table = atmel_ac97c_dt_ids, }, }; module_platform_driver(atmel_ac97c_driver); |