driver_chipcommon.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * Sonics Silicon Backplane
  3. * Broadcom ChipCommon core driver
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <m@bues.ch>
  7. * Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
  8. *
  9. * Licensed under the GNU/GPL. See COPYING for details.
  10. */
  11. #include <linux/ssb/ssb.h>
  12. #include <linux/ssb/ssb_regs.h>
  13. #include <linux/export.h>
  14. #include <linux/pci.h>
  15. #include <linux/bcm47xx_wdt.h>
  16. #include "ssb_private.h"
  17. /* Clock sources */
  18. enum ssb_clksrc {
  19. /* PCI clock */
  20. SSB_CHIPCO_CLKSRC_PCI,
  21. /* Crystal slow clock oscillator */
  22. SSB_CHIPCO_CLKSRC_XTALOS,
  23. /* Low power oscillator */
  24. SSB_CHIPCO_CLKSRC_LOPWROS,
  25. };
  26. static inline u32 chipco_write32_masked(struct ssb_chipcommon *cc, u16 offset,
  27. u32 mask, u32 value)
  28. {
  29. value &= mask;
  30. value |= chipco_read32(cc, offset) & ~mask;
  31. chipco_write32(cc, offset, value);
  32. return value;
  33. }
  34. void ssb_chipco_set_clockmode(struct ssb_chipcommon *cc,
  35. enum ssb_clkmode mode)
  36. {
  37. struct ssb_device *ccdev = cc->dev;
  38. struct ssb_bus *bus;
  39. u32 tmp;
  40. if (!ccdev)
  41. return;
  42. bus = ccdev->bus;
  43. /* We support SLOW only on 6..9 */
  44. if (ccdev->id.revision >= 10 && mode == SSB_CLKMODE_SLOW)
  45. mode = SSB_CLKMODE_DYNAMIC;
  46. if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
  47. return; /* PMU controls clockmode, separated function needed */
  48. SSB_WARN_ON(ccdev->id.revision >= 20);
  49. /* chipcommon cores prior to rev6 don't support dynamic clock control */
  50. if (ccdev->id.revision < 6)
  51. return;
  52. /* ChipCommon cores rev10+ need testing */
  53. if (ccdev->id.revision >= 10)
  54. return;
  55. if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
  56. return;
  57. switch (mode) {
  58. case SSB_CLKMODE_SLOW: /* For revs 6..9 only */
  59. tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
  60. tmp |= SSB_CHIPCO_SLOWCLKCTL_FSLOW;
  61. chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
  62. break;
  63. case SSB_CLKMODE_FAST:
  64. if (ccdev->id.revision < 10) {
  65. ssb_pci_xtal(bus, SSB_GPIO_XTAL, 1); /* Force crystal on */
  66. tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
  67. tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
  68. tmp |= SSB_CHIPCO_SLOWCLKCTL_IPLL;
  69. chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
  70. } else {
  71. chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
  72. (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) |
  73. SSB_CHIPCO_SYSCLKCTL_FORCEHT));
  74. /* udelay(150); TODO: not available in early init */
  75. }
  76. break;
  77. case SSB_CLKMODE_DYNAMIC:
  78. if (ccdev->id.revision < 10) {
  79. tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
  80. tmp &= ~SSB_CHIPCO_SLOWCLKCTL_FSLOW;
  81. tmp &= ~SSB_CHIPCO_SLOWCLKCTL_IPLL;
  82. tmp &= ~SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
  83. if ((tmp & SSB_CHIPCO_SLOWCLKCTL_SRC) !=
  84. SSB_CHIPCO_SLOWCLKCTL_SRC_XTAL)
  85. tmp |= SSB_CHIPCO_SLOWCLKCTL_ENXTAL;
  86. chipco_write32(cc, SSB_CHIPCO_SLOWCLKCTL, tmp);
  87. /* For dynamic control, we have to release our xtal_pu
  88. * "force on" */
  89. if (tmp & SSB_CHIPCO_SLOWCLKCTL_ENXTAL)
  90. ssb_pci_xtal(bus, SSB_GPIO_XTAL, 0);
  91. } else {
  92. chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
  93. (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
  94. ~SSB_CHIPCO_SYSCLKCTL_FORCEHT));
  95. }
  96. break;
  97. default:
  98. SSB_WARN_ON(1);
  99. }
  100. }
  101. /* Get the Slow Clock Source */
  102. static enum ssb_clksrc chipco_pctl_get_slowclksrc(struct ssb_chipcommon *cc)
  103. {
  104. struct ssb_bus *bus = cc->dev->bus;
  105. u32 uninitialized_var(tmp);
  106. if (cc->dev->id.revision < 6) {
  107. if (bus->bustype == SSB_BUSTYPE_SSB ||
  108. bus->bustype == SSB_BUSTYPE_PCMCIA)
  109. return SSB_CHIPCO_CLKSRC_XTALOS;
  110. if (bus->bustype == SSB_BUSTYPE_PCI) {
  111. pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &tmp);
  112. if (tmp & 0x10)
  113. return SSB_CHIPCO_CLKSRC_PCI;
  114. return SSB_CHIPCO_CLKSRC_XTALOS;
  115. }
  116. }
  117. if (cc->dev->id.revision < 10) {
  118. tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
  119. tmp &= 0x7;
  120. if (tmp == 0)
  121. return SSB_CHIPCO_CLKSRC_LOPWROS;
  122. if (tmp == 1)
  123. return SSB_CHIPCO_CLKSRC_XTALOS;
  124. if (tmp == 2)
  125. return SSB_CHIPCO_CLKSRC_PCI;
  126. }
  127. return SSB_CHIPCO_CLKSRC_XTALOS;
  128. }
  129. /* Get maximum or minimum (depending on get_max flag) slowclock frequency. */
  130. static int chipco_pctl_clockfreqlimit(struct ssb_chipcommon *cc, int get_max)
  131. {
  132. int uninitialized_var(limit);
  133. enum ssb_clksrc clocksrc;
  134. int divisor = 1;
  135. u32 tmp;
  136. clocksrc = chipco_pctl_get_slowclksrc(cc);
  137. if (cc->dev->id.revision < 6) {
  138. switch (clocksrc) {
  139. case SSB_CHIPCO_CLKSRC_PCI:
  140. divisor = 64;
  141. break;
  142. case SSB_CHIPCO_CLKSRC_XTALOS:
  143. divisor = 32;
  144. break;
  145. default:
  146. SSB_WARN_ON(1);
  147. }
  148. } else if (cc->dev->id.revision < 10) {
  149. switch (clocksrc) {
  150. case SSB_CHIPCO_CLKSRC_LOPWROS:
  151. break;
  152. case SSB_CHIPCO_CLKSRC_XTALOS:
  153. case SSB_CHIPCO_CLKSRC_PCI:
  154. tmp = chipco_read32(cc, SSB_CHIPCO_SLOWCLKCTL);
  155. divisor = (tmp >> 16) + 1;
  156. divisor *= 4;
  157. break;
  158. }
  159. } else {
  160. tmp = chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL);
  161. divisor = (tmp >> 16) + 1;
  162. divisor *= 4;
  163. }
  164. switch (clocksrc) {
  165. case SSB_CHIPCO_CLKSRC_LOPWROS:
  166. if (get_max)
  167. limit = 43000;
  168. else
  169. limit = 25000;
  170. break;
  171. case SSB_CHIPCO_CLKSRC_XTALOS:
  172. if (get_max)
  173. limit = 20200000;
  174. else
  175. limit = 19800000;
  176. break;
  177. case SSB_CHIPCO_CLKSRC_PCI:
  178. if (get_max)
  179. limit = 34000000;
  180. else
  181. limit = 25000000;
  182. break;
  183. }
  184. limit /= divisor;
  185. return limit;
  186. }
  187. static void chipco_powercontrol_init(struct ssb_chipcommon *cc)
  188. {
  189. struct ssb_bus *bus = cc->dev->bus;
  190. if (bus->chip_id == 0x4321) {
  191. if (bus->chip_rev == 0)
  192. chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0x3A4);
  193. else if (bus->chip_rev == 1)
  194. chipco_write32(cc, SSB_CHIPCO_CHIPCTL, 0xA4);
  195. }
  196. if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
  197. return;
  198. if (cc->dev->id.revision >= 10) {
  199. /* Set Idle Power clock rate to 1Mhz */
  200. chipco_write32(cc, SSB_CHIPCO_SYSCLKCTL,
  201. (chipco_read32(cc, SSB_CHIPCO_SYSCLKCTL) &
  202. 0x0000FFFF) | 0x00040000);
  203. } else {
  204. int maxfreq;
  205. maxfreq = chipco_pctl_clockfreqlimit(cc, 1);
  206. chipco_write32(cc, SSB_CHIPCO_PLLONDELAY,
  207. (maxfreq * 150 + 999999) / 1000000);
  208. chipco_write32(cc, SSB_CHIPCO_FREFSELDELAY,
  209. (maxfreq * 15 + 999999) / 1000000);
  210. }
  211. }
  212. /* http://bcm-v4.sipsolutions.net/802.11/PmuFastPwrupDelay */
  213. static u16 pmu_fast_powerup_delay(struct ssb_chipcommon *cc)
  214. {
  215. struct ssb_bus *bus = cc->dev->bus;
  216. switch (bus->chip_id) {
  217. case 0x4312:
  218. case 0x4322:
  219. case 0x4328:
  220. return 7000;
  221. case 0x4325:
  222. /* TODO: */
  223. default:
  224. return 15000;
  225. }
  226. }
  227. /* http://bcm-v4.sipsolutions.net/802.11/ClkctlFastPwrupDelay */
  228. static void calc_fast_powerup_delay(struct ssb_chipcommon *cc)
  229. {
  230. struct ssb_bus *bus = cc->dev->bus;
  231. int minfreq;
  232. unsigned int tmp;
  233. u32 pll_on_delay;
  234. if (bus->bustype != SSB_BUSTYPE_PCI)
  235. return;
  236. if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
  237. cc->fast_pwrup_delay = pmu_fast_powerup_delay(cc);
  238. return;
  239. }
  240. if (!(cc->capabilities & SSB_CHIPCO_CAP_PCTL))
  241. return;
  242. minfreq = chipco_pctl_clockfreqlimit(cc, 0);
  243. pll_on_delay = chipco_read32(cc, SSB_CHIPCO_PLLONDELAY);
  244. tmp = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq;
  245. SSB_WARN_ON(tmp & ~0xFFFF);
  246. cc->fast_pwrup_delay = tmp;
  247. }
  248. static u32 ssb_chipco_alp_clock(struct ssb_chipcommon *cc)
  249. {
  250. if (cc->capabilities & SSB_CHIPCO_CAP_PMU)
  251. return ssb_pmu_get_alp_clock(cc);
  252. return 20000000;
  253. }
  254. static u32 ssb_chipco_watchdog_get_max_timer(struct ssb_chipcommon *cc)
  255. {
  256. u32 nb;
  257. if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
  258. if (cc->dev->id.revision < 26)
  259. nb = 16;
  260. else
  261. nb = (cc->dev->id.revision >= 37) ? 32 : 24;
  262. } else {
  263. nb = 28;
  264. }
  265. if (nb == 32)
  266. return 0xffffffff;
  267. else
  268. return (1 << nb) - 1;
  269. }
  270. u32 ssb_chipco_watchdog_timer_set_wdt(struct bcm47xx_wdt *wdt, u32 ticks)
  271. {
  272. struct ssb_chipcommon *cc = bcm47xx_wdt_get_drvdata(wdt);
  273. if (cc->dev->bus->bustype != SSB_BUSTYPE_SSB)
  274. return 0;
  275. return ssb_chipco_watchdog_timer_set(cc, ticks);
  276. }
  277. u32 ssb_chipco_watchdog_timer_set_ms(struct bcm47xx_wdt *wdt, u32 ms)
  278. {
  279. struct ssb_chipcommon *cc = bcm47xx_wdt_get_drvdata(wdt);
  280. u32 ticks;
  281. if (cc->dev->bus->bustype != SSB_BUSTYPE_SSB)
  282. return 0;
  283. ticks = ssb_chipco_watchdog_timer_set(cc, cc->ticks_per_ms * ms);
  284. return ticks / cc->ticks_per_ms;
  285. }
  286. static int ssb_chipco_watchdog_ticks_per_ms(struct ssb_chipcommon *cc)
  287. {
  288. struct ssb_bus *bus = cc->dev->bus;
  289. if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
  290. /* based on 32KHz ILP clock */
  291. return 32;
  292. } else {
  293. if (cc->dev->id.revision < 18)
  294. return ssb_clockspeed(bus) / 1000;
  295. else
  296. return ssb_chipco_alp_clock(cc) / 1000;
  297. }
  298. }
  299. void ssb_chipcommon_init(struct ssb_chipcommon *cc)
  300. {
  301. if (!cc->dev)
  302. return; /* We don't have a ChipCommon */
  303. spin_lock_init(&cc->gpio_lock);
  304. if (cc->dev->id.revision >= 11)
  305. cc->status = chipco_read32(cc, SSB_CHIPCO_CHIPSTAT);
  306. ssb_dbg("chipcommon status is 0x%x\n", cc->status);
  307. if (cc->dev->id.revision >= 20) {
  308. chipco_write32(cc, SSB_CHIPCO_GPIOPULLUP, 0);
  309. chipco_write32(cc, SSB_CHIPCO_GPIOPULLDOWN, 0);
  310. }
  311. ssb_pmu_init(cc);
  312. chipco_powercontrol_init(cc);
  313. ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
  314. calc_fast_powerup_delay(cc);
  315. if (cc->dev->bus->bustype == SSB_BUSTYPE_SSB) {
  316. cc->ticks_per_ms = ssb_chipco_watchdog_ticks_per_ms(cc);
  317. cc->max_timer_ms = ssb_chipco_watchdog_get_max_timer(cc) / cc->ticks_per_ms;
  318. }
  319. }
  320. void ssb_chipco_suspend(struct ssb_chipcommon *cc)
  321. {
  322. if (!cc->dev)
  323. return;
  324. ssb_chipco_set_clockmode(cc, SSB_CLKMODE_SLOW);
  325. }
  326. void ssb_chipco_resume(struct ssb_chipcommon *cc)
  327. {
  328. if (!cc->dev)
  329. return;
  330. chipco_powercontrol_init(cc);
  331. ssb_chipco_set_clockmode(cc, SSB_CLKMODE_FAST);
  332. }
  333. /* Get the processor clock */
  334. void ssb_chipco_get_clockcpu(struct ssb_chipcommon *cc,
  335. u32 *plltype, u32 *n, u32 *m)
  336. {
  337. *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N);
  338. *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
  339. switch (*plltype) {
  340. case SSB_PLLTYPE_2:
  341. case SSB_PLLTYPE_4:
  342. case SSB_PLLTYPE_6:
  343. case SSB_PLLTYPE_7:
  344. *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS);
  345. break;
  346. case SSB_PLLTYPE_3:
  347. /* 5350 uses m2 to control mips */
  348. *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2);
  349. break;
  350. default:
  351. *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB);
  352. break;
  353. }
  354. }
  355. /* Get the bus clock */
  356. void ssb_chipco_get_clockcontrol(struct ssb_chipcommon *cc,
  357. u32 *plltype, u32 *n, u32 *m)
  358. {
  359. *n = chipco_read32(cc, SSB_CHIPCO_CLOCK_N);
  360. *plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
  361. switch (*plltype) {
  362. case SSB_PLLTYPE_6: /* 100/200 or 120/240 only */
  363. *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_MIPS);
  364. break;
  365. case SSB_PLLTYPE_3: /* 25Mhz, 2 dividers */
  366. if (cc->dev->bus->chip_id != 0x5365) {
  367. *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_M2);
  368. break;
  369. }
  370. /* Fallthough */
  371. default:
  372. *m = chipco_read32(cc, SSB_CHIPCO_CLOCK_SB);
  373. }
  374. }
  375. void ssb_chipco_timing_init(struct ssb_chipcommon *cc,
  376. unsigned long ns)
  377. {
  378. struct ssb_device *dev = cc->dev;
  379. struct ssb_bus *bus = dev->bus;
  380. u32 tmp;
  381. /* set register for external IO to control LED. */
  382. chipco_write32(cc, SSB_CHIPCO_PROG_CFG, 0x11);
  383. tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */
  384. tmp |= DIV_ROUND_UP(40, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 40ns */
  385. tmp |= DIV_ROUND_UP(240, ns); /* Waitcount-0 = 240ns */
  386. chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */
  387. /* Set timing for the flash */
  388. tmp = DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_3_SHIFT; /* Waitcount-3 = 10nS */
  389. tmp |= DIV_ROUND_UP(10, ns) << SSB_FLASH_WCNT_1_SHIFT; /* Waitcount-1 = 10nS */
  390. tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120nS */
  391. if ((bus->chip_id == 0x5365) ||
  392. (dev->id.revision < 9))
  393. chipco_write32(cc, SSB_CHIPCO_FLASH_WAITCNT, tmp);
  394. if ((bus->chip_id == 0x5365) ||
  395. (dev->id.revision < 9) ||
  396. ((bus->chip_id == 0x5350) && (bus->chip_rev == 0)))
  397. chipco_write32(cc, SSB_CHIPCO_PCMCIA_MEMWAIT, tmp);
  398. if (bus->chip_id == 0x5350) {
  399. /* Enable EXTIF */
  400. tmp = DIV_ROUND_UP(10, ns) << SSB_PROG_WCNT_3_SHIFT; /* Waitcount-3 = 10ns */
  401. tmp |= DIV_ROUND_UP(20, ns) << SSB_PROG_WCNT_2_SHIFT; /* Waitcount-2 = 20ns */
  402. tmp |= DIV_ROUND_UP(100, ns) << SSB_PROG_WCNT_1_SHIFT; /* Waitcount-1 = 100ns */
  403. tmp |= DIV_ROUND_UP(120, ns); /* Waitcount-0 = 120ns */
  404. chipco_write32(cc, SSB_CHIPCO_PROG_WAITCNT, tmp); /* 0x01020a0c for a 100Mhz clock */
  405. }
  406. }
  407. /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
  408. u32 ssb_chipco_watchdog_timer_set(struct ssb_chipcommon *cc, u32 ticks)
  409. {
  410. u32 maxt;
  411. enum ssb_clkmode clkmode;
  412. maxt = ssb_chipco_watchdog_get_max_timer(cc);
  413. if (cc->capabilities & SSB_CHIPCO_CAP_PMU) {
  414. if (ticks == 1)
  415. ticks = 2;
  416. else if (ticks > maxt)
  417. ticks = maxt;
  418. chipco_write32(cc, SSB_CHIPCO_PMU_WATCHDOG, ticks);
  419. } else {
  420. clkmode = ticks ? SSB_CLKMODE_FAST : SSB_CLKMODE_DYNAMIC;
  421. ssb_chipco_set_clockmode(cc, clkmode);
  422. if (ticks > maxt)
  423. ticks = maxt;
  424. /* instant NMI */
  425. chipco_write32(cc, SSB_CHIPCO_WATCHDOG, ticks);
  426. }
  427. return ticks;
  428. }
  429. void ssb_chipco_irq_mask(struct ssb_chipcommon *cc, u32 mask, u32 value)
  430. {
  431. chipco_write32_masked(cc, SSB_CHIPCO_IRQMASK, mask, value);
  432. }
  433. u32 ssb_chipco_irq_status(struct ssb_chipcommon *cc, u32 mask)
  434. {
  435. return chipco_read32(cc, SSB_CHIPCO_IRQSTAT) & mask;
  436. }
  437. u32 ssb_chipco_gpio_in(struct ssb_chipcommon *cc, u32 mask)
  438. {
  439. return chipco_read32(cc, SSB_CHIPCO_GPIOIN) & mask;
  440. }
  441. u32 ssb_chipco_gpio_out(struct ssb_chipcommon *cc, u32 mask, u32 value)
  442. {
  443. unsigned long flags;
  444. u32 res = 0;
  445. spin_lock_irqsave(&cc->gpio_lock, flags);
  446. res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUT, mask, value);
  447. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  448. return res;
  449. }
  450. u32 ssb_chipco_gpio_outen(struct ssb_chipcommon *cc, u32 mask, u32 value)
  451. {
  452. unsigned long flags;
  453. u32 res = 0;
  454. spin_lock_irqsave(&cc->gpio_lock, flags);
  455. res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOOUTEN, mask, value);
  456. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  457. return res;
  458. }
  459. u32 ssb_chipco_gpio_control(struct ssb_chipcommon *cc, u32 mask, u32 value)
  460. {
  461. unsigned long flags;
  462. u32 res = 0;
  463. spin_lock_irqsave(&cc->gpio_lock, flags);
  464. res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOCTL, mask, value);
  465. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  466. return res;
  467. }
  468. EXPORT_SYMBOL(ssb_chipco_gpio_control);
  469. u32 ssb_chipco_gpio_intmask(struct ssb_chipcommon *cc, u32 mask, u32 value)
  470. {
  471. unsigned long flags;
  472. u32 res = 0;
  473. spin_lock_irqsave(&cc->gpio_lock, flags);
  474. res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOIRQ, mask, value);
  475. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  476. return res;
  477. }
  478. u32 ssb_chipco_gpio_polarity(struct ssb_chipcommon *cc, u32 mask, u32 value)
  479. {
  480. unsigned long flags;
  481. u32 res = 0;
  482. spin_lock_irqsave(&cc->gpio_lock, flags);
  483. res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOPOL, mask, value);
  484. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  485. return res;
  486. }
  487. u32 ssb_chipco_gpio_pullup(struct ssb_chipcommon *cc, u32 mask, u32 value)
  488. {
  489. unsigned long flags;
  490. u32 res = 0;
  491. if (cc->dev->id.revision < 20)
  492. return 0xffffffff;
  493. spin_lock_irqsave(&cc->gpio_lock, flags);
  494. res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOPULLUP, mask, value);
  495. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  496. return res;
  497. }
  498. u32 ssb_chipco_gpio_pulldown(struct ssb_chipcommon *cc, u32 mask, u32 value)
  499. {
  500. unsigned long flags;
  501. u32 res = 0;
  502. if (cc->dev->id.revision < 20)
  503. return 0xffffffff;
  504. spin_lock_irqsave(&cc->gpio_lock, flags);
  505. res = chipco_write32_masked(cc, SSB_CHIPCO_GPIOPULLDOWN, mask, value);
  506. spin_unlock_irqrestore(&cc->gpio_lock, flags);
  507. return res;
  508. }
  509. #ifdef CONFIG_SSB_SERIAL
  510. int ssb_chipco_serial_init(struct ssb_chipcommon *cc,
  511. struct ssb_serial_port *ports)
  512. {
  513. struct ssb_bus *bus = cc->dev->bus;
  514. int nr_ports = 0;
  515. u32 plltype;
  516. unsigned int irq;
  517. u32 baud_base, div;
  518. u32 i, n;
  519. unsigned int ccrev = cc->dev->id.revision;
  520. plltype = (cc->capabilities & SSB_CHIPCO_CAP_PLLT);
  521. irq = ssb_mips_irq(cc->dev);
  522. if (plltype == SSB_PLLTYPE_1) {
  523. /* PLL clock */
  524. baud_base = ssb_calc_clock_rate(plltype,
  525. chipco_read32(cc, SSB_CHIPCO_CLOCK_N),
  526. chipco_read32(cc, SSB_CHIPCO_CLOCK_M2));
  527. div = 1;
  528. } else {
  529. if (ccrev == 20) {
  530. /* BCM5354 uses constant 25MHz clock */
  531. baud_base = 25000000;
  532. div = 48;
  533. /* Set the override bit so we don't divide it */
  534. chipco_write32(cc, SSB_CHIPCO_CORECTL,
  535. chipco_read32(cc, SSB_CHIPCO_CORECTL)
  536. | SSB_CHIPCO_CORECTL_UARTCLK0);
  537. } else if ((ccrev >= 11) && (ccrev != 15)) {
  538. baud_base = ssb_chipco_alp_clock(cc);
  539. div = 1;
  540. if (ccrev >= 21) {
  541. /* Turn off UART clock before switching clocksource. */
  542. chipco_write32(cc, SSB_CHIPCO_CORECTL,
  543. chipco_read32(cc, SSB_CHIPCO_CORECTL)
  544. & ~SSB_CHIPCO_CORECTL_UARTCLKEN);
  545. }
  546. /* Set the override bit so we don't divide it */
  547. chipco_write32(cc, SSB_CHIPCO_CORECTL,
  548. chipco_read32(cc, SSB_CHIPCO_CORECTL)
  549. | SSB_CHIPCO_CORECTL_UARTCLK0);
  550. if (ccrev >= 21) {
  551. /* Re-enable the UART clock. */
  552. chipco_write32(cc, SSB_CHIPCO_CORECTL,
  553. chipco_read32(cc, SSB_CHIPCO_CORECTL)
  554. | SSB_CHIPCO_CORECTL_UARTCLKEN);
  555. }
  556. } else if (ccrev >= 3) {
  557. /* Internal backplane clock */
  558. baud_base = ssb_clockspeed(bus);
  559. div = chipco_read32(cc, SSB_CHIPCO_CLKDIV)
  560. & SSB_CHIPCO_CLKDIV_UART;
  561. } else {
  562. /* Fixed internal backplane clock */
  563. baud_base = 88000000;
  564. div = 48;
  565. }
  566. /* Clock source depends on strapping if UartClkOverride is unset */
  567. if ((ccrev > 0) &&
  568. !(chipco_read32(cc, SSB_CHIPCO_CORECTL) & SSB_CHIPCO_CORECTL_UARTCLK0)) {
  569. if ((cc->capabilities & SSB_CHIPCO_CAP_UARTCLK) ==
  570. SSB_CHIPCO_CAP_UARTCLK_INT) {
  571. /* Internal divided backplane clock */
  572. baud_base /= div;
  573. } else {
  574. /* Assume external clock of 1.8432 MHz */
  575. baud_base = 1843200;
  576. }
  577. }
  578. }
  579. /* Determine the registers of the UARTs */
  580. n = (cc->capabilities & SSB_CHIPCO_CAP_NRUART);
  581. for (i = 0; i < n; i++) {
  582. void __iomem *cc_mmio;
  583. void __iomem *uart_regs;
  584. cc_mmio = cc->dev->bus->mmio + (cc->dev->core_index * SSB_CORE_SIZE);
  585. uart_regs = cc_mmio + SSB_CHIPCO_UART0_DATA;
  586. /* Offset changed at after rev 0 */
  587. if (ccrev == 0)
  588. uart_regs += (i * 8);
  589. else
  590. uart_regs += (i * 256);
  591. nr_ports++;
  592. ports[i].regs = uart_regs;
  593. ports[i].irq = irq;
  594. ports[i].baud_base = baud_base;
  595. ports[i].reg_shift = 0;
  596. }
  597. return nr_ports;
  598. }
  599. #endif /* CONFIG_SSB_SERIAL */