21 #include <linux/errno.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
27 #include <linux/wait.h>
30 #include <linux/device.h>
40 #define REG_IOSEL_1 0x04
41 #define REG_IOSEL_2 0x08
42 #define REG_PREDIV 0x0c
43 #define REG_INTR_ST 0x10
44 #define REG_INTR_EN 0x14
45 #define REG_TEST_CTRL 0x18
48 #define PORT_CFG_2 0x00
49 #define PORT_ADDR 0x04
50 #define PORT_DATA 0x08
51 #define PORT_CFG_1 0x0c
52 #define PORT_STATE 0x10
54 #define SSP_PORT_CONFIG_MASK (SSP_EARLY_DIN | SSP_DELAY_DOUT)
55 #define SSP_PORT_CLKRATE_MASK 0x0f
57 #define SSP_SEQRAM_WR_EN BIT(4)
58 #define SSP_SEQRAM_RD_EN BIT(5)
59 #define SSP_START BIT(15)
60 #define SSP_BUSY BIT(10)
61 #define SSP_PORT_ASL BIT(7)
62 #define SSP_PORT_CFO1 BIT(6)
64 #define SSP_PORT_SEQRAM_SIZE 32
66 static const int ssp_port_base[] = {0x040, 0x080};
67 static const int ssp_port_seqram[] = {0x100, 0x180};
109 ssp_write(ssp, reg, (ssp_read(ssp, reg) & ~mask) | bits);
112 static inline u32 ssp_port_read(
struct ti_ssp *ssp,
int port,
int reg)
114 return ssp_read(ssp, ssp_port_base[port] + reg);
117 static inline void ssp_port_write(
struct ti_ssp *ssp,
int port,
int reg,
120 ssp_write(ssp, ssp_port_base[port] + reg, val);
123 static inline void ssp_port_rmw(
struct ti_ssp *ssp,
int port,
int reg,
126 ssp_rmw(ssp, ssp_port_base[port] + reg, mask, bits);
129 static inline void ssp_port_clr_bits(
struct ti_ssp *ssp,
int port,
int reg,
132 ssp_port_rmw(ssp, port, reg, bits, 0);
135 static inline void ssp_port_set_bits(
struct ti_ssp *ssp,
int port,
int reg,
138 ssp_port_rmw(ssp, port, reg, 0, bits);
152 struct ti_ssp *ssp = dev_to_ssp(dev);
156 spin_lock(&ssp->
lock);
157 ret = __set_mode(ssp, port, mode);
158 spin_unlock(&ssp->
lock);
172 static void __set_iosel(
struct ti_ssp *ssp,
int port,
u32 iosel)
174 unsigned val, shift = port ? 16 : 0;
178 val &= 0xffff << (port ? 0 : 16);
179 val |= (iosel & 0xffff) << (port ? 16 : 0);
183 val = (iosel >> 16) & 0x7;
184 __set_iosel2(ssp, 0x7 << shift, val << shift);
189 struct ti_ssp *ssp = dev_to_ssp(dev);
192 spin_lock(&ssp->
lock);
193 __set_iosel(ssp, port, iosel);
194 spin_unlock(&ssp->
lock);
202 struct ti_ssp *ssp = dev_to_ssp(dev);
209 spin_lock(&ssp->
lock);
215 for (i = 0; i < len; i++) {
217 ssp_port_seqram[port]);
223 spin_unlock(&ssp->
lock);
231 struct ti_ssp *ssp = dev_to_ssp(dev);
233 int shift = port ? 27 : 11;
235 return (ssp_read(ssp,
REG_IOSEL_2) >> shift) & 0xf;
241 struct ti_ssp *ssp = dev_to_ssp(dev);
244 spin_lock(&ssp->
lock);
246 shift = port ? 22 : 6;
248 __set_iosel2(ssp, 0xf << shift, val << shift);
250 spin_unlock(&ssp->
lock);
256 static inline int __xfer_done(
struct ti_ssp *ssp,
int port)
263 struct ti_ssp *ssp = dev_to_ssp(dev);
271 spin_lock(&ssp->
lock);
273 ssp_port_write(ssp, port,
PORT_ADDR, input >> 16);
274 ssp_port_write(ssp, port,
PORT_DATA, input & 0xffff);
275 ssp_port_rmw(ssp, port,
PORT_CFG_1, 0x3f, pc);
284 spin_unlock(&ssp->
lock);
287 __xfer_done(ssp, port));
288 spin_unlock_irq(&ssp->
wqh.
lock);
294 *output = (ssp_port_read(ssp, port,
PORT_ADDR) << 16) |
295 (ssp_port_read(ssp, port,
PORT_DATA) & 0xffff);
298 ret = ssp_port_read(ssp, port,
PORT_STATE) & 0x3f;
306 struct ti_ssp *ssp = dev_data;
322 int error = 0, prediv = 0xff,
id;
323 unsigned long sysclk;
329 dev_err(dev,
"cannot allocate device info\n");
339 dev_err(dev,
"cannot determine register area\n");
346 dev_err(dev,
"cannot claim register memory\n");
350 ssp->regs =
ioremap(ssp->res->start, resource_size(ssp->res));
353 dev_err(dev,
"cannot map register memory\n");
358 if (IS_ERR(ssp->clk)) {
359 error = PTR_ERR(ssp->clk);
360 dev_err(dev,
"cannot claim device clock\n");
374 dev_err(dev,
"cannot acquire irq\n");
384 dev_err(dev,
"cannot enable device clock\n");
401 prediv = (sysclk / pdata->
out_clock) - 1;
402 prediv =
clamp(prediv, 0, 0xff);
405 memset(cells, 0,
sizeof(cells));
406 for (
id = 0;
id < 2;
id++) {
411 cells[
id].platform_data = data->
pdata;
417 dev_err(dev,
"cannot add mfd cells\n");
453 .probe = ti_ssp_probe,