^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Atmel SSC driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2007 Atmel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/atmel-ssc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "../../sound/soc/atmel/atmel_ssc_dai.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Serialize access to ssc_list and user count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static DEFINE_MUTEX(user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static LIST_HEAD(ssc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct ssc_device *ssc_request(unsigned int ssc_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int ssc_valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct ssc_device *ssc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) mutex_lock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) list_for_each_entry(ssc, &ssc_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (ssc->pdev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (of_alias_get_id(ssc->pdev->dev.of_node, "ssc")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) == ssc_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ssc->pdev->id = ssc_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ssc_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) } else if (ssc->pdev->id == ssc_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ssc_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!ssc_valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) mutex_unlock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) pr_err("ssc: ssc%d platform device is missing\n", ssc_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (ssc->user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) mutex_unlock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) dev_dbg(&ssc->pdev->dev, "module busy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return ERR_PTR(-EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ssc->user++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) mutex_unlock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) clk_prepare(ssc->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return ssc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) EXPORT_SYMBOL(ssc_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) void ssc_free(struct ssc_device *ssc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) bool disable_clk = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) mutex_lock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (ssc->user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ssc->user--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) disable_clk = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) dev_dbg(&ssc->pdev->dev, "device already free\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) mutex_unlock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (disable_clk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) clk_unprepare(ssc->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) EXPORT_SYMBOL(ssc_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static struct atmel_ssc_platform_data at91rm9200_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .use_dma = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .has_fslen_ext = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static struct atmel_ssc_platform_data at91sam9rl_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .use_dma = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .has_fslen_ext = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static struct atmel_ssc_platform_data at91sam9g45_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .use_dma = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .has_fslen_ext = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static const struct platform_device_id atmel_ssc_devtypes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .name = "at91rm9200_ssc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .driver_data = (unsigned long) &at91rm9200_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .name = "at91sam9rl_ssc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .driver_data = (unsigned long) &at91sam9rl_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .name = "at91sam9g45_ssc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .driver_data = (unsigned long) &at91sam9g45_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static const struct of_device_id atmel_ssc_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .compatible = "atmel,at91rm9200-ssc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .data = &at91rm9200_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .compatible = "atmel,at91sam9rl-ssc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .data = &at91sam9rl_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .compatible = "atmel,at91sam9g45-ssc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .data = &at91sam9g45_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_DEVICE_TABLE(of, atmel_ssc_dt_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static inline const struct atmel_ssc_platform_data *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) atmel_ssc_get_driver_data(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (pdev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) match = of_match_node(atmel_ssc_dt_ids, pdev->dev.of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (match == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return match->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return (struct atmel_ssc_platform_data *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) platform_get_device_id(pdev)->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #ifdef CONFIG_SND_ATMEL_SOC_SSC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int ssc_sound_dai_probe(struct ssc_device *ssc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct device_node *np = ssc->pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ssc->sound_dai = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!of_property_read_bool(np, "#sound-dai-cells"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) id = of_alias_get_id(np, "ssc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ret = atmel_ssc_set_audio(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ssc->sound_dai = !ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void ssc_sound_dai_remove(struct ssc_device *ssc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (!ssc->sound_dai)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) atmel_ssc_put_audio(of_alias_get_id(ssc->pdev->dev.of_node, "ssc"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static inline int ssc_sound_dai_probe(struct ssc_device *ssc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (of_property_read_bool(ssc->pdev->dev.of_node, "#sound-dai-cells"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static inline void ssc_sound_dai_remove(struct ssc_device *ssc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int ssc_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct resource *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct ssc_device *ssc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) const struct atmel_ssc_platform_data *plat_dat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ssc = devm_kzalloc(&pdev->dev, sizeof(struct ssc_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!ssc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) dev_dbg(&pdev->dev, "out of memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ssc->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) plat_dat = atmel_ssc_get_driver_data(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!plat_dat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ssc->pdata = (struct atmel_ssc_platform_data *)plat_dat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (pdev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ssc->clk_from_rk_pin =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) of_property_read_bool(np, "atmel,clk-from-rk-pin");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ssc->regs = devm_ioremap_resource(&pdev->dev, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (IS_ERR(ssc->regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return PTR_ERR(ssc->regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ssc->phybase = regs->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ssc->clk = devm_clk_get(&pdev->dev, "pclk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (IS_ERR(ssc->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) dev_dbg(&pdev->dev, "no pclk clock defined\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* disable all interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) clk_prepare_enable(ssc->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ssc_writel(ssc->regs, IDR, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ssc_readl(ssc->regs, SR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) clk_disable_unprepare(ssc->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) ssc->irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!ssc->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) dev_dbg(&pdev->dev, "could not get irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) mutex_lock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) list_add_tail(&ssc->list, &ssc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) mutex_unlock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) platform_set_drvdata(pdev, ssc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) dev_info(&pdev->dev, "Atmel SSC device at 0x%p (irq %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ssc->regs, ssc->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (ssc_sound_dai_probe(ssc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) dev_err(&pdev->dev, "failed to auto-setup ssc for audio\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int ssc_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct ssc_device *ssc = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ssc_sound_dai_remove(ssc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) mutex_lock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) list_del(&ssc->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) mutex_unlock(&user_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static struct platform_driver ssc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .name = "ssc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .of_match_table = of_match_ptr(atmel_ssc_dt_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .id_table = atmel_ssc_devtypes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) .probe = ssc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .remove = ssc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) module_platform_driver(ssc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) MODULE_DESCRIPTION("SSC driver for Atmel AVR32 and AT91");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) MODULE_ALIAS("platform:ssc");