Changes in 4.9.311 USB: serial: pl2303: add IBM device IDs USB: serial: simple: add Nokia phone driver netdevice: add the case if dev is NULL virtio_console: break out of buf poll on remove ethernet: sun: Free the coherent when failing in probing af_key: add __GFP_ZERO flag for compose_sadb_supported in function pfkey_register block: Add a helper to validate the block size virtio-blk: Use blk_validate_block_size() to validate block size USB: usb-storage: Fix use of bitfields for hardware data in ene_ub6250.c coresight: Fix TRCCONFIGR.QE sysfs interface iio: inkern: apply consumer scale on IIO_VAL_INT cases iio: inkern: make a best effort on offset calculation clk: uniphier: Fix fixed-rate initialization ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE SUNRPC: avoid race between mod_timer() and del_timer_sync() NFSD: prevent underflow in nfssvc_decode_writeargs() can: ems_usb: ems_usb_start_xmit(): fix double dev_kfree_skb() in error path jffs2: fix use-after-free in jffs2_clear_xattr_subsystem jffs2: fix memory leak in jffs2_do_mount_fs jffs2: fix memory leak in jffs2_scan_medium mm/pages_alloc.c: don't create ZONE_MOVABLE beyond the end of a node mempolicy: mbind_range() set_policy() after vma_merge() scsi: libsas: Fix sas_ata_qc_issue() handling of NCQ NON DATA commands Revert "Input: clear BTN_RIGHT/MIDDLE on buttonpads" ALSA: cs4236: fix an incorrect NULL check on list iterator drivers: hamradio: 6pack: fix UAF bug caused by mod_timer() video: fbdev: sm712fb: Fix crash in smtcfb_read() video: fbdev: atari: Atari 2 bpp (STe) palette bugfix ARM: dts: exynos: fix UART3 pins configuration in Exynos5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5420 carl9170: fix missing bit-wise or operator for tx_params thermal: int340x: Increase bitmap size lib/raid6/test: fix multiple definition linking error DEC: Limit PMAX memory probing to R3k systems media: davinci: vpif: fix unbalanced runtime PM get brcmfmac: firmware: Allocate space for default boardrev in nvram brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio PCI: pciehp: Clear cmd_busy bit in polling mode crypto: authenc - Fix sleep in atomic context in decrypt_tail crypto: mxs-dcp - Fix scatterlist processing spi: tegra114: Add missing IRQ check in tegra_spi_probe selftests/x86: Add validity check and allow field splitting hwmon: (pmbus) Add mutex to regulator ops hwmon: (sch56xx-common) Replace WDOG_ACTIVE with WDOG_HW_RUNNING PM: hibernate: fix __setup handler error handling PM: suspend: fix return value of __setup handler crypto: vmx - add missing dependencies crypto: ccp - ccp_dmaengine_unregister release dma channels hwmon: (pmbus) Add Vin unit off handling clocksource: acpi_pm: fix return value of __setup handler sched/debug: Remove mpol_get/put and task_lock/unlock from sched_show_numa perf/core: Fix address filter parser for multiple filters perf/x86/intel/pt: Fix address filter config for 32-bit kernel video: fbdev: smscufx: Fix null-ptr-deref in ufx_usb_probe() video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name() ARM: dts: qcom: ipq4019: fix sleep clock soc: ti: wkup_m3_ipc: Fix IRQ check in wkup_m3_ipc_probe media: usb: go7007: s2250-board: fix leak in probe() ASoC: ti: davinci-i2s: Add check for clk_enable() ALSA: spi: Add check for clk_enable() arm64: dts: ns2: Fix spi-cpol and spi-cpha property arm64: dts: broadcom: Fix sata nodename printk: fix return value of printk.devkmsg __setup handler ASoC: mxs-saif: Handle errors for clk_enable ASoC: atmel_ssc_dai: Handle errors for clk_enable memory: emif: Add check for setup_interrupts memory: emif: check the pointer temp in get_device_details() ALSA: firewire-lib: fix uninitialized flag for AV/C deferred transaction ASoC: atmel: Add missing of_node_put() in at91sam9g20ek_audio_probe ASoC: wm8350: Handle error for wm8350_register_irq ASoC: fsi: Add check for clk_enable video: fbdev: omapfb: Add missing of_node_put() in dvic_probe_of ASoC: dmaengine: do not use a NULL prepare_slave_config() callback ASoC: mxs: Fix error handling in mxs_sgtl5000_probe ASoC: imx-es8328: Fix error return code in imx_es8328_probe() mtd: onenand: Check for error irq drm/edid: Don't clear formats if using deep color ath9k_htc: fix uninit value bugs ray_cs: Check ioremap return value power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init HID: i2c-hid: fix GET/SET_REPORT for unnumbered reports iwlwifi: Fix -EIO error code that is never returned scsi: pm8001: Fix command initialization in pm80XX_send_read_log() scsi: pm8001: Fix command initialization in pm8001_chip_ssp_tm_req() scsi: pm8001: Fix payload initialization in pm80xx_set_thermal_config() scsi: pm8001: Fix abort all task initialization TOMOYO: fix __setup handlers return values ext2: correct max file size computing drm/tegra: Fix reference leak in tegra_dsi_ganged_probe KVM: x86: Fix emulation in writing cr8 KVM: x86/emulator: Defer not-present segment check in __load_segment_descriptor() i2c: xiic: Make bus names unique power: supply: wm8350-power: Handle error for wm8350_register_irq power: supply: wm8350-power: Add missing free in free_charger_irq powerpc/sysdev: fix incorrect use to determine if list is empty mfd: mc13xxx: Add check for mc13xxx_irq_request MIPS: RB532: fix return value of __setup handler USB: storage: ums-realtek: fix error code in rts51x_read_mem() af_netlink: Fix shift out of bounds in group mask calculation i2c: mux: demux-pinctrl: do not deactivate a master that is not active mfd: asic3: Add missing iounmap() on error asic3_mfd_probe mxser: fix xmit_buf leak in activate when LSR == 0xff pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() iio: adc: Add check for devm_request_threaded_irq clk: qcom: clk-rcg2: Update the frac table for pixel clock remoteproc: qcom_wcnss: Add missing of_node_put() in wcnss_alloc_memory_region clk: loongson1: Terminate clk_div_table with sentinel element clk: clps711x: Terminate clk_div_table with sentinel element clk: tegra: tegra124-emc: Fix missing put_device() call in emc_ensure_emc_driver NFS: remove unneeded check in decode_devicenotify_args() pinctrl: mediatek: Fix missing of_node_put() in mtk_pctrl_init pinctrl: nomadik: Add missing of_node_put() in nmk_pinctrl_probe pinctrl/rockchip: Add missing of_node_put() in rockchip_pinctrl_probe tty: hvc: fix return value of __setup handler kgdboc: fix return value of __setup handler kgdbts: fix return value of __setup handler jfs: fix divide error in dbNextAG netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options net: phy: broadcom: Fix brcm_fet_config_init() qlcnic: dcb: default to returning -EOPNOTSUPP net/x25: Fix null-ptr-deref caused by x25_disconnect selinux: use correct type for context length loop: use sysfs_emit() in the sysfs xxx show() Fix incorrect type in assignment of ipv6 port for audit irqchip/nvic: Release nvic_base upon failure ACPICA: Avoid walking the ACPI Namespace if it is not there ACPI/APEI: Limit printable size of BERT table data PM: core: keep irq flags in device_pm_check_callbacks() spi: tegra20: Use of_device_get_match_data() ext4: don't BUG if someone dirty pages without asking ext4 first ntfs: add sanity check on allocation size video: fbdev: nvidiafb: Use strscpy() to prevent buffer overflow video: fbdev: w100fb: Reset global state video: fbdev: cirrusfb: check pixclock to avoid divide by zero video: fbdev: omapfb: acx565akm: replace snprintf with sysfs_emit ARM: dts: qcom: fix gic_irq_domain_translate warnings for msm8960 ARM: dts: bcm2837: Add the missing L1/L2 cache information video: fbdev: omapfb: panel-dsi-cm: Use sysfs_emit() instead of snprintf() video: fbdev: omapfb: panel-tpo-td043mtea1: Use sysfs_emit() instead of snprintf() ASoC: soc-core: skip zero num_dai component in searching dai name media: cx88-mpeg: clear interrupt status register before streaming video ARM: tegra: tamonten: Fix I2C3 pad setting ARM: mmp: Fix failure to remove sram device video: fbdev: sm712fb: Fix crash in smtcfb_write() media: hdpvr: initialize dev->worker at hdpvr_register_videodev mmc: host: Return an error when ->enable_sdio_irq() ops is missing scsi: qla2xxx: Fix incorrect reporting of task management failure KVM: Prevent module exit until all VMs are freed ubifs: Add missing iput if do_tmpfile() failed in rename whiteout ubifs: setflags: Make dirtied_ino_d 8 bytes aligned gfs2: Make sure FITRIM minlen is rounded up to fs block size pinctrl: pinconf-generic: Print arguments for bias-pull-* ACPI: CPPC: Avoid out of bounds access when parsing _CPC data mm/mmap: return 1 from stack_guard_gap __setup() handler mm/memcontrol: return 1 from cgroup.memory __setup() handler ubi: fastmap: Return error code if memory allocation fails in add_aeb() ASoC: topology: Allow TLV control to be either read or write ARM: dts: spear1340: Update serial node properties ARM: dts: spear13xx: Update SPI dma properties openvswitch: Fixed nd target mask field in the flow dump. KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated rtc: wm8350: Handle error for wm8350_register_irq ARM: 9187/1: JIVE: fix return value of __setup handler KVM: x86/svm: Clear reserved bits written to PerfEvtSeln MSRs ath5k: fix OOB in ath5k_eeprom_read_pcal_info_5111 ptp: replace snprintf with sysfs_emit powerpc: dts: t104xrdb: fix phy type for FMAN 4/5 scsi: mvsas: Replace snprintf() with sysfs_emit() scsi: bfa: Replace snprintf() with sysfs_emit() iommu/arm-smmu-v3: fix event handling soft lockup dm ioctl: prevent potential spectre v1 gadget scsi: pm8001: Fix pm8001_mpi_task_abort_resp() scsi: aha152x: Fix aha152x_setup() __setup handler return value bnxt_en: Eliminate unintended link toggle during FW reset MIPS: fix fortify panic when copying asm exception handlers scsi: libfc: Fix use after free in fc_exch_abts_resp() usb: dwc3: omap: fix "unbalanced disables for smps10_out1" on omap5evm xtensa: fix DTC warning unit_address_format Bluetooth: Fix use after free in hci_send_acl init/main.c: return 1 from handled __setup() functions w1: w1_therm: fixes w1_seq for ds28ea00 sensors SUNRPC/call_alloc: async tasks mustn't block waiting for memory serial: samsung_tty: do not unlock port->lock for uart_write_wakeup() virtio_console: eliminate anonymous module_init & module_exit jfs: prevent NULL deref in diFree mm: fix race between MADV_FREE reclaim and blkdev direct IO read scsi: zorro7xx: Fix a resource leak in zorro7xx_remove_one() net: stmmac: Fix unset max_speed difference between DT and non-DT platforms drm/imx: Fix memory leak in imx_pd_connector_get_modes drbd: Fix five use after free bugs in get_initial_state mmmremap.c: avoid pointless invalidate_range_start/end on mremap(old_size=0) mm/mempolicy: fix mpol_new leak in shared_policy_replace x86/pm: Save the MSR validity status at context setup x86/speculation: Restore speculation related MSRs during S3 resume arm64: patch_text: Fixup last cpu should be master tools build: Use $(shell ) instead of `` to get embedded libperl's ccopts dmaengine: Revert "dmaengine: shdma: Fix runtime PM imbalance on error" mm: don't skip swap entry even if zap_details specified arm64: module: remove (NOLOAD) from linker script xfrm: policy: match with both mark and mask on user interfaces veth: Ensure eth header is in skb's linear part net: ethernet: stmmac: fix altr_tse_pcs function when using a fixed-link nfc: nci: add flush_workqueue to prevent uaf cifs: potential buffer overflow in handling symlinks drm/amdkfd: Check for potential null return of kmalloc_array() scsi: ibmvscsis: Increase INITIAL_SRP_LIMIT to 1024 net: micrel: fix KS8851_MLL Kconfig gpu: ipu-v3: Fix dev_dbg frequency output scsi: mvsas: Add PCI ID of RocketRaid 2640 drivers: net: slip: fix NPD bug in sl_tx_timeout() mm, page_alloc: fix build_zonerefs_node() mm: kmemleak: take a full lowmem check in kmemleak_*_phys() ALSA: pcm: Test for "silence" field in struct "pcm_format_data" ARM: davinci: da850-evm: Avoid NULL pointer dereference smp: Fix offline cpu check in flush_smp_call_function_queue() i2c: pasemi: Wait for write xfers to finish gcc-plugins: latent_entropy: use /dev/urandom Linux 4.9.311 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ia8f55c5ae2f0eb71b0893d8271a10dfd3c78b3b8
1147 lines
28 KiB
C
1147 lines
28 KiB
C
/*
|
|
* Driver for AT73C213 16-bit stereo DAC connected to Atmel SSC
|
|
*
|
|
* Copyright (C) 2006-2007 Atmel Norway
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
* the Free Software Foundation.
|
|
*/
|
|
|
|
/*#define DEBUG*/
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/err.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/device.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/io.h>
|
|
|
|
#include <sound/initval.h>
|
|
#include <sound/control.h>
|
|
#include <sound/core.h>
|
|
#include <sound/pcm.h>
|
|
|
|
#include <linux/atmel-ssc.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
#include <linux/spi/at73c213.h>
|
|
|
|
#include "at73c213.h"
|
|
|
|
#define BITRATE_MIN 8000 /* Hardware limit? */
|
|
#define BITRATE_TARGET CONFIG_SND_AT73C213_TARGET_BITRATE
|
|
#define BITRATE_MAX 50000 /* Hardware limit. */
|
|
|
|
/* Initial (hardware reset) AT73C213 register values. */
|
|
static u8 snd_at73c213_original_image[18] =
|
|
{
|
|
0x00, /* 00 - CTRL */
|
|
0x05, /* 01 - LLIG */
|
|
0x05, /* 02 - RLIG */
|
|
0x08, /* 03 - LPMG */
|
|
0x08, /* 04 - RPMG */
|
|
0x00, /* 05 - LLOG */
|
|
0x00, /* 06 - RLOG */
|
|
0x22, /* 07 - OLC */
|
|
0x09, /* 08 - MC */
|
|
0x00, /* 09 - CSFC */
|
|
0x00, /* 0A - MISC */
|
|
0x00, /* 0B - */
|
|
0x00, /* 0C - PRECH */
|
|
0x05, /* 0D - AUXG */
|
|
0x00, /* 0E - */
|
|
0x00, /* 0F - */
|
|
0x00, /* 10 - RST */
|
|
0x00, /* 11 - PA_CTRL */
|
|
};
|
|
|
|
struct snd_at73c213 {
|
|
struct snd_card *card;
|
|
struct snd_pcm *pcm;
|
|
struct snd_pcm_substream *substream;
|
|
struct at73c213_board_info *board;
|
|
int irq;
|
|
int period;
|
|
unsigned long bitrate;
|
|
struct ssc_device *ssc;
|
|
struct spi_device *spi;
|
|
u8 spi_wbuffer[2];
|
|
u8 spi_rbuffer[2];
|
|
/* Image of the SPI registers in AT73C213. */
|
|
u8 reg_image[18];
|
|
/* Protect SSC registers against concurrent access. */
|
|
spinlock_t lock;
|
|
/* Protect mixer registers against concurrent access. */
|
|
struct mutex mixer_lock;
|
|
};
|
|
|
|
#define get_chip(card) ((struct snd_at73c213 *)card->private_data)
|
|
|
|
static int
|
|
snd_at73c213_write_reg(struct snd_at73c213 *chip, u8 reg, u8 val)
|
|
{
|
|
struct spi_message msg;
|
|
struct spi_transfer msg_xfer = {
|
|
.len = 2,
|
|
.cs_change = 0,
|
|
};
|
|
int retval;
|
|
|
|
spi_message_init(&msg);
|
|
|
|
chip->spi_wbuffer[0] = reg;
|
|
chip->spi_wbuffer[1] = val;
|
|
|
|
msg_xfer.tx_buf = chip->spi_wbuffer;
|
|
msg_xfer.rx_buf = chip->spi_rbuffer;
|
|
spi_message_add_tail(&msg_xfer, &msg);
|
|
|
|
retval = spi_sync(chip->spi, &msg);
|
|
|
|
if (!retval)
|
|
chip->reg_image[reg] = val;
|
|
|
|
return retval;
|
|
}
|
|
|
|
static struct snd_pcm_hardware snd_at73c213_playback_hw = {
|
|
.info = SNDRV_PCM_INFO_INTERLEAVED |
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER,
|
|
.formats = SNDRV_PCM_FMTBIT_S16_BE,
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
.rate_min = 8000, /* Replaced by chip->bitrate later. */
|
|
.rate_max = 50000, /* Replaced by chip->bitrate later. */
|
|
.channels_min = 1,
|
|
.channels_max = 2,
|
|
.buffer_bytes_max = 64 * 1024 - 1,
|
|
.period_bytes_min = 512,
|
|
.period_bytes_max = 64 * 1024 - 1,
|
|
.periods_min = 4,
|
|
.periods_max = 1024,
|
|
};
|
|
|
|
/*
|
|
* Calculate and set bitrate and divisions.
|
|
*/
|
|
static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
|
|
{
|
|
unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
|
|
unsigned long dac_rate_new, ssc_div;
|
|
int status;
|
|
unsigned long ssc_div_max, ssc_div_min;
|
|
int max_tries;
|
|
|
|
/*
|
|
* We connect two clocks here, picking divisors so the I2S clocks
|
|
* out data at the same rate the DAC clocks it in ... and as close
|
|
* as practical to the desired target rate.
|
|
*
|
|
* The DAC master clock (MCLK) is programmable, and is either 256
|
|
* or (not here) 384 times the I2S output clock (BCLK).
|
|
*/
|
|
|
|
/* SSC clock / (bitrate * stereo * 16-bit). */
|
|
ssc_div = ssc_rate / (BITRATE_TARGET * 2 * 16);
|
|
ssc_div_min = ssc_rate / (BITRATE_MAX * 2 * 16);
|
|
ssc_div_max = ssc_rate / (BITRATE_MIN * 2 * 16);
|
|
max_tries = (ssc_div_max - ssc_div_min) / 2;
|
|
|
|
if (max_tries < 1)
|
|
max_tries = 1;
|
|
|
|
/* ssc_div must be even. */
|
|
ssc_div = (ssc_div + 1) & ~1UL;
|
|
|
|
if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN) {
|
|
ssc_div -= 2;
|
|
if ((ssc_rate / (ssc_div * 2 * 16)) > BITRATE_MAX)
|
|
return -ENXIO;
|
|
}
|
|
|
|
/* Search for a possible bitrate. */
|
|
do {
|
|
/* SSC clock / (ssc divider * 16-bit * stereo). */
|
|
if ((ssc_rate / (ssc_div * 2 * 16)) < BITRATE_MIN)
|
|
return -ENXIO;
|
|
|
|
/* 256 / (2 * 16) = 8 */
|
|
dac_rate_new = 8 * (ssc_rate / ssc_div);
|
|
|
|
status = clk_round_rate(chip->board->dac_clk, dac_rate_new);
|
|
if (status <= 0)
|
|
return status;
|
|
|
|
/* Ignore difference smaller than 256 Hz. */
|
|
if ((status/256) == (dac_rate_new/256))
|
|
goto set_rate;
|
|
|
|
ssc_div += 2;
|
|
} while (--max_tries);
|
|
|
|
/* Not able to find a valid bitrate. */
|
|
return -ENXIO;
|
|
|
|
set_rate:
|
|
status = clk_set_rate(chip->board->dac_clk, status);
|
|
if (status < 0)
|
|
return status;
|
|
|
|
/* Set divider in SSC device. */
|
|
ssc_writel(chip->ssc->regs, CMR, ssc_div/2);
|
|
|
|
/* SSC clock / (ssc divider * 16-bit * stereo). */
|
|
chip->bitrate = ssc_rate / (ssc_div * 16 * 2);
|
|
|
|
dev_info(&chip->spi->dev,
|
|
"at73c213: supported bitrate is %lu (%lu divider)\n",
|
|
chip->bitrate, ssc_div);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
int err;
|
|
|
|
/* ensure buffer_size is a multiple of period_size */
|
|
err = snd_pcm_hw_constraint_integer(runtime,
|
|
SNDRV_PCM_HW_PARAM_PERIODS);
|
|
if (err < 0)
|
|
return err;
|
|
snd_at73c213_playback_hw.rate_min = chip->bitrate;
|
|
snd_at73c213_playback_hw.rate_max = chip->bitrate;
|
|
runtime->hw = snd_at73c213_playback_hw;
|
|
chip->substream = substream;
|
|
|
|
err = clk_enable(chip->ssc->clk);
|
|
if (err)
|
|
return err;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_pcm_close(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
|
|
chip->substream = NULL;
|
|
clk_disable(chip->ssc->clk);
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream,
|
|
struct snd_pcm_hw_params *hw_params)
|
|
{
|
|
struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
|
|
int channels = params_channels(hw_params);
|
|
int val;
|
|
|
|
val = ssc_readl(chip->ssc->regs, TFMR);
|
|
val = SSC_BFINS(TFMR_DATNB, channels - 1, val);
|
|
ssc_writel(chip->ssc->regs, TFMR, val);
|
|
|
|
return snd_pcm_lib_malloc_pages(substream,
|
|
params_buffer_bytes(hw_params));
|
|
}
|
|
|
|
static int snd_at73c213_pcm_hw_free(struct snd_pcm_substream *substream)
|
|
{
|
|
return snd_pcm_lib_free_pages(substream);
|
|
}
|
|
|
|
static int snd_at73c213_pcm_prepare(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
int block_size;
|
|
|
|
block_size = frames_to_bytes(runtime, runtime->period_size);
|
|
|
|
chip->period = 0;
|
|
|
|
ssc_writel(chip->ssc->regs, PDC_TPR,
|
|
(long)runtime->dma_addr);
|
|
ssc_writel(chip->ssc->regs, PDC_TCR,
|
|
runtime->period_size * runtime->channels);
|
|
ssc_writel(chip->ssc->regs, PDC_TNPR,
|
|
(long)runtime->dma_addr + block_size);
|
|
ssc_writel(chip->ssc->regs, PDC_TNCR,
|
|
runtime->period_size * runtime->channels);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_pcm_trigger(struct snd_pcm_substream *substream,
|
|
int cmd)
|
|
{
|
|
struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
|
|
int retval = 0;
|
|
|
|
spin_lock(&chip->lock);
|
|
|
|
switch (cmd) {
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
ssc_writel(chip->ssc->regs, IER, SSC_BIT(IER_ENDTX));
|
|
ssc_writel(chip->ssc->regs, PDC_PTCR, SSC_BIT(PDC_PTCR_TXTEN));
|
|
break;
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
ssc_writel(chip->ssc->regs, PDC_PTCR, SSC_BIT(PDC_PTCR_TXTDIS));
|
|
ssc_writel(chip->ssc->regs, IDR, SSC_BIT(IDR_ENDTX));
|
|
break;
|
|
default:
|
|
dev_dbg(&chip->spi->dev, "spurious command %x\n", cmd);
|
|
retval = -EINVAL;
|
|
break;
|
|
}
|
|
|
|
spin_unlock(&chip->lock);
|
|
|
|
return retval;
|
|
}
|
|
|
|
static snd_pcm_uframes_t
|
|
snd_at73c213_pcm_pointer(struct snd_pcm_substream *substream)
|
|
{
|
|
struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
snd_pcm_uframes_t pos;
|
|
unsigned long bytes;
|
|
|
|
bytes = ssc_readl(chip->ssc->regs, PDC_TPR)
|
|
- (unsigned long)runtime->dma_addr;
|
|
|
|
pos = bytes_to_frames(runtime, bytes);
|
|
if (pos >= runtime->buffer_size)
|
|
pos -= runtime->buffer_size;
|
|
|
|
return pos;
|
|
}
|
|
|
|
static struct snd_pcm_ops at73c213_playback_ops = {
|
|
.open = snd_at73c213_pcm_open,
|
|
.close = snd_at73c213_pcm_close,
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
.hw_params = snd_at73c213_pcm_hw_params,
|
|
.hw_free = snd_at73c213_pcm_hw_free,
|
|
.prepare = snd_at73c213_pcm_prepare,
|
|
.trigger = snd_at73c213_pcm_trigger,
|
|
.pointer = snd_at73c213_pcm_pointer,
|
|
};
|
|
|
|
static int snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
|
|
{
|
|
struct snd_pcm *pcm;
|
|
int retval;
|
|
|
|
retval = snd_pcm_new(chip->card, chip->card->shortname,
|
|
device, 1, 0, &pcm);
|
|
if (retval < 0)
|
|
goto out;
|
|
|
|
pcm->private_data = chip;
|
|
pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER;
|
|
strcpy(pcm->name, "at73c213");
|
|
chip->pcm = pcm;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &at73c213_playback_ops);
|
|
|
|
retval = snd_pcm_lib_preallocate_pages_for_all(chip->pcm,
|
|
SNDRV_DMA_TYPE_DEV, &chip->ssc->pdev->dev,
|
|
64 * 1024, 64 * 1024);
|
|
out:
|
|
return retval;
|
|
}
|
|
|
|
static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
|
|
{
|
|
struct snd_at73c213 *chip = dev_id;
|
|
struct snd_pcm_runtime *runtime = chip->substream->runtime;
|
|
u32 status;
|
|
int offset;
|
|
int block_size;
|
|
int next_period;
|
|
int retval = IRQ_NONE;
|
|
|
|
spin_lock(&chip->lock);
|
|
|
|
block_size = frames_to_bytes(runtime, runtime->period_size);
|
|
status = ssc_readl(chip->ssc->regs, IMR);
|
|
|
|
if (status & SSC_BIT(IMR_ENDTX)) {
|
|
chip->period++;
|
|
if (chip->period == runtime->periods)
|
|
chip->period = 0;
|
|
next_period = chip->period + 1;
|
|
if (next_period == runtime->periods)
|
|
next_period = 0;
|
|
|
|
offset = block_size * next_period;
|
|
|
|
ssc_writel(chip->ssc->regs, PDC_TNPR,
|
|
(long)runtime->dma_addr + offset);
|
|
ssc_writel(chip->ssc->regs, PDC_TNCR,
|
|
runtime->period_size * runtime->channels);
|
|
retval = IRQ_HANDLED;
|
|
}
|
|
|
|
ssc_readl(chip->ssc->regs, IMR);
|
|
spin_unlock(&chip->lock);
|
|
|
|
if (status & SSC_BIT(IMR_ENDTX))
|
|
snd_pcm_period_elapsed(chip->substream);
|
|
|
|
return retval;
|
|
}
|
|
|
|
/*
|
|
* Mixer functions.
|
|
*/
|
|
static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
{
|
|
struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
|
|
int reg = kcontrol->private_value & 0xff;
|
|
int shift = (kcontrol->private_value >> 8) & 0xff;
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
int invert = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
mutex_lock(&chip->mixer_lock);
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
(chip->reg_image[reg] >> shift) & mask;
|
|
|
|
if (invert)
|
|
ucontrol->value.integer.value[0] =
|
|
mask - ucontrol->value.integer.value[0];
|
|
|
|
mutex_unlock(&chip->mixer_lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_mono_put(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
{
|
|
struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
|
|
int reg = kcontrol->private_value & 0xff;
|
|
int shift = (kcontrol->private_value >> 8) & 0xff;
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
int invert = (kcontrol->private_value >> 24) & 0xff;
|
|
int change, retval;
|
|
unsigned short val;
|
|
|
|
val = (ucontrol->value.integer.value[0] & mask);
|
|
if (invert)
|
|
val = mask - val;
|
|
val <<= shift;
|
|
|
|
mutex_lock(&chip->mixer_lock);
|
|
|
|
val = (chip->reg_image[reg] & ~(mask << shift)) | val;
|
|
change = val != chip->reg_image[reg];
|
|
retval = snd_at73c213_write_reg(chip, reg, val);
|
|
|
|
mutex_unlock(&chip->mixer_lock);
|
|
|
|
if (retval)
|
|
return retval;
|
|
|
|
return change;
|
|
}
|
|
|
|
static int snd_at73c213_stereo_info(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_info *uinfo)
|
|
{
|
|
int mask = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
if (mask == 1)
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
|
|
else
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
uinfo->value.integer.min = 0;
|
|
uinfo->value.integer.max = mask;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
{
|
|
struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
|
|
int left_reg = kcontrol->private_value & 0xff;
|
|
int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
|
int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
|
int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
|
int mask = (kcontrol->private_value >> 24) & 0xff;
|
|
int invert = (kcontrol->private_value >> 22) & 1;
|
|
|
|
mutex_lock(&chip->mixer_lock);
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
(chip->reg_image[left_reg] >> shift_left) & mask;
|
|
ucontrol->value.integer.value[1] =
|
|
(chip->reg_image[right_reg] >> shift_right) & mask;
|
|
|
|
if (invert) {
|
|
ucontrol->value.integer.value[0] =
|
|
mask - ucontrol->value.integer.value[0];
|
|
ucontrol->value.integer.value[1] =
|
|
mask - ucontrol->value.integer.value[1];
|
|
}
|
|
|
|
mutex_unlock(&chip->mixer_lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_stereo_put(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
{
|
|
struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
|
|
int left_reg = kcontrol->private_value & 0xff;
|
|
int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
|
int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
|
int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
|
int mask = (kcontrol->private_value >> 24) & 0xff;
|
|
int invert = (kcontrol->private_value >> 22) & 1;
|
|
int change, retval;
|
|
unsigned short val1, val2;
|
|
|
|
val1 = ucontrol->value.integer.value[0] & mask;
|
|
val2 = ucontrol->value.integer.value[1] & mask;
|
|
if (invert) {
|
|
val1 = mask - val1;
|
|
val2 = mask - val2;
|
|
}
|
|
val1 <<= shift_left;
|
|
val2 <<= shift_right;
|
|
|
|
mutex_lock(&chip->mixer_lock);
|
|
|
|
val1 = (chip->reg_image[left_reg] & ~(mask << shift_left)) | val1;
|
|
val2 = (chip->reg_image[right_reg] & ~(mask << shift_right)) | val2;
|
|
change = val1 != chip->reg_image[left_reg]
|
|
|| val2 != chip->reg_image[right_reg];
|
|
retval = snd_at73c213_write_reg(chip, left_reg, val1);
|
|
if (retval) {
|
|
mutex_unlock(&chip->mixer_lock);
|
|
goto out;
|
|
}
|
|
retval = snd_at73c213_write_reg(chip, right_reg, val2);
|
|
if (retval) {
|
|
mutex_unlock(&chip->mixer_lock);
|
|
goto out;
|
|
}
|
|
|
|
mutex_unlock(&chip->mixer_lock);
|
|
|
|
return change;
|
|
|
|
out:
|
|
return retval;
|
|
}
|
|
|
|
#define snd_at73c213_mono_switch_info snd_ctl_boolean_mono_info
|
|
|
|
static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
{
|
|
struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
|
|
int reg = kcontrol->private_value & 0xff;
|
|
int shift = (kcontrol->private_value >> 8) & 0xff;
|
|
int invert = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
mutex_lock(&chip->mixer_lock);
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
(chip->reg_image[reg] >> shift) & 0x01;
|
|
|
|
if (invert)
|
|
ucontrol->value.integer.value[0] =
|
|
0x01 - ucontrol->value.integer.value[0];
|
|
|
|
mutex_unlock(&chip->mixer_lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_mono_switch_put(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
{
|
|
struct snd_at73c213 *chip = snd_kcontrol_chip(kcontrol);
|
|
int reg = kcontrol->private_value & 0xff;
|
|
int shift = (kcontrol->private_value >> 8) & 0xff;
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
int invert = (kcontrol->private_value >> 24) & 0xff;
|
|
int change, retval;
|
|
unsigned short val;
|
|
|
|
if (ucontrol->value.integer.value[0])
|
|
val = mask;
|
|
else
|
|
val = 0;
|
|
|
|
if (invert)
|
|
val = mask - val;
|
|
val <<= shift;
|
|
|
|
mutex_lock(&chip->mixer_lock);
|
|
|
|
val |= (chip->reg_image[reg] & ~(mask << shift));
|
|
change = val != chip->reg_image[reg];
|
|
|
|
retval = snd_at73c213_write_reg(chip, reg, val);
|
|
|
|
mutex_unlock(&chip->mixer_lock);
|
|
|
|
if (retval)
|
|
return retval;
|
|
|
|
return change;
|
|
}
|
|
|
|
static int snd_at73c213_pa_volume_info(struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_info *uinfo)
|
|
{
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
uinfo->count = 1;
|
|
uinfo->value.integer.min = 0;
|
|
uinfo->value.integer.max = ((kcontrol->private_value >> 16) & 0xff) - 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_line_capture_volume_info(
|
|
struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_info *uinfo)
|
|
{
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
uinfo->count = 2;
|
|
/* When inverted will give values 0x10001 => 0. */
|
|
uinfo->value.integer.min = 14;
|
|
uinfo->value.integer.max = 31;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_aux_capture_volume_info(
|
|
struct snd_kcontrol *kcontrol,
|
|
struct snd_ctl_elem_info *uinfo)
|
|
{
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
uinfo->count = 1;
|
|
/* When inverted will give values 0x10001 => 0. */
|
|
uinfo->value.integer.min = 14;
|
|
uinfo->value.integer.max = 31;
|
|
|
|
return 0;
|
|
}
|
|
|
|
#define AT73C213_MONO_SWITCH(xname, xindex, reg, shift, mask, invert) \
|
|
{ \
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
|
|
.name = xname, \
|
|
.index = xindex, \
|
|
.info = snd_at73c213_mono_switch_info, \
|
|
.get = snd_at73c213_mono_switch_get, \
|
|
.put = snd_at73c213_mono_switch_put, \
|
|
.private_value = (reg | (shift << 8) | (mask << 16) | (invert << 24)) \
|
|
}
|
|
|
|
#define AT73C213_STEREO(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
|
|
{ \
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
|
|
.name = xname, \
|
|
.index = xindex, \
|
|
.info = snd_at73c213_stereo_info, \
|
|
.get = snd_at73c213_stereo_get, \
|
|
.put = snd_at73c213_stereo_put, \
|
|
.private_value = (left_reg | (right_reg << 8) \
|
|
| (shift_left << 16) | (shift_right << 19) \
|
|
| (mask << 24) | (invert << 22)) \
|
|
}
|
|
|
|
static struct snd_kcontrol_new snd_at73c213_controls[] = {
|
|
AT73C213_STEREO("Master Playback Volume", 0, DAC_LMPG, DAC_RMPG, 0, 0, 0x1f, 1),
|
|
AT73C213_STEREO("Master Playback Switch", 0, DAC_LMPG, DAC_RMPG, 5, 5, 1, 1),
|
|
AT73C213_STEREO("PCM Playback Volume", 0, DAC_LLOG, DAC_RLOG, 0, 0, 0x1f, 1),
|
|
AT73C213_STEREO("PCM Playback Switch", 0, DAC_LLOG, DAC_RLOG, 5, 5, 1, 1),
|
|
AT73C213_MONO_SWITCH("Mono PA Playback Switch", 0, DAC_CTRL, DAC_CTRL_ONPADRV,
|
|
0x01, 0),
|
|
{
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
.name = "PA Playback Volume",
|
|
.index = 0,
|
|
.info = snd_at73c213_pa_volume_info,
|
|
.get = snd_at73c213_mono_get,
|
|
.put = snd_at73c213_mono_put,
|
|
.private_value = PA_CTRL | (PA_CTRL_APAGAIN << 8) | \
|
|
(0x0f << 16) | (1 << 24),
|
|
},
|
|
AT73C213_MONO_SWITCH("PA High Gain Playback Switch", 0, PA_CTRL, PA_CTRL_APALP,
|
|
0x01, 1),
|
|
AT73C213_MONO_SWITCH("PA Playback Switch", 0, PA_CTRL, PA_CTRL_APAON, 0x01, 0),
|
|
{
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
.name = "Aux Capture Volume",
|
|
.index = 0,
|
|
.info = snd_at73c213_aux_capture_volume_info,
|
|
.get = snd_at73c213_mono_get,
|
|
.put = snd_at73c213_mono_put,
|
|
.private_value = DAC_AUXG | (0 << 8) | (0x1f << 16) | (1 << 24),
|
|
},
|
|
AT73C213_MONO_SWITCH("Aux Capture Switch", 0, DAC_CTRL, DAC_CTRL_ONAUXIN,
|
|
0x01, 0),
|
|
{
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
.name = "Line Capture Volume",
|
|
.index = 0,
|
|
.info = snd_at73c213_line_capture_volume_info,
|
|
.get = snd_at73c213_stereo_get,
|
|
.put = snd_at73c213_stereo_put,
|
|
.private_value = DAC_LLIG | (DAC_RLIG << 8) | (0 << 16) | (0 << 19)
|
|
| (0x1f << 24) | (1 << 22),
|
|
},
|
|
AT73C213_MONO_SWITCH("Line Capture Switch", 0, DAC_CTRL, 0, 0x03, 0),
|
|
};
|
|
|
|
static int snd_at73c213_mixer(struct snd_at73c213 *chip)
|
|
{
|
|
struct snd_card *card;
|
|
int errval, idx;
|
|
|
|
if (chip == NULL || chip->pcm == NULL)
|
|
return -EINVAL;
|
|
|
|
card = chip->card;
|
|
|
|
strcpy(card->mixername, chip->pcm->name);
|
|
|
|
for (idx = 0; idx < ARRAY_SIZE(snd_at73c213_controls); idx++) {
|
|
errval = snd_ctl_add(card,
|
|
snd_ctl_new1(&snd_at73c213_controls[idx],
|
|
chip));
|
|
if (errval < 0)
|
|
goto cleanup;
|
|
}
|
|
|
|
return 0;
|
|
|
|
cleanup:
|
|
for (idx = 1; idx < ARRAY_SIZE(snd_at73c213_controls) + 1; idx++) {
|
|
struct snd_kcontrol *kctl;
|
|
kctl = snd_ctl_find_numid(card, idx);
|
|
if (kctl)
|
|
snd_ctl_remove(card, kctl);
|
|
}
|
|
return errval;
|
|
}
|
|
|
|
/*
|
|
* Device functions
|
|
*/
|
|
static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
|
|
{
|
|
/*
|
|
* Continuous clock output.
|
|
* Starts on falling TF.
|
|
* Delay 1 cycle (1 bit).
|
|
* Periode is 16 bit (16 - 1).
|
|
*/
|
|
ssc_writel(chip->ssc->regs, TCMR,
|
|
SSC_BF(TCMR_CKO, 1)
|
|
| SSC_BF(TCMR_START, 4)
|
|
| SSC_BF(TCMR_STTDLY, 1)
|
|
| SSC_BF(TCMR_PERIOD, 16 - 1));
|
|
/*
|
|
* Data length is 16 bit (16 - 1).
|
|
* Transmit MSB first.
|
|
* Transmit 2 words each transfer.
|
|
* Frame sync length is 16 bit (16 - 1).
|
|
* Frame starts on negative pulse.
|
|
*/
|
|
ssc_writel(chip->ssc->regs, TFMR,
|
|
SSC_BF(TFMR_DATLEN, 16 - 1)
|
|
| SSC_BIT(TFMR_MSBF)
|
|
| SSC_BF(TFMR_DATNB, 1)
|
|
| SSC_BF(TFMR_FSLEN, 16 - 1)
|
|
| SSC_BF(TFMR_FSOS, 1));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_chip_init(struct snd_at73c213 *chip)
|
|
{
|
|
int retval;
|
|
unsigned char dac_ctrl = 0;
|
|
|
|
retval = snd_at73c213_set_bitrate(chip);
|
|
if (retval)
|
|
goto out;
|
|
|
|
/* Enable DAC master clock. */
|
|
retval = clk_enable(chip->board->dac_clk);
|
|
if (retval)
|
|
goto out;
|
|
|
|
/* Initialize at73c213 on SPI bus. */
|
|
retval = snd_at73c213_write_reg(chip, DAC_RST, 0x04);
|
|
if (retval)
|
|
goto out_clk;
|
|
msleep(1);
|
|
retval = snd_at73c213_write_reg(chip, DAC_RST, 0x03);
|
|
if (retval)
|
|
goto out_clk;
|
|
|
|
/* Precharge everything. */
|
|
retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0xff);
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, PA_CTRL, (1<<PA_CTRL_APAPRECH));
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, DAC_CTRL,
|
|
(1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR));
|
|
if (retval)
|
|
goto out_clk;
|
|
|
|
msleep(50);
|
|
|
|
/* Stop precharging PA. */
|
|
retval = snd_at73c213_write_reg(chip, PA_CTRL,
|
|
(1<<PA_CTRL_APALP) | 0x0f);
|
|
if (retval)
|
|
goto out_clk;
|
|
|
|
msleep(450);
|
|
|
|
/* Stop precharging DAC, turn on master power. */
|
|
retval = snd_at73c213_write_reg(chip, DAC_PRECH, (1<<DAC_PRECH_ONMSTR));
|
|
if (retval)
|
|
goto out_clk;
|
|
|
|
msleep(1);
|
|
|
|
/* Turn on DAC. */
|
|
dac_ctrl = (1<<DAC_CTRL_ONDACL) | (1<<DAC_CTRL_ONDACR)
|
|
| (1<<DAC_CTRL_ONLNOL) | (1<<DAC_CTRL_ONLNOR);
|
|
|
|
retval = snd_at73c213_write_reg(chip, DAC_CTRL, dac_ctrl);
|
|
if (retval)
|
|
goto out_clk;
|
|
|
|
/* Mute sound. */
|
|
retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
|
|
if (retval)
|
|
goto out_clk;
|
|
retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
|
|
if (retval)
|
|
goto out_clk;
|
|
|
|
/* Enable I2S device, i.e. clock output. */
|
|
ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
|
|
|
|
goto out;
|
|
|
|
out_clk:
|
|
clk_disable(chip->board->dac_clk);
|
|
out:
|
|
return retval;
|
|
}
|
|
|
|
static int snd_at73c213_dev_free(struct snd_device *device)
|
|
{
|
|
struct snd_at73c213 *chip = device->device_data;
|
|
|
|
ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
|
|
if (chip->irq >= 0) {
|
|
free_irq(chip->irq, chip);
|
|
chip->irq = -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_dev_init(struct snd_card *card,
|
|
struct spi_device *spi)
|
|
{
|
|
static struct snd_device_ops ops = {
|
|
.dev_free = snd_at73c213_dev_free,
|
|
};
|
|
struct snd_at73c213 *chip = get_chip(card);
|
|
int irq, retval;
|
|
|
|
irq = chip->ssc->irq;
|
|
if (irq < 0)
|
|
return irq;
|
|
|
|
spin_lock_init(&chip->lock);
|
|
mutex_init(&chip->mixer_lock);
|
|
chip->card = card;
|
|
chip->irq = -1;
|
|
|
|
retval = clk_enable(chip->ssc->clk);
|
|
if (retval)
|
|
return retval;
|
|
|
|
retval = request_irq(irq, snd_at73c213_interrupt, 0, "at73c213", chip);
|
|
if (retval) {
|
|
dev_dbg(&chip->spi->dev, "unable to request irq %d\n", irq);
|
|
goto out;
|
|
}
|
|
chip->irq = irq;
|
|
|
|
memcpy(&chip->reg_image, &snd_at73c213_original_image,
|
|
sizeof(snd_at73c213_original_image));
|
|
|
|
retval = snd_at73c213_ssc_init(chip);
|
|
if (retval)
|
|
goto out_irq;
|
|
|
|
retval = snd_at73c213_chip_init(chip);
|
|
if (retval)
|
|
goto out_irq;
|
|
|
|
retval = snd_at73c213_pcm_new(chip, 0);
|
|
if (retval)
|
|
goto out_irq;
|
|
|
|
retval = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
|
|
if (retval)
|
|
goto out_irq;
|
|
|
|
retval = snd_at73c213_mixer(chip);
|
|
if (retval)
|
|
goto out_snd_dev;
|
|
|
|
goto out;
|
|
|
|
out_snd_dev:
|
|
snd_device_free(card, chip);
|
|
out_irq:
|
|
free_irq(chip->irq, chip);
|
|
chip->irq = -1;
|
|
out:
|
|
clk_disable(chip->ssc->clk);
|
|
|
|
return retval;
|
|
}
|
|
|
|
static int snd_at73c213_probe(struct spi_device *spi)
|
|
{
|
|
struct snd_card *card;
|
|
struct snd_at73c213 *chip;
|
|
struct at73c213_board_info *board;
|
|
int retval;
|
|
char id[16];
|
|
|
|
board = spi->dev.platform_data;
|
|
if (!board) {
|
|
dev_dbg(&spi->dev, "no platform_data\n");
|
|
return -ENXIO;
|
|
}
|
|
|
|
if (!board->dac_clk) {
|
|
dev_dbg(&spi->dev, "no DAC clk\n");
|
|
return -ENXIO;
|
|
}
|
|
|
|
if (IS_ERR(board->dac_clk)) {
|
|
dev_dbg(&spi->dev, "no DAC clk\n");
|
|
return PTR_ERR(board->dac_clk);
|
|
}
|
|
|
|
/* Allocate "card" using some unused identifiers. */
|
|
snprintf(id, sizeof id, "at73c213_%d", board->ssc_id);
|
|
retval = snd_card_new(&spi->dev, -1, id, THIS_MODULE,
|
|
sizeof(struct snd_at73c213), &card);
|
|
if (retval < 0)
|
|
goto out;
|
|
|
|
chip = card->private_data;
|
|
chip->spi = spi;
|
|
chip->board = board;
|
|
|
|
chip->ssc = ssc_request(board->ssc_id);
|
|
if (IS_ERR(chip->ssc)) {
|
|
dev_dbg(&spi->dev, "could not get ssc%d device\n",
|
|
board->ssc_id);
|
|
retval = PTR_ERR(chip->ssc);
|
|
goto out_card;
|
|
}
|
|
|
|
retval = snd_at73c213_dev_init(card, spi);
|
|
if (retval)
|
|
goto out_ssc;
|
|
|
|
strcpy(card->driver, "at73c213");
|
|
strcpy(card->shortname, board->shortname);
|
|
sprintf(card->longname, "%s on irq %d", card->shortname, chip->irq);
|
|
|
|
retval = snd_card_register(card);
|
|
if (retval)
|
|
goto out_ssc;
|
|
|
|
dev_set_drvdata(&spi->dev, card);
|
|
|
|
goto out;
|
|
|
|
out_ssc:
|
|
ssc_free(chip->ssc);
|
|
out_card:
|
|
snd_card_free(card);
|
|
out:
|
|
return retval;
|
|
}
|
|
|
|
static int snd_at73c213_remove(struct spi_device *spi)
|
|
{
|
|
struct snd_card *card = dev_get_drvdata(&spi->dev);
|
|
struct snd_at73c213 *chip = card->private_data;
|
|
int retval;
|
|
|
|
/* Stop playback. */
|
|
retval = clk_enable(chip->ssc->clk);
|
|
if (retval)
|
|
goto out;
|
|
ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
|
|
clk_disable(chip->ssc->clk);
|
|
|
|
/* Mute sound. */
|
|
retval = snd_at73c213_write_reg(chip, DAC_LMPG, 0x3f);
|
|
if (retval)
|
|
goto out;
|
|
retval = snd_at73c213_write_reg(chip, DAC_RMPG, 0x3f);
|
|
if (retval)
|
|
goto out;
|
|
retval = snd_at73c213_write_reg(chip, DAC_LLOG, 0x3f);
|
|
if (retval)
|
|
goto out;
|
|
retval = snd_at73c213_write_reg(chip, DAC_RLOG, 0x3f);
|
|
if (retval)
|
|
goto out;
|
|
retval = snd_at73c213_write_reg(chip, DAC_LLIG, 0x11);
|
|
if (retval)
|
|
goto out;
|
|
retval = snd_at73c213_write_reg(chip, DAC_RLIG, 0x11);
|
|
if (retval)
|
|
goto out;
|
|
retval = snd_at73c213_write_reg(chip, DAC_AUXG, 0x11);
|
|
if (retval)
|
|
goto out;
|
|
|
|
/* Turn off PA. */
|
|
retval = snd_at73c213_write_reg(chip, PA_CTRL,
|
|
chip->reg_image[PA_CTRL] | 0x0f);
|
|
if (retval)
|
|
goto out;
|
|
msleep(10);
|
|
retval = snd_at73c213_write_reg(chip, PA_CTRL,
|
|
(1 << PA_CTRL_APALP) | 0x0f);
|
|
if (retval)
|
|
goto out;
|
|
|
|
/* Turn off external DAC. */
|
|
retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x0c);
|
|
if (retval)
|
|
goto out;
|
|
msleep(2);
|
|
retval = snd_at73c213_write_reg(chip, DAC_CTRL, 0x00);
|
|
if (retval)
|
|
goto out;
|
|
|
|
/* Turn off master power. */
|
|
retval = snd_at73c213_write_reg(chip, DAC_PRECH, 0x00);
|
|
if (retval)
|
|
goto out;
|
|
|
|
out:
|
|
/* Stop DAC master clock. */
|
|
clk_disable(chip->board->dac_clk);
|
|
|
|
ssc_free(chip->ssc);
|
|
snd_card_free(card);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int snd_at73c213_suspend(struct device *dev)
|
|
{
|
|
struct snd_card *card = dev_get_drvdata(dev);
|
|
struct snd_at73c213 *chip = card->private_data;
|
|
|
|
ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXDIS));
|
|
clk_disable(chip->ssc->clk);
|
|
clk_disable(chip->board->dac_clk);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int snd_at73c213_resume(struct device *dev)
|
|
{
|
|
struct snd_card *card = dev_get_drvdata(dev);
|
|
struct snd_at73c213 *chip = card->private_data;
|
|
int retval;
|
|
|
|
retval = clk_enable(chip->board->dac_clk);
|
|
if (retval)
|
|
return retval;
|
|
retval = clk_enable(chip->ssc->clk);
|
|
if (retval) {
|
|
clk_disable(chip->board->dac_clk);
|
|
return retval;
|
|
}
|
|
ssc_writel(chip->ssc->regs, CR, SSC_BIT(CR_TXEN));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static SIMPLE_DEV_PM_OPS(at73c213_pm_ops, snd_at73c213_suspend,
|
|
snd_at73c213_resume);
|
|
#define AT73C213_PM_OPS (&at73c213_pm_ops)
|
|
|
|
#else
|
|
#define AT73C213_PM_OPS NULL
|
|
#endif
|
|
|
|
static struct spi_driver at73c213_driver = {
|
|
.driver = {
|
|
.name = "at73c213",
|
|
.pm = AT73C213_PM_OPS,
|
|
},
|
|
.probe = snd_at73c213_probe,
|
|
.remove = snd_at73c213_remove,
|
|
};
|
|
|
|
module_spi_driver(at73c213_driver);
|
|
|
|
MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
|
|
MODULE_DESCRIPTION("Sound driver for AT73C213 with Atmel SSC");
|
|
MODULE_LICENSE("GPL");
|