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