Blame view

drivers/ssb/driver_extif.c 5 KB
61e115a56   Michael Buesch   [SSB]: add Sonics...
1
2
3
4
5
  /*
   * Sonics Silicon Backplane
   * Broadcom EXTIF core driver
   *
   * Copyright 2005, Broadcom Corporation
eb032b983   Michael Buesch   Update my e-mail ...
6
   * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
61e115a56   Michael Buesch   [SSB]: add Sonics...
7
8
9
10
11
   * Copyright 2006, 2007, Felix Fietkau <nbd@openwrt.org>
   * Copyright 2007, Aurelien Jarno <aurelien@aurel32.net>
   *
   * Licensed under the GNU/GPL. See COPYING for details.
   */
b8b6069cf   Michael Buesch   ssb: Remove home-...
12
  #include "ssb_private.h"
61e115a56   Michael Buesch   [SSB]: add Sonics...
13
14
15
  #include <linux/serial.h>
  #include <linux/serial_core.h>
  #include <linux/serial_reg.h>
61e115a56   Michael Buesch   [SSB]: add Sonics...
16
17
18
19
20
21
22
23
24
25
  
  static inline u32 extif_read32(struct ssb_extif *extif, u16 offset)
  {
  	return ssb_read32(extif->dev, offset);
  }
  
  static inline void extif_write32(struct ssb_extif *extif, u16 offset, u32 value)
  {
  	ssb_write32(extif->dev, offset, value);
  }
c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
26
27
  static inline u32 extif_write32_masked(struct ssb_extif *extif, u16 offset,
  				       u32 mask, u32 value)
61e115a56   Michael Buesch   [SSB]: add Sonics...
28
29
30
31
  {
  	value &= mask;
  	value |= extif_read32(extif, offset) & ~mask;
  	extif_write32(extif, offset, value);
c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
32
33
  
  	return value;
61e115a56   Michael Buesch   [SSB]: add Sonics...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  }
  
  #ifdef CONFIG_SSB_SERIAL
  static bool serial_exists(u8 *regs)
  {
  	u8 save_mcr, msr = 0;
  
  	if (regs) {
  		save_mcr = regs[UART_MCR];
  		regs[UART_MCR] = (UART_MCR_LOOP | UART_MCR_OUT2 | UART_MCR_RTS);
  		msr = regs[UART_MSR] & (UART_MSR_DCD | UART_MSR_RI
  					| UART_MSR_CTS | UART_MSR_DSR);
  		regs[UART_MCR] = save_mcr;
  	}
  	return (msr == (UART_MSR_DCD | UART_MSR_CTS));
  }
  
  int ssb_extif_serial_init(struct ssb_extif *extif, struct ssb_serial_port *ports)
  {
  	u32 i, nr_ports = 0;
  
  	/* Disable GPIO interrupt initially */
  	extif_write32(extif, SSB_EXTIF_GPIO_INTPOL, 0);
  	extif_write32(extif, SSB_EXTIF_GPIO_INTMASK, 0);
  
  	for (i = 0; i < 2; i++) {
  		void __iomem *uart_regs;
4bdc0d676   Christoph Hellwig   remove ioremap_no...
61
  		uart_regs = ioremap(SSB_EUART, 16);
61e115a56   Michael Buesch   [SSB]: add Sonics...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  		if (uart_regs) {
  			uart_regs += (i * 8);
  
  			if (serial_exists(uart_regs) && ports) {
  				extif_write32(extif, SSB_EXTIF_GPIO_INTMASK, 2);
  
  				nr_ports++;
  				ports[i].regs = uart_regs;
  				ports[i].irq = 2;
  				ports[i].baud_base = 13500000;
  				ports[i].reg_shift = 0;
  			}
  			iounmap(uart_regs);
  		}
  	}
  	return nr_ports;
  }
  #endif /* CONFIG_SSB_SERIAL */
  
  void ssb_extif_timing_init(struct ssb_extif *extif, unsigned long ns)
  {
  	u32 tmp;
  
  	/* Initialize extif so we can get to the LEDs and external UART */
  	extif_write32(extif, SSB_EXTIF_PROG_CFG, SSB_EXTCFG_EN);
  
  	/* Set timing for the flash */
  	tmp  = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT;
  	tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT;
  	tmp |= DIV_ROUND_UP(120, ns);
  	extif_write32(extif, SSB_EXTIF_PROG_WAITCNT, tmp);
  
  	/* Set programmable interface timing for external uart */
  	tmp  = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT;
  	tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT;
  	tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT;
  	tmp |= DIV_ROUND_UP(120, ns);
  	extif_write32(extif, SSB_EXTIF_PROG_WAITCNT, tmp);
  }
  
  void ssb_extif_get_clockcontrol(struct ssb_extif *extif,
  				u32 *pll_type, u32 *n, u32 *m)
  {
  	*pll_type = SSB_PLLTYPE_1;
  	*n = extif_read32(extif, SSB_EXTIF_CLOCK_N);
  	*m = extif_read32(extif, SSB_EXTIF_CLOCK_SB);
  }
