Blame view

drivers/bcma/core.c 3.62 KB
8369ae33b   Rafał Miłecki   bcma: add Broadco...
1
2
3
4
5
6
7
8
  /*
   * Broadcom specific AMBA
   * Core ops
   *
   * Licensed under the GNU/GPL. See COPYING for details.
   */
  
  #include "bcma_private.h"
44a8e3772   Paul Gortmaker   bcma: fix implici...
9
  #include <linux/export.h>
8369ae33b   Rafał Miłecki   bcma: add Broadco...
10
  #include <linux/bcma/bcma.h>
972da7ec4   Rafał Miłecki   bcma: update core...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  static bool bcma_core_wait_value(struct bcma_device *core, u16 reg, u32 mask,
  				 u32 value, int timeout)
  {
  	unsigned long deadline = jiffies + timeout;
  	u32 val;
  
  	do {
  		val = bcma_aread32(core, reg);
  		if ((val & mask) == value)
  			return true;
  		cpu_relax();
  		udelay(10);
  	} while (!time_after_eq(jiffies, deadline));
  
  	bcma_warn(core->bus, "Timeout waiting for register 0x%04X!
  ", reg);
  
  	return false;
  }
8369ae33b   Rafał Miłecki   bcma: add Broadco...
30
31
32
33
34
35
36
37
38
39
  bool bcma_core_is_enabled(struct bcma_device *core)
  {
  	if ((bcma_aread32(core, BCMA_IOCTL) & (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC))
  	    != BCMA_IOCTL_CLK)
  		return false;
  	if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
  		return false;
  	return true;
  }
  EXPORT_SYMBOL_GPL(bcma_core_is_enabled);
e3ae0cac0   Arend van Spriel   drivers: bcma: ex...
40
  void bcma_core_disable(struct bcma_device *core, u32 flags)
8369ae33b   Rafał Miłecki   bcma: add Broadco...
41
42
43
  {
  	if (bcma_aread32(core, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET)
  		return;
972da7ec4   Rafał Miłecki   bcma: update core...
44
  	bcma_core_wait_value(core, BCMA_RESET_ST, ~0, 0, 300);
8369ae33b   Rafał Miłecki   bcma: add Broadco...
45
46
  
  	bcma_awrite32(core, BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
044e68c0c   Nathan Hintz   bcma: Add flush f...
47
  	bcma_aread32(core, BCMA_RESET_CTL);
8369ae33b   Rafał Miłecki   bcma: add Broadco...
48
  	udelay(1);
972da7ec4   Rafał Miłecki   bcma: update core...
49
50
51
52
  
  	bcma_awrite32(core, BCMA_IOCTL, flags);
  	bcma_aread32(core, BCMA_IOCTL);
  	udelay(10);
8369ae33b   Rafał Miłecki   bcma: add Broadco...
53
  }
e3ae0cac0   Arend van Spriel   drivers: bcma: ex...
54
  EXPORT_SYMBOL_GPL(bcma_core_disable);
8369ae33b   Rafał Miłecki   bcma: add Broadco...
55
56
57
58
59
60
61
62
63
  
  int bcma_core_enable(struct bcma_device *core, u32 flags)
  {
  	bcma_core_disable(core, flags);
  
  	bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags));
  	bcma_aread32(core, BCMA_IOCTL);
  
  	bcma_awrite32(core, BCMA_RESET_CTL, 0);
972da7ec4   Rafał Miłecki   bcma: update core...
64
  	bcma_aread32(core, BCMA_RESET_CTL);
8369ae33b   Rafał Miłecki   bcma: add Broadco...
65
66
67
68
69
70
71
72
73
  	udelay(1);
  
  	bcma_awrite32(core, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags));
  	bcma_aread32(core, BCMA_IOCTL);
  	udelay(1);
  
  	return 0;
  }
  EXPORT_SYMBOL_GPL(bcma_core_enable);
