blob: f93022113f5932cbf67cc737f2dc49d617396fdb [file] [log] [blame]
Greg Kroah-Hartmane3b3d0f2017-11-06 18:11:51 +01001// SPDX-License-Identifier: GPL-2.0
Joe Perchese4ac92d2014-05-20 14:05:50 -07002#ifndef __SAMSUNG_H
3#define __SAMSUNG_H
4
Jovi Zhang99edb3d2011-03-30 05:30:41 -04005/*
Ben Dooksb4975492008-07-03 12:32:51 +01006 * Driver for Samsung SoC onboard UARTs.
7 *
Ben Dooksccae9412009-11-13 22:54:14 +00008 * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics
Ben Dooksb4975492008-07-03 12:32:51 +01009 * http://armlinux.simtec.co.uk/
Ben Dooksb4975492008-07-03 12:32:51 +010010*/
11
Robert Baldyga7bb6b2f2014-12-10 12:49:22 +010012#include <linux/dmaengine.h>
13
Ben Dooksb4975492008-07-03 12:32:51 +010014struct s3c24xx_uart_info {
15 char *name;
16 unsigned int type;
17 unsigned int fifosize;
18 unsigned long rx_fifomask;
19 unsigned long rx_fifoshift;
20 unsigned long rx_fifofull;
21 unsigned long tx_fifomask;
22 unsigned long tx_fifoshift;
23 unsigned long tx_fifofull;
Thomas Abraham5f5a7a52011-10-24 11:47:46 +020024 unsigned int def_clk_sel;
25 unsigned long num_clks;
26 unsigned long clksel_mask;
27 unsigned long clksel_shift;
Ben Dooksb4975492008-07-03 12:32:51 +010028
Ben Dooks090f8482008-12-12 00:24:21 +000029 /* uart port features */
30
31 unsigned int has_divslot:1;
32
Ben Dooksb4975492008-07-03 12:32:51 +010033 /* uart controls */
34 int (*reset_port)(struct uart_port *, struct s3c2410_uartcfg *);
35};
36
Thomas Abrahamda121502011-11-02 19:23:25 +090037struct s3c24xx_serial_drv_data {
38 struct s3c24xx_uart_info *info;
39 struct s3c2410_uartcfg *def_cfg;
40 unsigned int fifosize[CONFIG_SERIAL_SAMSUNG_UARTS];
41};
42
Robert Baldyga7bb6b2f2014-12-10 12:49:22 +010043struct s3c24xx_uart_dma {
Robert Baldyga7bb6b2f2014-12-10 12:49:22 +010044 unsigned int rx_chan_id;
45 unsigned int tx_chan_id;
46
47 struct dma_slave_config rx_conf;
48 struct dma_slave_config tx_conf;
49
50 struct dma_chan *rx_chan;
51 struct dma_chan *tx_chan;
52
53 dma_addr_t rx_addr;
54 dma_addr_t tx_addr;
55
56 dma_cookie_t rx_cookie;
57 dma_cookie_t tx_cookie;
58
59 char *rx_buf;
60
61 dma_addr_t tx_transfer_addr;
62
63 size_t rx_size;
64 size_t tx_size;
65
66 struct dma_async_tx_descriptor *tx_desc;
67 struct dma_async_tx_descriptor *rx_desc;
68
69 int tx_bytes_requested;
70 int rx_bytes_requested;
71};
72
Ben Dooksb4975492008-07-03 12:32:51 +010073struct s3c24xx_uart_port {
74 unsigned char rx_claimed;
75 unsigned char tx_claimed;
Ben Dooks30555472008-10-21 14:06:36 +010076 unsigned int pm_level;
77 unsigned long baudclk_rate;
Marek Szyprowski81ccb2a2015-07-31 10:58:27 +020078 unsigned int min_dma_size;
Ben Dooksb4975492008-07-03 12:32:51 +010079
Ben Dooksb73c289c2008-10-21 14:07:04 +010080 unsigned int rx_irq;
81 unsigned int tx_irq;
82
Robert Baldyga29bef792014-12-10 12:49:26 +010083 unsigned int tx_in_progress;
84 unsigned int tx_mode;
Robert Baldygab543c302014-12-10 12:49:27 +010085 unsigned int rx_mode;
Robert Baldyga29bef792014-12-10 12:49:26 +010086
Ben Dooksb4975492008-07-03 12:32:51 +010087 struct s3c24xx_uart_info *info;
Ben Dooksb4975492008-07-03 12:32:51 +010088 struct clk *clk;
89 struct clk *baudclk;
90 struct uart_port port;
Thomas Abrahamda121502011-11-02 19:23:25 +090091 struct s3c24xx_serial_drv_data *drv_data;
Ben Dooks30555472008-10-21 14:06:36 +010092
Thomas Abraham4d84e972011-10-24 11:47:25 +020093 /* reference to platform data */
94 struct s3c2410_uartcfg *cfg;
95
Robert Baldyga7bb6b2f2014-12-10 12:49:22 +010096 struct s3c24xx_uart_dma *dma;
97
Krzysztof Kozlowskiebaa81c2016-06-27 13:59:08 +020098#ifdef CONFIG_ARM_S3C24XX_CPUFREQ
Ben Dooks30555472008-10-21 14:06:36 +010099 struct notifier_block freq_transition;
100#endif
Ben Dooksb4975492008-07-03 12:32:51 +0100101};
102
103/* conversion functions */
104
Jingoo Hand4aab202013-09-09 14:10:30 +0900105#define s3c24xx_dev_to_port(__dev) dev_get_drvdata(__dev)
Ben Dooksb4975492008-07-03 12:32:51 +0100106
107/* register access controls */
108
109#define portaddr(port, reg) ((port)->membase + (reg))
Jingoo Han9fdedf52013-08-08 17:29:48 +0900110#define portaddrl(port, reg) \
111 ((unsigned long *)(unsigned long)((port)->membase + (reg)))
Ben Dooksb4975492008-07-03 12:32:51 +0100112
Matthew Leache37697b2016-06-22 17:57:02 +0100113#define rd_regb(port, reg) (readb_relaxed(portaddr(port, reg)))
114#define rd_regl(port, reg) (readl_relaxed(portaddr(port, reg)))
Ben Dooksb4975492008-07-03 12:32:51 +0100115
Matthew Leache37697b2016-06-22 17:57:02 +0100116#define wr_regb(port, reg, val) writeb_relaxed(val, portaddr(port, reg))
117#define wr_regl(port, reg, val) writel_relaxed(val, portaddr(port, reg))
Ben Dooksb4975492008-07-03 12:32:51 +0100118
Matthew Leachbbb5ff92016-06-22 17:57:03 +0100119/* Byte-order aware bit setting/clearing functions. */
120
121static inline void s3c24xx_set_bit(struct uart_port *port, int idx,
122 unsigned int reg)
123{
124 unsigned long flags;
125 u32 val;
126
127 local_irq_save(flags);
128 val = rd_regl(port, reg);
129 val |= (1 << idx);
130 wr_regl(port, reg, val);
131 local_irq_restore(flags);
132}
133
134static inline void s3c24xx_clear_bit(struct uart_port *port, int idx,
135 unsigned int reg)
136{
137 unsigned long flags;
138 u32 val;
139
140 local_irq_save(flags);
141 val = rd_regl(port, reg);
142 val &= ~(1 << idx);
143 wr_regl(port, reg, val);
144 local_irq_restore(flags);
145}
146
Ben Dooksb4975492008-07-03 12:32:51 +0100147#endif