blob: 32ced0c8f7894d7645cbc1b9001e5a0c77ade3bb [file] [log] [blame]
Sebastian Reichelb209e042013-12-15 23:38:58 +01001/* OMAP SSI internal interface.
2 *
3 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
4 * Copyright (C) 2013 Sebastian Reichel
5 *
6 * Contact: Carlos Chinea <carlos.chinea@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#ifndef __LINUX_HSI_OMAP_SSI_H__
24#define __LINUX_HSI_OMAP_SSI_H__
25
26#include <linux/device.h>
Paul Gortmakera1a0bec2015-05-01 20:02:30 -040027#include <linux/module.h>
Sebastian Reichelb209e042013-12-15 23:38:58 +010028#include <linux/platform_device.h>
29#include <linux/hsi/hsi.h>
Sebastian Reichel73e6ce02016-04-30 00:04:29 +020030#include <linux/gpio/consumer.h>
Sebastian Reichelb209e042013-12-15 23:38:58 +010031#include <linux/interrupt.h>
32#include <linux/io.h>
33
34#define SSI_MAX_CHANNELS 8
35#define SSI_MAX_GDD_LCH 8
36#define SSI_BYTES_TO_FRAMES(x) ((((x) - 1) >> 2) + 1)
37
Sebastian Reichel20830572016-04-30 17:11:54 +020038#define SSI_WAKE_EN 0
39
Sebastian Reichelb209e042013-12-15 23:38:58 +010040/**
41 * struct omap_ssm_ctx - OMAP synchronous serial module (TX/RX) context
42 * @mode: Bit transmission mode
43 * @channels: Number of channels
44 * @framesize: Frame size in bits
45 * @timeout: RX frame timeout
46 * @divisor: TX divider
47 * @arb_mode: Arbitration mode for TX frame (Round robin, priority)
48 */
49struct omap_ssm_ctx {
50 u32 mode;
51 u32 channels;
52 u32 frame_size;
53 union {
54 u32 timeout; /* Rx Only */
55 struct {
56 u32 arb_mode;
57 u32 divisor;
58 }; /* Tx only */
59 };
60};
61
62/**
63 * struct omap_ssi_port - OMAP SSI port data
64 * @dev: device associated to the port (HSI port)
65 * @pdev: platform device associated to the port
66 * @sst_dma: SSI transmitter physical base address
67 * @ssr_dma: SSI receiver physical base address
68 * @sst_base: SSI transmitter base address
69 * @ssr_base: SSI receiver base address
70 * @wk_lock: spin lock to serialize access to the wake lines
71 * @lock: Spin lock to serialize access to the SSI port
72 * @channels: Current number of channels configured (1,2,4 or 8)
73 * @txqueue: TX message queues
74 * @rxqueue: RX message queues
75 * @brkqueue: Queue of incoming HWBREAK requests (FRAME mode)
Sebastian Reichel4e552312016-05-20 06:25:06 +020076 * @errqueue: Queue for failed messages
77 * @errqueue_work: Delayed Work for failed messages
Sebastian Reichelb209e042013-12-15 23:38:58 +010078 * @irq: IRQ number
79 * @wake_irq: IRQ number for incoming wake line (-1 if none)
80 * @wake_gpio: GPIO number for incoming wake line (-1 if none)
Sebastian Reichel20830572016-04-30 17:11:54 +020081 * @flags: flags to keep track of states
Sebastian Reichelb209e042013-12-15 23:38:58 +010082 * @wk_refcount: Reference count for output wake line
Sebastian Reichel7c5d8162016-05-11 20:33:45 +020083 * @work: worker for starting TX
Sebastian Reichelb209e042013-12-15 23:38:58 +010084 * @sys_mpu_enable: Context for the interrupt enable register for irq 0
85 * @sst: Context for the synchronous serial transmitter
86 * @ssr: Context for the synchronous serial receiver
87 */
88struct omap_ssi_port {
89 struct device *dev;
90 struct device *pdev;
91 dma_addr_t sst_dma;
92 dma_addr_t ssr_dma;
93 void __iomem *sst_base;
94 void __iomem *ssr_base;
95 spinlock_t wk_lock;
96 spinlock_t lock;
97 unsigned int channels;
98 struct list_head txqueue[SSI_MAX_CHANNELS];
99 struct list_head rxqueue[SSI_MAX_CHANNELS];
100 struct list_head brkqueue;
Sebastian Reichel4e552312016-05-20 06:25:06 +0200101 struct list_head errqueue;
102 struct delayed_work errqueue_work;
Sebastian Reichelb209e042013-12-15 23:38:58 +0100103 unsigned int irq;
104 int wake_irq;
Sebastian Reichel73e6ce02016-04-30 00:04:29 +0200105 struct gpio_desc *wake_gpio;
Sebastian Reichelb209e042013-12-15 23:38:58 +0100106 bool wktest:1; /* FIXME: HACK to be removed */
Sebastian Reichel20830572016-04-30 17:11:54 +0200107 unsigned long flags;
Sebastian Reichelb209e042013-12-15 23:38:58 +0100108 unsigned int wk_refcount;
Sebastian Reichel7c5d8162016-05-11 20:33:45 +0200109 struct work_struct work;
Sebastian Reichelb209e042013-12-15 23:38:58 +0100110 /* OMAP SSI port context */
111 u32 sys_mpu_enable; /* We use only one irq */
112 struct omap_ssm_ctx sst;
113 struct omap_ssm_ctx ssr;
114 u32 loss_count;
115 u32 port_id;
116#ifdef CONFIG_DEBUG_FS
117 struct dentry *dir;
118#endif
119};
120
121/**
122 * struct gdd_trn - GDD transaction data
123 * @msg: Pointer to the HSI message being served
124 * @sg: Pointer to the current sg entry being served
125 */
126struct gdd_trn {
127 struct hsi_msg *msg;
128 struct scatterlist *sg;
129};
130
131/**
132 * struct omap_ssi_controller - OMAP SSI controller data
133 * @dev: device associated to the controller (HSI controller)
134 * @sys: SSI I/O base address
135 * @gdd: GDD I/O base address
136 * @fck: SSI functional clock
137 * @gdd_irq: IRQ line for GDD
138 * @gdd_tasklet: bottom half for DMA transfers
139 * @gdd_trn: Array of GDD transaction data for ongoing GDD transfers
140 * @lock: lock to serialize access to GDD
Sebastian Reichel4bcf7412016-01-31 01:52:38 +0100141 * @fck_nb: DVFS notfifier block
142 * @fck_rate: clock rate
Sebastian Reichelb209e042013-12-15 23:38:58 +0100143 * @loss_count: To follow if we need to restore context or not
144 * @max_speed: Maximum TX speed (Kb/s) set by the clients.
Sebastian Reichelb209e042013-12-15 23:38:58 +0100145 * @gdd_gcr: SSI GDD saved context
146 * @get_loss: Pointer to omap_pm_get_dev_context_loss_count, if any
147 * @port: Array of pointers of the ports of the controller
148 * @dir: Debugfs SSI root directory
149 */
150struct omap_ssi_controller {
151 struct device *dev;
152 void __iomem *sys;
153 void __iomem *gdd;
154 struct clk *fck;
155 unsigned int gdd_irq;
156 struct tasklet_struct gdd_tasklet;
157 struct gdd_trn gdd_trn[SSI_MAX_GDD_LCH];
158 spinlock_t lock;
Sebastian Reichel4bcf7412016-01-31 01:52:38 +0100159 struct notifier_block fck_nb;
Sebastian Reichelb209e042013-12-15 23:38:58 +0100160 unsigned long fck_rate;
161 u32 loss_count;
162 u32 max_speed;
163 /* OMAP SSI Controller context */
Sebastian Reichelb209e042013-12-15 23:38:58 +0100164 u32 gdd_gcr;
165 int (*get_loss)(struct device *dev);
166 struct omap_ssi_port **port;
167#ifdef CONFIG_DEBUG_FS
168 struct dentry *dir;
169#endif
170};
171
Sebastian Reichel4bcf7412016-01-31 01:52:38 +0100172void omap_ssi_port_update_fclk(struct hsi_controller *ssi,
173 struct omap_ssi_port *omap_port);
174
Sebastian Reichel0fae1982016-04-30 03:24:09 +0200175extern struct platform_driver ssi_port_pdriver;
176
Sebastian Reichelb209e042013-12-15 23:38:58 +0100177#endif /* __LINUX_HSI_OMAP_SSI_H__ */