7424dd0d0   Rafał Miłecki   bcma: allow setti...
74
75
76
77
78
79
80
81
82
83
84
85
86
  
  void bcma_core_set_clockmode(struct bcma_device *core,
  			     enum bcma_clkmode clkmode)
  {
  	u16 i;
  
  	WARN_ON(core->id.id != BCMA_CORE_CHIPCOMMON &&
  		core->id.id != BCMA_CORE_PCIE &&
  		core->id.id != BCMA_CORE_80211);
  
  	switch (clkmode) {
  	case BCMA_CLKMODE_FAST:
  		bcma_set32(core, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
1fd41a65f   Rafał Miłecki   bcma: change dela...
87
  		usleep_range(64, 300);
7424dd0d0   Rafał Miłecki   bcma: allow setti...
88
89
90
91
92
93
94
95
96
  		for (i = 0; i < 1500; i++) {
  			if (bcma_read32(core, BCMA_CLKCTLST) &
  			    BCMA_CLKCTLST_HAVEHT) {
  				i = 0;
  				break;
  			}
  			udelay(10);
  		}
  		if (i)
3d9d8af33   Rafał Miłecki   bcma: use custom ...
97
98
  			bcma_err(core->bus, "HT force timeout
  ");
7424dd0d0   Rafał Miłecki   bcma: allow setti...
99
100
  		break;
  	case BCMA_CLKMODE_DYNAMIC:
0b2948eeb   Hauke Mehrtens   bcma: implement s...
101
  		bcma_set32(core, BCMA_CLKCTLST, ~BCMA_CLKCTLST_FORCEHT);
7424dd0d0   Rafał Miłecki   bcma: allow setti...
102
103
104
105
  		break;
  	}
  }
  EXPORT_SYMBOL_GPL(bcma_core_set_clockmode);
6f53912fc   Rafał Miłecki   bcma: allow enabl...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  
  void bcma_core_pll_ctl(struct bcma_device *core, u32 req, u32 status, bool on)
  {
  	u16 i;
  
  	WARN_ON(req & ~BCMA_CLKCTLST_EXTRESREQ);
  	WARN_ON(status & ~BCMA_CLKCTLST_EXTRESST);
  
  	if (on) {
  		bcma_set32(core, BCMA_CLKCTLST, req);
  		for (i = 0; i < 10000; i++) {
  			if ((bcma_read32(core, BCMA_CLKCTLST) & status) ==
  			    status) {
  				i = 0;
  				break;
  			}
  			udelay(10);
  		}
  		if (i)
3d9d8af33   Rafał Miłecki   bcma: use custom ...
125
126
  			bcma_err(core->bus, "PLL enable timeout
  ");
6f53912fc   Rafał Miłecki   bcma: allow enabl...
127
  	} else {
c722839cc   Rafał Miłecki   bcma: implement d...
128
129
130
131
132
133
134
  		/*
  		 * Mask the PLL but don't wait for it to be disabled. PLL may be
  		 * shared between cores and will be still up if there is another
  		 * core using it.
  		 */
  		bcma_mask32(core, BCMA_CLKCTLST, ~req);
  		bcma_read32(core, BCMA_CLKCTLST);
6f53912fc   Rafał Miłecki   bcma: allow enabl...
135
136
137
  	}
  }
  EXPORT_SYMBOL_GPL(bcma_core_pll_ctl);
05aec2333   Rafał Miłecki   bcma: inform driv...
138
139
140
141
  
  u32 bcma_core_dma_translation(struct bcma_device *core)
  {
  	switch (core->bus->hosttype) {
ecd177c21   Hauke Mehrtens   bcma: add SOC bus
142
143
  	case BCMA_HOSTTYPE_SOC:
  		return 0;
05aec2333   Rafał Miłecki   bcma: inform driv...
144
145
146
147
148
149
  	case BCMA_HOSTTYPE_PCI:
  		if (bcma_aread32(core, BCMA_IOST) & BCMA_IOST_DMA64)
  			return BCMA_DMA_TRANSLATION_DMA64_CMT;
  		else
  			return BCMA_DMA_TRANSLATION_DMA32_CMT;
  	default:
3d9d8af33   Rafał Miłecki   bcma: use custom ...
150
151
152
  		bcma_err(core->bus, "DMA translation unknown for host %d
  ",
  			 core->bus->hosttype);
05aec2333   Rafał Miłecki   bcma: inform driv...
153
154
155
156
  	}
  	return BCMA_DMA_TRANSLATION_NONE;
  }
  EXPORT_SYMBOL(bcma_core_dma_translation);