soc_common.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*======================================================================
  2. Common support code for the PCMCIA control functionality of
  3. integrated SOCs like the SA-11x0 and PXA2xx microprocessors.
  4. The contents of this file are subject to the Mozilla Public
  5. License Version 1.1 (the "License"); you may not use this file
  6. except in compliance with the License. You may obtain a copy of
  7. the License at http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS
  9. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. implied. See the License for the specific language governing
  11. rights and limitations under the License.
  12. The initial developer of the original code is John G. Dorsey
  13. <john+@cs.cmu.edu>. Portions created by John G. Dorsey are
  14. Copyright (C) 1999 John G. Dorsey. All Rights Reserved.
  15. Alternatively, the contents of this file may be used under the
  16. terms of the GNU Public License version 2 (the "GPL"), in which
  17. case the provisions of the GPL are applicable instead of the
  18. above. If you wish to allow the use of your version of this file
  19. only under the terms of the GPL and not to allow others to use
  20. your version of this file under the MPL, indicate your decision
  21. by deleting the provisions above and replace them with the notice
  22. and other provisions required by the GPL. If you do not delete
  23. the provisions above, a recipient may use your version of this
  24. file under either the MPL or the GPL.
  25. ======================================================================*/
  26. #include <linux/cpufreq.h>
  27. #include <linux/init.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/io.h>
  30. #include <linux/irq.h>
  31. #include <linux/kernel.h>
  32. #include <linux/mm.h>
  33. #include <linux/module.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/mutex.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/timer.h>
  38. #include <mach/hardware.h>
  39. #include <asm/system.h>
  40. #include "soc_common.h"
  41. #ifdef CONFIG_PCMCIA_DEBUG
  42. static int pc_debug;
  43. module_param(pc_debug, int, 0644);
  44. void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
  45. int lvl, const char *fmt, ...)
  46. {
  47. struct va_format vaf;
  48. va_list args;
  49. if (pc_debug > lvl) {
  50. va_start(args, fmt);
  51. vaf.fmt = fmt;
  52. vaf.va = &args;
  53. printk(KERN_DEBUG "skt%u: %s: %pV", skt->nr, func, &vaf);
  54. va_end(args);
  55. }
  56. }
  57. EXPORT_SYMBOL(soc_pcmcia_debug);
  58. #endif
  59. #define to_soc_pcmcia_socket(x) \
  60. container_of(x, struct soc_pcmcia_socket, socket)
  61. static unsigned short
  62. calc_speed(unsigned short *spds, int num, unsigned short dflt)
  63. {
  64. unsigned short speed = 0;
  65. int i;
  66. for (i = 0; i < num; i++)
  67. if (speed < spds[i])
  68. speed = spds[i];
  69. if (speed == 0)
  70. speed = dflt;
  71. return speed;
  72. }
  73. void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *skt,
  74. struct soc_pcmcia_timing *timing)
  75. {
  76. timing->io =
  77. calc_speed(skt->spd_io, MAX_IO_WIN, SOC_PCMCIA_IO_ACCESS);
  78. timing->mem =
  79. calc_speed(skt->spd_mem, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
  80. timing->attr =
  81. calc_speed(skt->spd_attr, MAX_WIN, SOC_PCMCIA_3V_MEM_ACCESS);
  82. }
  83. EXPORT_SYMBOL(soc_common_pcmcia_get_timing);
  84. static unsigned int soc_common_pcmcia_skt_state(struct soc_pcmcia_socket *skt)
  85. {
  86. struct pcmcia_state state;
  87. unsigned int stat;
  88. memset(&state, 0, sizeof(struct pcmcia_state));
  89. skt->ops->socket_state(skt, &state);
  90. stat = state.detect ? SS_DETECT : 0;
  91. stat |= state.ready ? SS_READY : 0;
  92. stat |= state.wrprot ? SS_WRPROT : 0;
  93. stat |= state.vs_3v ? SS_3VCARD : 0;
  94. stat |= state.vs_Xv ? SS_XVCARD : 0;
  95. /* The power status of individual sockets is not available
  96. * explicitly from the hardware, so we just remember the state
  97. * and regurgitate it upon request:
  98. */
  99. stat |= skt->cs_state.Vcc ? SS_POWERON : 0;
  100. if (skt->cs_state.flags & SS_IOCARD)
  101. stat |= state.bvd1 ? SS_STSCHG : 0;
  102. else {
  103. if (state.bvd1 == 0)
  104. stat |= SS_BATDEAD;
  105. else if (state.bvd2 == 0)
  106. stat |= SS_BATWARN;
  107. }
  108. return stat;
  109. }
  110. /*
  111. * soc_common_pcmcia_config_skt
  112. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  113. *
  114. * Convert PCMCIA socket state to our socket configure structure.
  115. */
  116. static int soc_common_pcmcia_config_skt(
  117. struct soc_pcmcia_socket *skt, socket_state_t *state)
  118. {
  119. int ret;
  120. ret = skt->ops->configure_socket(skt, state);
  121. if (ret == 0) {
  122. /*
  123. * This really needs a better solution. The IRQ
  124. * may or may not be claimed by the driver.
  125. */
  126. if (skt->irq_state != 1 && state->io_irq) {
  127. skt->irq_state = 1;
  128. irq_set_irq_type(skt->socket.pci_irq,
  129. IRQ_TYPE_EDGE_FALLING);
  130. } else if (skt->irq_state == 1 && state->io_irq == 0) {
  131. skt->irq_state = 0;
  132. irq_set_irq_type(skt->socket.pci_irq, IRQ_TYPE_NONE);
  133. }
  134. skt->cs_state = *state;
  135. }
  136. if (ret < 0)
  137. printk(KERN_ERR "soc_common_pcmcia: unable to configure "
  138. "socket %d\n", skt->nr);
  139. return ret;
  140. }
  141. /* soc_common_pcmcia_sock_init()
  142. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  143. *
  144. * (Re-)Initialise the socket, turning on status interrupts
  145. * and PCMCIA bus. This must wait for power to stabilise
  146. * so that the card status signals report correctly.
  147. *
  148. * Returns: 0
  149. */
  150. static int soc_common_pcmcia_sock_init(struct pcmcia_socket *sock)
  151. {
  152. struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
  153. debug(skt, 2, "initializing socket\n");
  154. skt->ops->socket_init(skt);
  155. return 0;
  156. }
  157. /*
  158. * soc_common_pcmcia_suspend()
  159. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  160. *
  161. * Remove power on the socket, disable IRQs from the card.
  162. * Turn off status interrupts, and disable the PCMCIA bus.
  163. *
  164. * Returns: 0
  165. */
  166. static int soc_common_pcmcia_suspend(struct pcmcia_socket *sock)
  167. {
  168. struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
  169. debug(skt, 2, "suspending socket\n");
  170. skt->ops->socket_suspend(skt);
  171. return 0;
  172. }
  173. static DEFINE_SPINLOCK(status_lock);
  174. static void soc_common_check_status(struct soc_pcmcia_socket *skt)
  175. {
  176. unsigned int events;
  177. debug(skt, 4, "entering PCMCIA monitoring thread\n");
  178. do {
  179. unsigned int status;
  180. unsigned long flags;
  181. status = soc_common_pcmcia_skt_state(skt);
  182. spin_lock_irqsave(&status_lock, flags);
  183. events = (status ^ skt->status) & skt->cs_state.csc_mask;
  184. skt->status = status;
  185. spin_unlock_irqrestore(&status_lock, flags);
  186. debug(skt, 4, "events: %s%s%s%s%s%s\n",
  187. events == 0 ? "<NONE>" : "",
  188. events & SS_DETECT ? "DETECT " : "",
  189. events & SS_READY ? "READY " : "",
  190. events & SS_BATDEAD ? "BATDEAD " : "",
  191. events & SS_BATWARN ? "BATWARN " : "",
  192. events & SS_STSCHG ? "STSCHG " : "");
  193. if (events)
  194. pcmcia_parse_events(&skt->socket, events);
  195. } while (events);
  196. }
  197. /* Let's poll for events in addition to IRQs since IRQ only is unreliable... */
  198. static void soc_common_pcmcia_poll_event(unsigned long dummy)
  199. {
  200. struct soc_pcmcia_socket *skt = (struct soc_pcmcia_socket *)dummy;
  201. debug(skt, 4, "polling for events\n");
  202. mod_timer(&skt->poll_timer, jiffies + SOC_PCMCIA_POLL_PERIOD);
  203. soc_common_check_status(skt);
  204. }
  205. /*
  206. * Service routine for socket driver interrupts (requested by the
  207. * low-level PCMCIA init() operation via soc_common_pcmcia_thread()).
  208. * The actual interrupt-servicing work is performed by
  209. * soc_common_pcmcia_thread(), largely because the Card Services event-
  210. * handling code performs scheduling operations which cannot be
  211. * executed from within an interrupt context.
  212. */
  213. static irqreturn_t soc_common_pcmcia_interrupt(int irq, void *dev)
  214. {
  215. struct soc_pcmcia_socket *skt = dev;
  216. debug(skt, 3, "servicing IRQ %d\n", irq);
  217. soc_common_check_status(skt);
  218. return IRQ_HANDLED;
  219. }
  220. /*
  221. * Implements the get_status() operation for the in-kernel PCMCIA
  222. * service (formerly SS_GetStatus in Card Services). Essentially just
  223. * fills in bits in `status' according to internal driver state or
  224. * the value of the voltage detect chipselect register.
  225. *
  226. * As a debugging note, during card startup, the PCMCIA core issues
  227. * three set_socket() commands in a row the first with RESET deasserted,
  228. * the second with RESET asserted, and the last with RESET deasserted
  229. * again. Following the third set_socket(), a get_status() command will
  230. * be issued. The kernel is looking for the SS_READY flag (see
  231. * setup_socket(), reset_socket(), and unreset_socket() in cs.c).
  232. *
  233. * Returns: 0
  234. */
  235. static int
  236. soc_common_pcmcia_get_status(struct pcmcia_socket *sock, unsigned int *status)
  237. {
  238. struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
  239. skt->status = soc_common_pcmcia_skt_state(skt);
  240. *status = skt->status;
  241. return 0;
  242. }
  243. /*
  244. * Implements the set_socket() operation for the in-kernel PCMCIA
  245. * service (formerly SS_SetSocket in Card Services). We more or
  246. * less punt all of this work and let the kernel handle the details
  247. * of power configuration, reset, &c. We also record the value of
  248. * `state' in order to regurgitate it to the PCMCIA core later.
  249. */
  250. static int soc_common_pcmcia_set_socket(
  251. struct pcmcia_socket *sock, socket_state_t *state)
  252. {
  253. struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
  254. debug(skt, 2, "mask: %s%s%s%s%s%s flags: %s%s%s%s%s%s Vcc %d Vpp %d irq %d\n",
  255. (state->csc_mask == 0) ? "<NONE> " : "",
  256. (state->csc_mask & SS_DETECT) ? "DETECT " : "",
  257. (state->csc_mask & SS_READY) ? "READY " : "",
  258. (state->csc_mask & SS_BATDEAD) ? "BATDEAD " : "",
  259. (state->csc_mask & SS_BATWARN) ? "BATWARN " : "",
  260. (state->csc_mask & SS_STSCHG) ? "STSCHG " : "",
  261. (state->flags == 0) ? "<NONE> " : "",
  262. (state->flags & SS_PWR_AUTO) ? "PWR_AUTO " : "",
  263. (state->flags & SS_IOCARD) ? "IOCARD " : "",
  264. (state->flags & SS_RESET) ? "RESET " : "",
  265. (state->flags & SS_SPKR_ENA) ? "SPKR_ENA " : "",
  266. (state->flags & SS_OUTPUT_ENA) ? "OUTPUT_ENA " : "",
  267. state->Vcc, state->Vpp, state->io_irq);
  268. return soc_common_pcmcia_config_skt(skt, state);
  269. }
  270. /*
  271. * Implements the set_io_map() operation for the in-kernel PCMCIA
  272. * service (formerly SS_SetIOMap in Card Services). We configure
  273. * the map speed as requested, but override the address ranges
  274. * supplied by Card Services.
  275. *
  276. * Returns: 0 on success, -1 on error
  277. */
  278. static int soc_common_pcmcia_set_io_map(
  279. struct pcmcia_socket *sock, struct pccard_io_map *map)
  280. {
  281. struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
  282. unsigned short speed = map->speed;
  283. debug(skt, 2, "map %u speed %u start 0x%08llx stop 0x%08llx\n",
  284. map->map, map->speed, (unsigned long long)map->start,
  285. (unsigned long long)map->stop);
  286. debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
  287. (map->flags == 0) ? "<NONE>" : "",
  288. (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
  289. (map->flags & MAP_16BIT) ? "16BIT " : "",
  290. (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
  291. (map->flags & MAP_0WS) ? "0WS " : "",
  292. (map->flags & MAP_WRPROT) ? "WRPROT " : "",
  293. (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "",
  294. (map->flags & MAP_PREFETCH) ? "PREFETCH " : "");
  295. if (map->map >= MAX_IO_WIN) {
  296. printk(KERN_ERR "%s(): map (%d) out of range\n", __func__,
  297. map->map);
  298. return -1;
  299. }
  300. if (map->flags & MAP_ACTIVE) {
  301. if (speed == 0)
  302. speed = SOC_PCMCIA_IO_ACCESS;
  303. } else {
  304. speed = 0;
  305. }
  306. skt->spd_io[map->map] = speed;
  307. skt->ops->set_timing(skt);
  308. if (map->stop == 1)
  309. map->stop = PAGE_SIZE-1;
  310. map->stop -= map->start;
  311. map->stop += skt->socket.io_offset;
  312. map->start = skt->socket.io_offset;
  313. return 0;
  314. }
  315. /*
  316. * Implements the set_mem_map() operation for the in-kernel PCMCIA
  317. * service (formerly SS_SetMemMap in Card Services). We configure
  318. * the map speed as requested, but override the address ranges
  319. * supplied by Card Services.
  320. *
  321. * Returns: 0 on success, -ERRNO on error
  322. */
  323. static int soc_common_pcmcia_set_mem_map(
  324. struct pcmcia_socket *sock, struct pccard_mem_map *map)
  325. {
  326. struct soc_pcmcia_socket *skt = to_soc_pcmcia_socket(sock);
  327. struct resource *res;
  328. unsigned short speed = map->speed;
  329. debug(skt, 2, "map %u speed %u card_start %08x\n",
  330. map->map, map->speed, map->card_start);
  331. debug(skt, 2, "flags: %s%s%s%s%s%s%s%s\n",
  332. (map->flags == 0) ? "<NONE>" : "",
  333. (map->flags & MAP_ACTIVE) ? "ACTIVE " : "",
  334. (map->flags & MAP_16BIT) ? "16BIT " : "",
  335. (map->flags & MAP_AUTOSZ) ? "AUTOSZ " : "",
  336. (map->flags & MAP_0WS) ? "0WS " : "",
  337. (map->flags & MAP_WRPROT) ? "WRPROT " : "",
  338. (map->flags & MAP_ATTRIB) ? "ATTRIB " : "",
  339. (map->flags & MAP_USE_WAIT) ? "USE_WAIT " : "");
  340. if (map->map >= MAX_WIN)
  341. return -EINVAL;
  342. if (map->flags & MAP_ACTIVE) {
  343. if (speed == 0)
  344. speed = 300;
  345. } else {
  346. speed = 0;
  347. }
  348. if (map->flags & MAP_ATTRIB) {
  349. res = &skt->res_attr;
  350. skt->spd_attr[map->map] = speed;
  351. skt->spd_mem[map->map] = 0;
  352. } else {
  353. res = &skt->res_mem;
  354. skt->spd_attr[map->map] = 0;
  355. skt->spd_mem[map->map] = speed;
  356. }
  357. skt->ops->set_timing(skt);
  358. map->static_start = res->start + map->card_start;
  359. return 0;
  360. }
  361. struct bittbl {
  362. unsigned int mask;
  363. const char *name;
  364. };
  365. static struct bittbl status_bits[] = {
  366. { SS_WRPROT, "SS_WRPROT" },
  367. { SS_BATDEAD, "SS_BATDEAD" },
  368. { SS_BATWARN, "SS_BATWARN" },
  369. { SS_READY, "SS_READY" },
  370. { SS_DETECT, "SS_DETECT" },
  371. { SS_POWERON, "SS_POWERON" },
  372. { SS_STSCHG, "SS_STSCHG" },
  373. { SS_3VCARD, "SS_3VCARD" },
  374. { SS_XVCARD, "SS_XVCARD" },
  375. };
  376. static struct bittbl conf_bits[] = {
  377. { SS_PWR_AUTO, "SS_PWR_AUTO" },
  378. { SS_IOCARD, "SS_IOCARD" },
  379. { SS_RESET, "SS_RESET" },
  380. { SS_DMA_MODE, "SS_DMA_MODE" },
  381. { SS_SPKR_ENA, "SS_SPKR_ENA" },
  382. { SS_OUTPUT_ENA, "SS_OUTPUT_ENA" },
  383. };
  384. static void dump_bits(char **p, const char *prefix,
  385. unsigned int val, struct bittbl *bits, int sz)
  386. {
  387. char *b = *p;
  388. int i;
  389. b += sprintf(b, "%-9s:", prefix);
  390. for (i = 0; i < sz; i++)
  391. if (val & bits[i].mask)
  392. b += sprintf(b, " %s", bits[i].name);
  393. *b++ = '\n';
  394. *p = b;
  395. }
  396. /*
  397. * Implements the /sys/class/pcmcia_socket/??/status file.
  398. *
  399. * Returns: the number of characters added to the buffer
  400. */
  401. static ssize_t show_status(
  402. struct device *dev, struct device_attribute *attr, char *buf)
  403. {
  404. struct soc_pcmcia_socket *skt =
  405. container_of(dev, struct soc_pcmcia_socket, socket.dev);
  406. char *p = buf;
  407. p += sprintf(p, "slot : %d\n", skt->nr);
  408. dump_bits(&p, "status", skt->status,
  409. status_bits, ARRAY_SIZE(status_bits));
  410. dump_bits(&p, "csc_mask", skt->cs_state.csc_mask,
  411. status_bits, ARRAY_SIZE(status_bits));
  412. dump_bits(&p, "cs_flags", skt->cs_state.flags,
  413. conf_bits, ARRAY_SIZE(conf_bits));
  414. p += sprintf(p, "Vcc : %d\n", skt->cs_state.Vcc);
  415. p += sprintf(p, "Vpp : %d\n", skt->cs_state.Vpp);
  416. p += sprintf(p, "IRQ : %d (%d)\n", skt->cs_state.io_irq,
  417. skt->socket.pci_irq);
  418. if (skt->ops->show_timing)
  419. p += skt->ops->show_timing(skt, p);
  420. return p-buf;
  421. }
  422. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  423. static struct pccard_operations soc_common_pcmcia_operations = {
  424. .init = soc_common_pcmcia_sock_init,
  425. .suspend = soc_common_pcmcia_suspend,
  426. .get_status = soc_common_pcmcia_get_status,
  427. .set_socket = soc_common_pcmcia_set_socket,
  428. .set_io_map = soc_common_pcmcia_set_io_map,
  429. .set_mem_map = soc_common_pcmcia_set_mem_map,
  430. };
  431. int soc_pcmcia_request_irqs(struct soc_pcmcia_socket *skt,
  432. struct pcmcia_irqs *irqs, int nr)
  433. {
  434. int i, res = 0;
  435. for (i = 0; i < nr; i++) {
  436. if (irqs[i].sock != skt->nr)
  437. continue;
  438. res = request_irq(irqs[i].irq, soc_common_pcmcia_interrupt,
  439. IRQF_DISABLED, irqs[i].str, skt);
  440. if (res)
  441. break;
  442. irq_set_irq_type(irqs[i].irq, IRQ_TYPE_NONE);
  443. }
  444. if (res) {
  445. printk(KERN_ERR "PCMCIA: request for IRQ%d failed (%d)\n",
  446. irqs[i].irq, res);
  447. while (i--)
  448. if (irqs[i].sock == skt->nr)
  449. free_irq(irqs[i].irq, skt);
  450. }
  451. return res;
  452. }
  453. EXPORT_SYMBOL(soc_pcmcia_request_irqs);
  454. void soc_pcmcia_free_irqs(struct soc_pcmcia_socket *skt,
  455. struct pcmcia_irqs *irqs, int nr)
  456. {
  457. int i;
  458. for (i = 0; i < nr; i++)
  459. if (irqs[i].sock == skt->nr)
  460. free_irq(irqs[i].irq, skt);
  461. }
  462. EXPORT_SYMBOL(soc_pcmcia_free_irqs);
  463. void soc_pcmcia_disable_irqs(struct soc_pcmcia_socket *skt,
  464. struct pcmcia_irqs *irqs, int nr)
  465. {
  466. int i;
  467. for (i = 0; i < nr; i++)
  468. if (irqs[i].sock == skt->nr)
  469. irq_set_irq_type(irqs[i].irq, IRQ_TYPE_NONE);
  470. }
  471. EXPORT_SYMBOL(soc_pcmcia_disable_irqs);
  472. void soc_pcmcia_enable_irqs(struct soc_pcmcia_socket *skt,
  473. struct pcmcia_irqs *irqs, int nr)
  474. {
  475. int i;
  476. for (i = 0; i < nr; i++)
  477. if (irqs[i].sock == skt->nr) {
  478. irq_set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_RISING);
  479. irq_set_irq_type(irqs[i].irq, IRQ_TYPE_EDGE_BOTH);
  480. }
  481. }
  482. EXPORT_SYMBOL(soc_pcmcia_enable_irqs);
  483. static LIST_HEAD(soc_pcmcia_sockets);
  484. static DEFINE_MUTEX(soc_pcmcia_sockets_lock);
  485. #ifdef CONFIG_CPU_FREQ
  486. static int
  487. soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
  488. {
  489. struct soc_pcmcia_socket *skt;
  490. struct cpufreq_freqs *freqs = data;
  491. int ret = 0;
  492. mutex_lock(&soc_pcmcia_sockets_lock);
  493. list_for_each_entry(skt, &soc_pcmcia_sockets, node)
  494. if (skt->ops->frequency_change)
  495. ret += skt->ops->frequency_change(skt, val, freqs);
  496. mutex_unlock(&soc_pcmcia_sockets_lock);
  497. return ret;
  498. }
  499. static struct notifier_block soc_pcmcia_notifier_block = {
  500. .notifier_call = soc_pcmcia_notifier
  501. };
  502. static int soc_pcmcia_cpufreq_register(void)
  503. {
  504. int ret;
  505. ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
  506. CPUFREQ_TRANSITION_NOTIFIER);
  507. if (ret < 0)
  508. printk(KERN_ERR "Unable to register CPU frequency change "
  509. "notifier for PCMCIA (%d)\n", ret);
  510. return ret;
  511. }
  512. fs_initcall(soc_pcmcia_cpufreq_register);
  513. static void soc_pcmcia_cpufreq_unregister(void)
  514. {
  515. cpufreq_unregister_notifier(&soc_pcmcia_notifier_block,
  516. CPUFREQ_TRANSITION_NOTIFIER);
  517. }
  518. module_exit(soc_pcmcia_cpufreq_unregister);
  519. #endif
  520. void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt)
  521. {
  522. mutex_lock(&soc_pcmcia_sockets_lock);
  523. del_timer_sync(&skt->poll_timer);
  524. pcmcia_unregister_socket(&skt->socket);
  525. skt->ops->hw_shutdown(skt);
  526. soc_common_pcmcia_config_skt(skt, &dead_socket);
  527. list_del(&skt->node);
  528. mutex_unlock(&soc_pcmcia_sockets_lock);
  529. iounmap(skt->virt_io);
  530. skt->virt_io = NULL;
  531. release_resource(&skt->res_attr);
  532. release_resource(&skt->res_mem);
  533. release_resource(&skt->res_io);
  534. release_resource(&skt->res_skt);
  535. }
  536. EXPORT_SYMBOL(soc_pcmcia_remove_one);
  537. int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt)
  538. {
  539. int ret;
  540. init_timer(&skt->poll_timer);
  541. skt->poll_timer.function = soc_common_pcmcia_poll_event;
  542. skt->poll_timer.data = (unsigned long)skt;
  543. skt->poll_timer.expires = jiffies + SOC_PCMCIA_POLL_PERIOD;
  544. ret = request_resource(&iomem_resource, &skt->res_skt);
  545. if (ret)
  546. goto out_err_1;
  547. ret = request_resource(&skt->res_skt, &skt->res_io);
  548. if (ret)
  549. goto out_err_2;
  550. ret = request_resource(&skt->res_skt, &skt->res_mem);
  551. if (ret)
  552. goto out_err_3;
  553. ret = request_resource(&skt->res_skt, &skt->res_attr);
  554. if (ret)
  555. goto out_err_4;
  556. skt->virt_io = ioremap(skt->res_io.start, 0x10000);
  557. if (skt->virt_io == NULL) {
  558. ret = -ENOMEM;
  559. goto out_err_5;
  560. }
  561. mutex_lock(&soc_pcmcia_sockets_lock);
  562. list_add(&skt->node, &soc_pcmcia_sockets);
  563. /*
  564. * We initialize default socket timing here, because
  565. * we are not guaranteed to see a SetIOMap operation at
  566. * runtime.
  567. */
  568. skt->ops->set_timing(skt);
  569. ret = skt->ops->hw_init(skt);
  570. if (ret)
  571. goto out_err_6;
  572. skt->socket.ops = &soc_common_pcmcia_operations;
  573. skt->socket.features = SS_CAP_STATIC_MAP|SS_CAP_PCCARD;
  574. skt->socket.resource_ops = &pccard_static_ops;
  575. skt->socket.irq_mask = 0;
  576. skt->socket.map_size = PAGE_SIZE;
  577. skt->socket.io_offset = (unsigned long)skt->virt_io;
  578. skt->status = soc_common_pcmcia_skt_state(skt);
  579. ret = pcmcia_register_socket(&skt->socket);
  580. if (ret)
  581. goto out_err_7;
  582. add_timer(&skt->poll_timer);
  583. mutex_unlock(&soc_pcmcia_sockets_lock);
  584. ret = device_create_file(&skt->socket.dev, &dev_attr_status);
  585. if (ret)
  586. goto out_err_8;
  587. return ret;
  588. out_err_8:
  589. mutex_lock(&soc_pcmcia_sockets_lock);
  590. del_timer_sync(&skt->poll_timer);
  591. pcmcia_unregister_socket(&skt->socket);
  592. out_err_7:
  593. skt->ops->hw_shutdown(skt);
  594. out_err_6:
  595. list_del(&skt->node);
  596. mutex_unlock(&soc_pcmcia_sockets_lock);
  597. iounmap(skt->virt_io);
  598. out_err_5:
  599. release_resource(&skt->res_attr);
  600. out_err_4:
  601. release_resource(&skt->res_mem);
  602. out_err_3:
  603. release_resource(&skt->res_io);
  604. out_err_2:
  605. release_resource(&skt->res_skt);
  606. out_err_1:
  607. return ret;
  608. }
  609. EXPORT_SYMBOL(soc_pcmcia_add_one);
  610. MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
  611. MODULE_DESCRIPTION("Linux PCMCIA Card Services: Common SoC support");
  612. MODULE_LICENSE("Dual MPL/GPL");