diff options
| author | Olof Johansson <olof@lixom.net> | 2014-01-02 13:33:15 -0500 |
|---|---|---|
| committer | Olof Johansson <olof@lixom.net> | 2014-01-02 13:33:15 -0500 |
| commit | 615e303e241cafa2ecf6452183532c2aff607920 (patch) | |
| tree | 2baa5731ddc81d8aeb3ef7aa95e5e8274e7fb189 /drivers/tty | |
| parent | 5aa88ce1137ca46164cc05dca3d7ee75ddee93d8 (diff) | |
| parent | ec09c5eb491834d4011c72538e58d8b7096076bd (diff) | |
Merge tag 'renesas-sh-sci2-for-v3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas into next/cleanup
From Simon Horman:
Second Round of Renesas SH SCI updates for v3.14
* Rework baud rate calculation
* Compute overrun_bit without using baud rate algo
* Remove unused GPIO request code
* Move overrun_bit and error_mask fields out of pdata
* Support resources passed through platform resources
* Don't check IRQ in verify port operation
* Set the UPF_FIXED_PORT flag
* Remove duplicate interrupt check in verify port op
* Simplify baud rate calculation algorithms
* Remove baud rate calculation algorithm 5
* Sort headers alphabetically
* tag 'renesas-sh-sci2-for-v3.14' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas:
serial: sh-sci: Rework baud rate calculation
serial: sh-sci: Compute overrun_bit without using baud rate algo
serial: sh-sci: Remove unused GPIO request code
serial: sh-sci: Move overrun_bit and error_mask fields out of pdata
serial: sh-sci: Support resources passed through platform resources
serial: sh-sci: Don't check IRQ in verify port operation
serial: sh-sci: Set the UPF_FIXED_PORT flag
serial: sh-sci: Remove duplicate interrupt check in verify port op
serial: sh-sci: Simplify baud rate calculation algorithms
serial: sh-sci: Remove baud rate calculation algorithm 5
serial: sh-sci: Sort headers alphabetically
Signed-off-by: Olof Johansson <olof@lixom.net>
Diffstat (limited to 'drivers/tty')
| -rw-r--r-- | drivers/tty/serial/sh-sci.c | 281 | ||||
| -rw-r--r-- | drivers/tty/serial/sh-sci.h | 2 |
2 files changed, 132 insertions, 151 deletions
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 1a3fc7a2e4db..e4bf0e435af6 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c | |||
| @@ -23,35 +23,34 @@ | |||
| 23 | 23 | ||
| 24 | #undef DEBUG | 24 | #undef DEBUG |
| 25 | 25 | ||
| 26 | #include <linux/module.h> | 26 | #include <linux/clk.h> |
| 27 | #include <linux/console.h> | ||
| 28 | #include <linux/ctype.h> | ||
| 29 | #include <linux/cpufreq.h> | ||
| 30 | #include <linux/delay.h> | ||
| 31 | #include <linux/dmaengine.h> | ||
| 32 | #include <linux/dma-mapping.h> | ||
| 33 | #include <linux/err.h> | ||
| 27 | #include <linux/errno.h> | 34 | #include <linux/errno.h> |
| 28 | #include <linux/sh_dma.h> | 35 | #include <linux/init.h> |
| 29 | #include <linux/timer.h> | ||
| 30 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
| 31 | #include <linux/tty.h> | ||
| 32 | #include <linux/tty_flip.h> | ||
| 33 | #include <linux/serial.h> | ||
| 34 | #include <linux/major.h> | ||
| 35 | #include <linux/string.h> | ||
| 36 | #include <linux/sysrq.h> | ||
| 37 | #include <linux/ioport.h> | 37 | #include <linux/ioport.h> |
| 38 | #include <linux/major.h> | ||
| 39 | #include <linux/module.h> | ||
| 38 | #include <linux/mm.h> | 40 | #include <linux/mm.h> |
| 39 | #include <linux/init.h> | ||
| 40 | #include <linux/delay.h> | ||
| 41 | #include <linux/console.h> | ||
| 42 | #include <linux/platform_device.h> | ||
| 43 | #include <linux/serial_sci.h> | ||
| 44 | #include <linux/notifier.h> | 41 | #include <linux/notifier.h> |
| 42 | #include <linux/platform_device.h> | ||
| 45 | #include <linux/pm_runtime.h> | 43 | #include <linux/pm_runtime.h> |
| 46 | #include <linux/cpufreq.h> | ||
| 47 | #include <linux/clk.h> | ||
| 48 | #include <linux/ctype.h> | ||
| 49 | #include <linux/err.h> | ||
| 50 | #include <linux/dmaengine.h> | ||
| 51 | #include <linux/dma-mapping.h> | ||
| 52 | #include <linux/scatterlist.h> | 44 | #include <linux/scatterlist.h> |
| 45 | #include <linux/serial.h> | ||
| 46 | #include <linux/serial_sci.h> | ||
| 47 | #include <linux/sh_dma.h> | ||
| 53 | #include <linux/slab.h> | 48 | #include <linux/slab.h> |
| 54 | #include <linux/gpio.h> | 49 | #include <linux/string.h> |
| 50 | #include <linux/sysrq.h> | ||
| 51 | #include <linux/timer.h> | ||
| 52 | #include <linux/tty.h> | ||
| 53 | #include <linux/tty_flip.h> | ||
| 55 | 54 | ||
| 56 | #ifdef CONFIG_SUPERH | 55 | #ifdef CONFIG_SUPERH |
| 57 | #include <asm/sh_bios.h> | 56 | #include <asm/sh_bios.h> |
| @@ -64,6 +63,10 @@ struct sci_port { | |||
| 64 | 63 | ||
| 65 | /* Platform configuration */ | 64 | /* Platform configuration */ |
| 66 | struct plat_sci_port *cfg; | 65 | struct plat_sci_port *cfg; |
| 66 | int overrun_bit; | ||
| 67 | unsigned int error_mask; | ||
| 68 | unsigned int sampling_rate; | ||
| 69 | |||
| 67 | 70 | ||
| 68 | /* Break timer */ | 71 | /* Break timer */ |
| 69 | struct timer_list break_timer; | 72 | struct timer_list break_timer; |
| @@ -74,8 +77,8 @@ struct sci_port { | |||
| 74 | /* Function clock */ | 77 | /* Function clock */ |
| 75 | struct clk *fclk; | 78 | struct clk *fclk; |
| 76 | 79 | ||
| 80 | int irqs[SCIx_NR_IRQS]; | ||
| 77 | char *irqstr[SCIx_NR_IRQS]; | 81 | char *irqstr[SCIx_NR_IRQS]; |
| 78 | char *gpiostr[SCIx_NR_FNS]; | ||
| 79 | 82 | ||
| 80 | struct dma_chan *chan_tx; | 83 | struct dma_chan *chan_tx; |
| 81 | struct dma_chan *chan_rx; | 84 | struct dma_chan *chan_rx; |
| @@ -759,19 +762,15 @@ static int sci_handle_errors(struct uart_port *port) | |||
| 759 | struct tty_port *tport = &port->state->port; | 762 | struct tty_port *tport = &port->state->port; |
| 760 | struct sci_port *s = to_sci_port(port); | 763 | struct sci_port *s = to_sci_port(port); |
| 761 | 764 | ||
| 762 | /* | 765 | /* Handle overruns */ |
| 763 | * Handle overruns, if supported. | 766 | if (status & (1 << s->overrun_bit)) { |
| 764 | */ | 767 | port->icount.overrun++; |
| 765 | if (s->cfg->overrun_bit != SCIx_NOT_SUPPORTED) { | ||
| 766 | if (status & (1 << s->cfg->overrun_bit)) { | ||
| 767 | port->icount.overrun++; | ||
| 768 | 768 | ||
| 769 | /* overrun error */ | 769 | /* overrun error */ |
| 770 | if (tty_insert_flip_char(tport, 0, TTY_OVERRUN)) | 770 | if (tty_insert_flip_char(tport, 0, TTY_OVERRUN)) |
| 771 | copied++; | 771 | copied++; |
| 772 | 772 | ||
| 773 | dev_notice(port->dev, "overrun error"); | 773 | dev_notice(port->dev, "overrun error"); |
| 774 | } | ||
| 775 | } | 774 | } |
| 776 | 775 | ||
| 777 | if (status & SCxSR_FER(port)) { | 776 | if (status & SCxSR_FER(port)) { |
| @@ -833,7 +832,7 @@ static int sci_handle_fifo_overrun(struct uart_port *port) | |||
| 833 | if (!reg->size) | 832 | if (!reg->size) |
| 834 | return 0; | 833 | return 0; |
| 835 | 834 | ||
| 836 | if ((serial_port_in(port, SCLSR) & (1 << s->cfg->overrun_bit))) { | 835 | if ((serial_port_in(port, SCLSR) & (1 << s->overrun_bit))) { |
| 837 | serial_port_out(port, SCLSR, 0); | 836 | serial_port_out(port, SCLSR, 0); |
| 838 | 837 | ||
| 839 | port->icount.overrun++; | 838 | port->icount.overrun++; |
| @@ -1079,19 +1078,19 @@ static int sci_request_irq(struct sci_port *port) | |||
| 1079 | 1078 | ||
| 1080 | for (i = j = 0; i < SCIx_NR_IRQS; i++, j++) { | 1079 | for (i = j = 0; i < SCIx_NR_IRQS; i++, j++) { |
| 1081 | struct sci_irq_desc *desc; | 1080 | struct sci_irq_desc *desc; |
| 1082 | unsigned int irq; | 1081 | int irq; |
| 1083 | 1082 | ||
| 1084 | if (SCIx_IRQ_IS_MUXED(port)) { | 1083 | if (SCIx_IRQ_IS_MUXED(port)) { |
| 1085 | i = SCIx_MUX_IRQ; | 1084 | i = SCIx_MUX_IRQ; |
| 1086 | irq = up->irq; | 1085 | irq = up->irq; |
| 1087 | } else { | 1086 | } else { |
| 1088 | irq = port->cfg->irqs[i]; | 1087 | irq = port->irqs[i]; |
| 1089 | 1088 | ||
| 1090 | /* | 1089 | /* |
| 1091 | * Certain port types won't support all of the | 1090 | * Certain port types won't support all of the |
| 1092 | * available interrupt sources. | 1091 | * available interrupt sources. |
| 1093 | */ | 1092 | */ |
| 1094 | if (unlikely(!irq)) | 1093 | if (unlikely(irq < 0)) |
| 1095 | continue; | 1094 | continue; |
| 1096 | } | 1095 | } |
| 1097 | 1096 | ||
| @@ -1116,7 +1115,7 @@ static int sci_request_irq(struct sci_port *port) | |||
| 1116 | 1115 | ||
| 1117 | out_noirq: | 1116 | out_noirq: |
| 1118 | while (--i >= 0) | 1117 | while (--i >= 0) |
| 1119 | free_irq(port->cfg->irqs[i], port); | 1118 | free_irq(port->irqs[i], port); |
| 1120 | 1119 | ||
| 1121 | out_nomem: | 1120 | out_nomem: |
| 1122 | while (--j >= 0) | 1121 | while (--j >= 0) |
| @@ -1134,16 +1133,16 @@ static void sci_free_irq(struct sci_port *port) | |||
| 1134 | * IRQ first. | 1133 | * IRQ first. |
| 1135 | */ | 1134 | */ |
| 1136 | for (i = 0; i < SCIx_NR_IRQS; i++) { | 1135 | for (i = 0; i < SCIx_NR_IRQS; i++) { |
| 1137 | unsigned int irq = port->cfg->irqs[i]; | 1136 | int irq = port->irqs[i]; |
| 1138 | 1137 | ||
| 1139 | /* | 1138 | /* |
| 1140 | * Certain port types won't support all of the available | 1139 | * Certain port types won't support all of the available |
| 1141 | * interrupt sources. | 1140 | * interrupt sources. |
| 1142 | */ | 1141 | */ |
| 1143 | if (unlikely(!irq)) | 1142 | if (unlikely(irq < 0)) |
| 1144 | continue; | 1143 | continue; |
| 1145 | 1144 | ||
| 1146 | free_irq(port->cfg->irqs[i], port); | 1145 | free_irq(port->irqs[i], port); |
| 1147 | kfree(port->irqstr[i]); | 1146 | kfree(port->irqstr[i]); |
| 1148 | 1147 | ||
| 1149 | if (SCIx_IRQ_IS_MUXED(port)) { | 1148 | if (SCIx_IRQ_IS_MUXED(port)) { |
| @@ -1153,67 +1152,6 @@ static void sci_free_irq(struct sci_port *port) | |||
| 1153 | } | 1152 | } |
| 1154 | } | 1153 | } |
| 1155 | 1154 | ||
| 1156 | static const char *sci_gpio_names[SCIx_NR_FNS] = { | ||
| 1157 | "sck", "rxd", "txd", "cts", "rts", | ||
| 1158 | }; | ||
| 1159 | |||
| 1160 | static const char *sci_gpio_str(unsigned int index) | ||
| 1161 | { | ||
| 1162 | return sci_gpio_names[index]; | ||
| 1163 | } | ||
| 1164 | |||
| 1165 | static void sci_init_gpios(struct sci_port *port) | ||
| 1166 | { | ||
| 1167 | struct uart_port *up = &port->port; | ||
| 1168 | int i; | ||
| 1169 | |||
| 1170 | if (!port->cfg) | ||
| 1171 | return; | ||
| 1172 | |||
| 1173 | for (i = 0; i < SCIx_NR_FNS; i++) { | ||
| 1174 | const char *desc; | ||
| 1175 | int ret; | ||
| 1176 | |||
| 1177 | if (!port->cfg->gpios[i]) | ||
| 1178 | continue; | ||
| 1179 | |||
| 1180 | desc = sci_gpio_str(i); | ||
| 1181 | |||
| 1182 | port->gpiostr[i] = kasprintf(GFP_KERNEL, "%s:%s", | ||
| 1183 | dev_name(up->dev), desc); | ||
| 1184 | |||
| 1185 | /* | ||
| 1186 | * If we've failed the allocation, we can still continue | ||
| 1187 | * on with a NULL string. | ||
| 1188 | */ | ||
| 1189 | if (!port->gpiostr[i]) | ||
| 1190 | dev_notice(up->dev, "%s string allocation failure\n", | ||
| 1191 | desc); | ||
| 1192 | |||
| 1193 | ret = gpio_request(port->cfg->gpios[i], port->gpiostr[i]); | ||
| 1194 | if (unlikely(ret != 0)) { | ||
| 1195 | dev_notice(up->dev, "failed %s gpio request\n", desc); | ||
| 1196 | |||
| 1197 | /* | ||
| 1198 | * If we can't get the GPIO for whatever reason, | ||
| 1199 | * no point in keeping the verbose string around. | ||
| 1200 | */ | ||
| 1201 | kfree(port->gpiostr[i]); | ||
| 1202 | } | ||
| 1203 | } | ||
| 1204 | } | ||
| 1205 | |||
| 1206 | static void sci_free_gpios(struct sci_port *port) | ||
| 1207 | { | ||
| 1208 | int i; | ||
| 1209 | |||
| 1210 | for (i = 0; i < SCIx_NR_FNS; i++) | ||
| 1211 | if (port->cfg->gpios[i]) { | ||
| 1212 | gpio_free(port->cfg->gpios[i]); | ||
| 1213 | kfree(port->gpiostr[i]); | ||
| 1214 | } | ||
| 1215 | } | ||
| 1216 | |||
| 1217 | static unsigned int sci_tx_empty(struct uart_port *port) | 1155 | static unsigned int sci_tx_empty(struct uart_port *port) |
| 1218 | { | 1156 | { |
| 1219 | unsigned short status = serial_port_in(port, SCxSR); | 1157 | unsigned short status = serial_port_in(port, SCxSR); |
| @@ -1659,7 +1597,7 @@ static void rx_timer_fn(unsigned long arg) | |||
| 1659 | 1597 | ||
| 1660 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { | 1598 | if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) { |
| 1661 | scr &= ~0x4000; | 1599 | scr &= ~0x4000; |
| 1662 | enable_irq(s->cfg->irqs[1]); | 1600 | enable_irq(s->irqs[SCIx_RXI_IRQ]); |
| 1663 | } | 1601 | } |
| 1664 | serial_port_out(port, SCSCR, scr | SCSCR_RIE); | 1602 | serial_port_out(port, SCSCR, scr | SCSCR_RIE); |
| 1665 | dev_dbg(port->dev, "DMA Rx timed out\n"); | 1603 | dev_dbg(port->dev, "DMA Rx timed out\n"); |
| @@ -1813,20 +1751,21 @@ static void sci_shutdown(struct uart_port *port) | |||
| 1813 | sci_free_irq(s); | 1751 | sci_free_irq(s); |
| 1814 | } | 1752 | } |
| 1815 | 1753 | ||
| 1816 | static unsigned int sci_scbrr_calc(unsigned int algo_id, unsigned int bps, | 1754 | static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps, |
| 1817 | unsigned long freq) | 1755 | unsigned long freq) |
| 1818 | { | 1756 | { |
| 1819 | switch (algo_id) { | 1757 | if (s->sampling_rate) |
| 1758 | return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1; | ||
| 1759 | |||
| 1760 | switch (s->cfg->scbrr_algo_id) { | ||
| 1820 | case SCBRR_ALGO_1: | 1761 | case SCBRR_ALGO_1: |
| 1821 | return ((freq + 16 * bps) / (16 * bps) - 1); | 1762 | return freq / (16 * bps); |
| 1822 | case SCBRR_ALGO_2: | 1763 | case SCBRR_ALGO_2: |
| 1823 | return ((freq + 16 * bps) / (32 * bps) - 1); | 1764 | return DIV_ROUND_CLOSEST(freq, 32 * bps) - 1; |
| 1824 | case SCBRR_ALGO_3: | 1765 | case SCBRR_ALGO_3: |
| 1825 | return (((freq * 2) + 16 * bps) / (16 * bps) - 1); | 1766 | return freq / (8 * bps); |
| 1826 | case SCBRR_ALGO_4: | 1767 | case SCBRR_ALGO_4: |
| 1827 | return (((freq * 2) + 16 * bps) / (32 * bps) - 1); | 1768 | return DIV_ROUND_CLOSEST(freq, 16 * bps) - 1; |
| 1828 | case SCBRR_ALGO_5: | ||
| 1829 | return (((freq * 1000 / 32) / bps) - 1); | ||
| 1830 | } | 1769 | } |
| 1831 | 1770 | ||
| 1832 | /* Warn, but use a safe default */ | 1771 | /* Warn, but use a safe default */ |
| @@ -1908,12 +1847,11 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, | |||
| 1908 | 1847 | ||
| 1909 | baud = uart_get_baud_rate(port, termios, old, 0, max_baud); | 1848 | baud = uart_get_baud_rate(port, termios, old, 0, max_baud); |
| 1910 | if (likely(baud && port->uartclk)) { | 1849 | if (likely(baud && port->uartclk)) { |
| 1911 | if (s->cfg->scbrr_algo_id == SCBRR_ALGO_6) { | 1850 | if (s->cfg->type == PORT_HSCIF) { |
| 1912 | sci_baud_calc_hscif(baud, port->uartclk, &t, &srr, | 1851 | sci_baud_calc_hscif(baud, port->uartclk, &t, &srr, |
| 1913 | &cks); | 1852 | &cks); |
| 1914 | } else { | 1853 | } else { |
| 1915 | t = sci_scbrr_calc(s->cfg->scbrr_algo_id, baud, | 1854 | t = sci_scbrr_calc(s, baud, port->uartclk); |
| 1916 | port->uartclk); | ||
| 1917 | for (cks = 0; t >= 256 && cks <= 3; cks++) | 1855 | for (cks = 0; t >= 256 && cks <= 3; cks++) |
| 1918 | t >>= 2; | 1856 | t >>= 2; |
| 1919 | } | 1857 | } |
| @@ -2120,10 +2058,6 @@ static void sci_config_port(struct uart_port *port, int flags) | |||
| 2120 | 2058 | ||
| 2121 | static int sci_verify_port(struct uart_port *port, struct serial_struct *ser) | 2059 | static int sci_verify_port(struct uart_port *port, struct serial_struct *ser) |
| 2122 | { | 2060 | { |
| 2123 | struct sci_port *s = to_sci_port(port); | ||
| 2124 | |||
| 2125 | if (ser->irq != s->cfg->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs) | ||
| 2126 | return -EINVAL; | ||
| 2127 | if (ser->baud_base < 2400) | 2061 | if (ser->baud_base < 2400) |
| 2128 | /* No paper tape reader for Mitch.. */ | 2062 | /* No paper tape reader for Mitch.. */ |
| 2129 | return -EINVAL; | 2063 | return -EINVAL; |
| @@ -2156,11 +2090,13 @@ static struct uart_ops sci_uart_ops = { | |||
| 2156 | }; | 2090 | }; |
| 2157 | 2091 | ||
| 2158 | static int sci_init_single(struct platform_device *dev, | 2092 | static int sci_init_single(struct platform_device *dev, |
| 2159 | struct sci_port *sci_port, | 2093 | struct sci_port *sci_port, unsigned int index, |
| 2160 | unsigned int index, | 2094 | struct plat_sci_port *p, bool early) |
| 2161 | struct plat_sci_port *p) | ||
| 2162 | { | 2095 | { |
| 2163 | struct uart_port *port = &sci_port->port; | 2096 | struct uart_port *port = &sci_port->port; |
| 2097 | const struct resource *res; | ||
| 2098 | unsigned int sampling_rate; | ||
| 2099 | unsigned int i; | ||
| 2164 | int ret; | 2100 | int ret; |
| 2165 | 2101 | ||
| 2166 | sci_port->cfg = p; | 2102 | sci_port->cfg = p; |
| @@ -2169,31 +2105,90 @@ static int sci_init_single(struct platform_device *dev, | |||
| 2169 | port->iotype = UPIO_MEM; | 2105 | port->iotype = UPIO_MEM; |
| 2170 | port->line = index; | 2106 | port->line = index; |
| 2171 | 2107 | ||
| 2108 | if (dev->num_resources) { | ||
| 2109 | /* Device has resources, use them. */ | ||
| 2110 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
| 2111 | if (res == NULL) | ||
| 2112 | return -ENOMEM; | ||
| 2113 | |||
| 2114 | port->mapbase = res->start; | ||
| 2115 | |||
| 2116 | for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i) | ||
| 2117 | sci_port->irqs[i] = platform_get_irq(dev, i); | ||
| 2118 | |||
| 2119 | /* The SCI generates several interrupts. They can be muxed | ||
| 2120 | * together or connected to different interrupt lines. In the | ||
| 2121 | * muxed case only one interrupt resource is specified. In the | ||
| 2122 | * non-muxed case three or four interrupt resources are | ||
| 2123 | * specified, as the BRI interrupt is optional. | ||
| 2124 | */ | ||
| 2125 | if (sci_port->irqs[0] < 0) | ||
| 2126 | return -ENXIO; | ||
| 2127 | |||
| 2128 | if (sci_port->irqs[1] < 0) { | ||
| 2129 | sci_port->irqs[1] = sci_port->irqs[0]; | ||
| 2130 | sci_port->irqs[2] = sci_port->irqs[0]; | ||
| 2131 | sci_port->irqs[3] = sci_port->irqs[0]; | ||
| 2132 | } | ||
| 2133 | } else { | ||
| 2134 | /* No resources, use old-style platform data. */ | ||
| 2135 | port->mapbase = p->mapbase; | ||
| 2136 | for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i) | ||
| 2137 | sci_port->irqs[i] = p->irqs[i] ? p->irqs[i] : -ENXIO; | ||
| 2138 | } | ||
| 2139 | |||
| 2140 | if (p->regtype == SCIx_PROBE_REGTYPE) { | ||
| 2141 | ret = sci_probe_regmap(p); | ||
| 2142 | if (unlikely(ret)) | ||
| 2143 | return ret; | ||
| 2144 | } | ||
| 2145 | |||
| 2172 | switch (p->type) { | 2146 | switch (p->type) { |
| 2173 | case PORT_SCIFB: | 2147 | case PORT_SCIFB: |
| 2174 | port->fifosize = 256; | 2148 | port->fifosize = 256; |
| 2149 | sci_port->overrun_bit = 9; | ||
| 2150 | sampling_rate = 16; | ||
| 2175 | break; | 2151 | break; |
| 2176 | case PORT_HSCIF: | 2152 | case PORT_HSCIF: |
| 2177 | port->fifosize = 128; | 2153 | port->fifosize = 128; |
| 2154 | sampling_rate = 0; | ||
| 2155 | sci_port->overrun_bit = 0; | ||
| 2178 | break; | 2156 | break; |
| 2179 | case PORT_SCIFA: | 2157 | case PORT_SCIFA: |
| 2180 | port->fifosize = 64; | 2158 | port->fifosize = 64; |
| 2159 | sci_port->overrun_bit = 9; | ||
| 2160 | sampling_rate = 16; | ||
| 2181 | break; | 2161 | break; |
| 2182 | case PORT_SCIF: | 2162 | case PORT_SCIF: |
| 2183 | port->fifosize = 16; | 2163 | port->fifosize = 16; |
| 2164 | if (p->regtype == SCIx_SH7705_SCIF_REGTYPE) { | ||
| 2165 | sci_port->overrun_bit = 9; | ||
| 2166 | sampling_rate = 16; | ||
| 2167 | } else { | ||
| 2168 | sci_port->overrun_bit = 0; | ||
| 2169 | sampling_rate = 32; | ||
| 2170 | } | ||
| 2184 | break; | 2171 | break; |
| 2185 | default: | 2172 | default: |
| 2186 | port->fifosize = 1; | 2173 | port->fifosize = 1; |
| 2174 | sci_port->overrun_bit = 5; | ||
| 2175 | sampling_rate = 32; | ||
| 2187 | break; | 2176 | break; |
| 2188 | } | 2177 | } |
| 2189 | 2178 | ||
| 2190 | if (p->regtype == SCIx_PROBE_REGTYPE) { | 2179 | /* Set the sampling rate if the baud rate calculation algorithm isn't |
| 2191 | ret = sci_probe_regmap(p); | 2180 | * specified. |
| 2192 | if (unlikely(ret)) | 2181 | */ |
| 2193 | return ret; | 2182 | if (p->scbrr_algo_id == SCBRR_ALGO_NONE) { |
| 2183 | /* SCIFA on sh7723 and sh7724 need a custom sampling rate that | ||
| 2184 | * doesn't match the SoC datasheet, this should be investigated. | ||
| 2185 | * Let platform data override the sampling rate for now. | ||
| 2186 | */ | ||
| 2187 | sci_port->sampling_rate = p->sampling_rate ? p->sampling_rate | ||
| 2188 | : sampling_rate; | ||
| 2194 | } | 2189 | } |
| 2195 | 2190 | ||
| 2196 | if (dev) { | 2191 | if (!early) { |
| 2197 | sci_port->iclk = clk_get(&dev->dev, "sci_ick"); | 2192 | sci_port->iclk = clk_get(&dev->dev, "sci_ick"); |
| 2198 | if (IS_ERR(sci_port->iclk)) { | 2193 | if (IS_ERR(sci_port->iclk)) { |
| 2199 | sci_port->iclk = clk_get(&dev->dev, "peripheral_clk"); | 2194 | sci_port->iclk = clk_get(&dev->dev, "peripheral_clk"); |
| @@ -2213,8 +2208,6 @@ static int sci_init_single(struct platform_device *dev, | |||
| 2213 | 2208 | ||
| 2214 | port->dev = &dev->dev; | 2209 | port->dev = &dev->dev; |
| 2215 | 2210 | ||
| 2216 | sci_init_gpios(sci_port); | ||
| 2217 | |||
| 2218 | pm_runtime_enable(&dev->dev); | 2211 | pm_runtime_enable(&dev->dev); |
| 2219 | } | 2212 | } |
| 2220 | 2213 | ||
| @@ -2225,32 +2218,22 @@ static int sci_init_single(struct platform_device *dev, | |||
| 2225 | /* | 2218 | /* |
| 2226 | * Establish some sensible defaults for the error detection. | 2219 | * Establish some sensible defaults for the error detection. |
| 2227 | */ | 2220 | */ |
| 2228 | if (!p->error_mask) | 2221 | sci_port->error_mask = (p->type == PORT_SCI) ? |
| 2229 | p->error_mask = (p->type == PORT_SCI) ? | ||
| 2230 | SCI_DEFAULT_ERROR_MASK : SCIF_DEFAULT_ERROR_MASK; | 2222 | SCI_DEFAULT_ERROR_MASK : SCIF_DEFAULT_ERROR_MASK; |
| 2231 | 2223 | ||
| 2232 | /* | 2224 | /* |
| 2233 | * Establish sensible defaults for the overrun detection, unless | 2225 | * Establish sensible defaults for the overrun detection, unless |
| 2234 | * the part has explicitly disabled support for it. | 2226 | * the part has explicitly disabled support for it. |
| 2235 | */ | 2227 | */ |
| 2236 | if (p->overrun_bit != SCIx_NOT_SUPPORTED) { | ||
| 2237 | if (p->type == PORT_SCI) | ||
| 2238 | p->overrun_bit = 5; | ||
| 2239 | else if (p->scbrr_algo_id == SCBRR_ALGO_4) | ||
| 2240 | p->overrun_bit = 9; | ||
| 2241 | else | ||
| 2242 | p->overrun_bit = 0; | ||
| 2243 | 2228 | ||
| 2244 | /* | 2229 | /* |
| 2245 | * Make the error mask inclusive of overrun detection, if | 2230 | * Make the error mask inclusive of overrun detection, if |
| 2246 | * supported. | 2231 | * supported. |
| 2247 | */ | 2232 | */ |
| 2248 | p->error_mask |= (1 << p->overrun_bit); | 2233 | sci_port->error_mask |= 1 << sci_port->overrun_bit; |
| 2249 | } | ||
| 2250 | 2234 | ||
| 2251 | port->mapbase = p->mapbase; | ||
| 2252 | port->type = p->type; | 2235 | port->type = p->type; |
| 2253 | port->flags = p->flags; | 2236 | port->flags = UPF_FIXED_PORT | p->flags; |
| 2254 | port->regshift = p->regshift; | 2237 | port->regshift = p->regshift; |
| 2255 | 2238 | ||
| 2256 | /* | 2239 | /* |
| @@ -2260,7 +2243,7 @@ static int sci_init_single(struct platform_device *dev, | |||
| 2260 | * | 2243 | * |
| 2261 | * For the muxed case there's nothing more to do. | 2244 | * For the muxed case there's nothing more to do. |
| 2262 | */ | 2245 | */ |
| 2263 | port->irq = p->irqs[SCIx_RXI_IRQ]; | 2246 | port->irq = sci_port->irqs[SCIx_RXI_IRQ]; |
| 2264 | port->irqflags = 0; | 2247 | port->irqflags = 0; |
| 2265 | 2248 | ||
| 2266 | port->serial_in = sci_serial_in; | 2249 | port->serial_in = sci_serial_in; |
| @@ -2275,8 +2258,6 @@ static int sci_init_single(struct platform_device *dev, | |||
| 2275 | 2258 | ||
| 2276 | static void sci_cleanup_single(struct sci_port *port) | 2259 | static void sci_cleanup_single(struct sci_port *port) |
| 2277 | { | 2260 | { |
| 2278 | sci_free_gpios(port); | ||
| 2279 | |||
| 2280 | clk_put(port->iclk); | 2261 | clk_put(port->iclk); |
| 2281 | clk_put(port->fclk); | 2262 | clk_put(port->fclk); |
| 2282 | 2263 | ||
| @@ -2392,7 +2373,7 @@ static int sci_probe_earlyprintk(struct platform_device *pdev) | |||
| 2392 | 2373 | ||
| 2393 | early_serial_console.index = pdev->id; | 2374 | early_serial_console.index = pdev->id; |
| 2394 | 2375 | ||
| 2395 | sci_init_single(NULL, &sci_ports[pdev->id], pdev->id, cfg); | 2376 | sci_init_single(pdev, &sci_ports[pdev->id], pdev->id, cfg, true); |
| 2396 | 2377 | ||
| 2397 | serial_console_setup(&early_serial_console, early_serial_buf); | 2378 | serial_console_setup(&early_serial_console, early_serial_buf); |
| 2398 | 2379 | ||
| @@ -2459,7 +2440,7 @@ static int sci_probe_single(struct platform_device *dev, | |||
| 2459 | return -EINVAL; | 2440 | return -EINVAL; |
| 2460 | } | 2441 | } |
| 2461 | 2442 | ||
| 2462 | ret = sci_init_single(dev, sciport, index, p); | 2443 | ret = sci_init_single(dev, sciport, index, p, false); |
| 2463 | if (ret) | 2444 | if (ret) |
| 2464 | return ret; | 2445 | return ret; |
| 2465 | 2446 | ||
diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h index 5aca7364634c..d5db81a0a430 100644 --- a/drivers/tty/serial/sh-sci.h +++ b/drivers/tty/serial/sh-sci.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER) | 9 | #define SCxSR_PER(port) (((port)->type == PORT_SCI) ? SCI_PER : SCIF_PER) |
| 10 | #define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK) | 10 | #define SCxSR_BRK(port) (((port)->type == PORT_SCI) ? 0x00 : SCIF_BRK) |
| 11 | 11 | ||
| 12 | #define SCxSR_ERRORS(port) (to_sci_port(port)->cfg->error_mask) | 12 | #define SCxSR_ERRORS(port) (to_sci_port(port)->error_mask) |
| 13 | 13 | ||
| 14 | #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \ | 14 | #if defined(CONFIG_CPU_SUBTYPE_SH7705) || \ |
| 15 | defined(CONFIG_CPU_SUBTYPE_SH7720) || \ | 15 | defined(CONFIG_CPU_SUBTYPE_SH7720) || \ |