9f640a637   Hauke Mehrtens   ssb: extif: add m...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  u32 ssb_extif_watchdog_timer_set_wdt(struct bcm47xx_wdt *wdt, u32 ticks)
  {
  	struct ssb_extif *extif = bcm47xx_wdt_get_drvdata(wdt);
  
  	return ssb_extif_watchdog_timer_set(extif, ticks);
  }
  
  u32 ssb_extif_watchdog_timer_set_ms(struct bcm47xx_wdt *wdt, u32 ms)
  {
  	struct ssb_extif *extif = bcm47xx_wdt_get_drvdata(wdt);
  	u32 ticks = (SSB_EXTIF_WATCHDOG_CLK / 1000) * ms;
  
  	ticks = ssb_extif_watchdog_timer_set(extif, ticks);
  
  	return (ticks * 1000) / SSB_EXTIF_WATCHDOG_CLK;
  }
  
  u32 ssb_extif_watchdog_timer_set(struct ssb_extif *extif, u32 ticks)
42bfad4f7   Michael Buesch   ssb: Fix watchdog...
127
  {
7280b51a2   Hauke Mehrtens   ssb: extif: add c...
128
129
  	if (ticks > SSB_EXTIF_WATCHDOG_MAX_TIMER)
  		ticks = SSB_EXTIF_WATCHDOG_MAX_TIMER;
42bfad4f7   Michael Buesch   ssb: Fix watchdog...
130
  	extif_write32(extif, SSB_EXTIF_WATCHDOG, ticks);
9f640a637   Hauke Mehrtens   ssb: extif: add m...
131
132
  
  	return ticks;
42bfad4f7   Michael Buesch   ssb: Fix watchdog...
133
  }
394bc7e38   Hauke Mehrtens   ssb: add locking ...
134
135
136
137
138
139
  void ssb_extif_init(struct ssb_extif *extif)
  {
  	if (!extif->dev)
  		return; /* We don't have a Extif core */
  	spin_lock_init(&extif->gpio_lock);
  }
61e115a56   Michael Buesch   [SSB]: add Sonics...
140
141
142
143
  u32 ssb_extif_gpio_in(struct ssb_extif *extif, u32 mask)
  {
  	return extif_read32(extif, SSB_EXTIF_GPIO_IN) & mask;
  }
c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
144
  u32 ssb_extif_gpio_out(struct ssb_extif *extif, u32 mask, u32 value)
61e115a56   Michael Buesch   [SSB]: add Sonics...
145
  {
394bc7e38   Hauke Mehrtens   ssb: add locking ...
146
147
148
149
150
  	unsigned long flags;
  	u32 res = 0;
  
  	spin_lock_irqsave(&extif->gpio_lock, flags);
  	res = extif_write32_masked(extif, SSB_EXTIF_GPIO_OUT(0),
61e115a56   Michael Buesch   [SSB]: add Sonics...
151
  				   mask, value);
394bc7e38   Hauke Mehrtens   ssb: add locking ...
152
153
154
  	spin_unlock_irqrestore(&extif->gpio_lock, flags);
  
  	return res;
61e115a56   Michael Buesch   [SSB]: add Sonics...
155
  }
c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
156
  u32 ssb_extif_gpio_outen(struct ssb_extif *extif, u32 mask, u32 value)
61e115a56   Michael Buesch   [SSB]: add Sonics...
157
  {
394bc7e38   Hauke Mehrtens   ssb: add locking ...
158
159
160
161
162
  	unsigned long flags;
  	u32 res = 0;
  
  	spin_lock_irqsave(&extif->gpio_lock, flags);
  	res = extif_write32_masked(extif, SSB_EXTIF_GPIO_OUTEN(0),
61e115a56   Michael Buesch   [SSB]: add Sonics...
163
  				   mask, value);
394bc7e38   Hauke Mehrtens   ssb: add locking ...
164
165
166
  	spin_unlock_irqrestore(&extif->gpio_lock, flags);
  
  	return res;
61e115a56   Michael Buesch   [SSB]: add Sonics...
167
  }
c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
168
169
170
  
  u32 ssb_extif_gpio_polarity(struct ssb_extif *extif, u32 mask, u32 value)
  {
394bc7e38   Hauke Mehrtens   ssb: add locking ...
171
172
173
174
175
176
177
178
  	unsigned long flags;
  	u32 res = 0;
  
  	spin_lock_irqsave(&extif->gpio_lock, flags);
  	res = extif_write32_masked(extif, SSB_EXTIF_GPIO_INTPOL, mask, value);
  	spin_unlock_irqrestore(&extif->gpio_lock, flags);
  
  	return res;
c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
179
  }
61e115a56   Michael Buesch   [SSB]: add Sonics...
180

c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
181
182
  u32 ssb_extif_gpio_intmask(struct ssb_extif *extif, u32 mask, u32 value)
  {
394bc7e38   Hauke Mehrtens   ssb: add locking ...
183
184
185
186
187
188
189
190
  	unsigned long flags;
  	u32 res = 0;
  
  	spin_lock_irqsave(&extif->gpio_lock, flags);
  	res = extif_write32_masked(extif, SSB_EXTIF_GPIO_INTMASK, mask, value);
  	spin_unlock_irqrestore(&extif->gpio_lock, flags);
  
  	return res;
c2bcbe65f   Michael Buesch   ssb: Fix the GPIO...
191
  }