^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) * i2sbus driver -- private definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __I2SBUS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __I2SBUS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/pmac_feature.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/dbdma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "../soundbus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct i2sbus_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct macio_chip *macio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define MAX_DBDMA_COMMANDS 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct dbdma_command_mem {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) dma_addr_t bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) dma_addr_t bus_cmd_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct dbdma_cmd *cmds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void *space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u32 running:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u32 stopping:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct pcm_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u32 created:1, /* has this direction been created with alsa? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) active:1; /* is this stream active? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* runtime information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int current_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u32 frame_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct dbdma_command_mem dbdma_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) volatile struct dbdma_regs __iomem *dbdma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct completion *stop_completion;
^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) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) aoa_resource_i2smmio = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) aoa_resource_txdbdma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) aoa_resource_rxdbdma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct i2sbus_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct soundbus_dev sound;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct macio_dev *macio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct i2sbus_control *control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) volatile struct i2s_interface_regs __iomem *intfregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct resource resources[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct resource *allocated_resource[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int interrupts[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) char rnames[3][32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* info about currently active substreams */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct pcm_info out, in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) snd_pcm_format_t format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned int rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* list for a single controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct list_head item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* number of bus on controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int bus_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* for use by control layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct pmf_function *enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *cell_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *cell_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *clock_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *clock_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* spinlock for low-level interrupt locking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) spinlock_t low_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* mutex for high-level consistency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define soundbus_dev_to_i2sbus_dev(sdev) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) container_of(sdev, struct i2sbus_dev, sound)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* pcm specific functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) extern int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct codec_info *ci, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) extern void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) i2sbus_detach_codec(struct soundbus_dev *dev, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) extern irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) i2sbus_tx_intr(int irq, void *devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) extern irqreturn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) i2sbus_rx_intr(int irq, void *devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) extern void i2sbus_wait_for_stop_both(struct i2sbus_dev *i2sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) extern void i2sbus_pcm_prepare_both(struct i2sbus_dev *i2sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* control specific functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) extern int i2sbus_control_init(struct macio_dev* dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct i2sbus_control **c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) extern void i2sbus_control_destroy(struct i2sbus_control *c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) extern int i2sbus_control_add_dev(struct i2sbus_control *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct i2sbus_dev *i2sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) extern void i2sbus_control_remove_dev(struct i2sbus_control *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct i2sbus_dev *i2sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) extern int i2sbus_control_enable(struct i2sbus_control *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct i2sbus_dev *i2sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) extern int i2sbus_control_cell(struct i2sbus_control *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct i2sbus_dev *i2sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) extern int i2sbus_control_clock(struct i2sbus_control *c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct i2sbus_dev *i2sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #endif /* __I2SBUS_H */