yenta_socket.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. /*
  2. * Regular cardbus driver ("yenta_socket")
  3. *
  4. * (C) Copyright 1999, 2000 Linus Torvalds
  5. *
  6. * Changelog:
  7. * Aug 2002: Manfred Spraul <manfred@colorfullife.com>
  8. * Dynamically adjust the size of the bridge resource
  9. *
  10. * May 2003: Dominik Brodowski <linux@brodo.de>
  11. * Merge pci_socket.c and yenta.c into one file
  12. */
  13. #include <linux/init.h>
  14. #include <linux/pci.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/delay.h>
  18. #include <linux/module.h>
  19. #include <linux/io.h>
  20. #include <linux/slab.h>
  21. #include <pcmcia/ss.h>
  22. #include "yenta_socket.h"
  23. #include "i82365.h"
  24. static bool disable_clkrun;
  25. module_param(disable_clkrun, bool, 0444);
  26. MODULE_PARM_DESC(disable_clkrun, "If PC card doesn't function properly, please try this option");
  27. static bool isa_probe = 1;
  28. module_param(isa_probe, bool, 0444);
  29. MODULE_PARM_DESC(isa_probe, "If set ISA interrupts are probed (default). Set to N to disable probing");
  30. static bool pwr_irqs_off;
  31. module_param(pwr_irqs_off, bool, 0644);
  32. MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!");
  33. static char o2_speedup[] = "default";
  34. module_param_string(o2_speedup, o2_speedup, sizeof(o2_speedup), 0444);
  35. MODULE_PARM_DESC(o2_speedup, "Use prefetch/burst for O2-bridges: 'on', 'off' "
  36. "or 'default' (uses recommended behaviour for the detected bridge)");
  37. /*
  38. * Only probe "regular" interrupts, don't
  39. * touch dangerous spots like the mouse irq,
  40. * because there are mice that apparently
  41. * get really confused if they get fondled
  42. * too intimately.
  43. *
  44. * Default to 11, 10, 9, 7, 6, 5, 4, 3.
  45. */
  46. static u32 isa_interrupts = 0x0ef8;
  47. #define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args)
  48. /* Don't ask.. */
  49. #define to_cycles(ns) ((ns)/120)
  50. #define to_ns(cycles) ((cycles)*120)
  51. /*
  52. * yenta PCI irq probing.
  53. * currently only used in the TI/EnE initialization code
  54. */
  55. #ifdef CONFIG_YENTA_TI
  56. static int yenta_probe_cb_irq(struct yenta_socket *socket);
  57. static unsigned int yenta_probe_irq(struct yenta_socket *socket,
  58. u32 isa_irq_mask);
  59. #endif
  60. static unsigned int override_bios;
  61. module_param(override_bios, uint, 0000);
  62. MODULE_PARM_DESC(override_bios, "yenta ignore bios resource allocation");
  63. /*
  64. * Generate easy-to-use ways of reading a cardbus sockets
  65. * regular memory space ("cb_xxx"), configuration space
  66. * ("config_xxx") and compatibility space ("exca_xxxx")
  67. */
  68. static inline u32 cb_readl(struct yenta_socket *socket, unsigned reg)
  69. {
  70. u32 val = readl(socket->base + reg);
  71. debug("%04x %08x\n", socket, reg, val);
  72. return val;
  73. }
  74. static inline void cb_writel(struct yenta_socket *socket, unsigned reg, u32 val)
  75. {
  76. debug("%04x %08x\n", socket, reg, val);
  77. writel(val, socket->base + reg);
  78. readl(socket->base + reg); /* avoid problems with PCI write posting */
  79. }
  80. static inline u8 config_readb(struct yenta_socket *socket, unsigned offset)
  81. {
  82. u8 val;
  83. pci_read_config_byte(socket->dev, offset, &val);
  84. debug("%04x %02x\n", socket, offset, val);
  85. return val;
  86. }
  87. static inline u16 config_readw(struct yenta_socket *socket, unsigned offset)
  88. {
  89. u16 val;
  90. pci_read_config_word(socket->dev, offset, &val);
  91. debug("%04x %04x\n", socket, offset, val);
  92. return val;
  93. }
  94. static inline u32 config_readl(struct yenta_socket *socket, unsigned offset)
  95. {
  96. u32 val;
  97. pci_read_config_dword(socket->dev, offset, &val);
  98. debug("%04x %08x\n", socket, offset, val);
  99. return val;
  100. }
  101. static inline void config_writeb(struct yenta_socket *socket, unsigned offset, u8 val)
  102. {
  103. debug("%04x %02x\n", socket, offset, val);
  104. pci_write_config_byte(socket->dev, offset, val);
  105. }
  106. static inline void config_writew(struct yenta_socket *socket, unsigned offset, u16 val)
  107. {
  108. debug("%04x %04x\n", socket, offset, val);
  109. pci_write_config_word(socket->dev, offset, val);
  110. }
  111. static inline void config_writel(struct yenta_socket *socket, unsigned offset, u32 val)
  112. {
  113. debug("%04x %08x\n", socket, offset, val);
  114. pci_write_config_dword(socket->dev, offset, val);
  115. }
  116. static inline u8 exca_readb(struct yenta_socket *socket, unsigned reg)
  117. {
  118. u8 val = readb(socket->base + 0x800 + reg);
  119. debug("%04x %02x\n", socket, reg, val);
  120. return val;
  121. }
  122. static inline u8 exca_readw(struct yenta_socket *socket, unsigned reg)
  123. {
  124. u16 val;
  125. val = readb(socket->base + 0x800 + reg);
  126. val |= readb(socket->base + 0x800 + reg + 1) << 8;
  127. debug("%04x %04x\n", socket, reg, val);
  128. return val;
  129. }
  130. static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val)
  131. {
  132. debug("%04x %02x\n", socket, reg, val);
  133. writeb(val, socket->base + 0x800 + reg);
  134. readb(socket->base + 0x800 + reg); /* PCI write posting... */
  135. }
  136. static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val)
  137. {
  138. debug("%04x %04x\n", socket, reg, val);
  139. writeb(val, socket->base + 0x800 + reg);
  140. writeb(val >> 8, socket->base + 0x800 + reg + 1);
  141. /* PCI write posting... */
  142. readb(socket->base + 0x800 + reg);
  143. readb(socket->base + 0x800 + reg + 1);
  144. }
  145. static ssize_t show_yenta_registers(struct device *yentadev, struct device_attribute *attr, char *buf)
  146. {
  147. struct pci_dev *dev = to_pci_dev(yentadev);
  148. struct yenta_socket *socket = pci_get_drvdata(dev);
  149. int offset = 0, i;
  150. offset = snprintf(buf, PAGE_SIZE, "CB registers:");
  151. for (i = 0; i < 0x24; i += 4) {
  152. unsigned val;
  153. if (!(i & 15))
  154. offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
  155. val = cb_readl(socket, i);
  156. offset += snprintf(buf + offset, PAGE_SIZE - offset, " %08x", val);
  157. }
  158. offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:");
  159. for (i = 0; i < 0x45; i++) {
  160. unsigned char val;
  161. if (!(i & 7)) {
  162. if (i & 8) {
  163. memcpy(buf + offset, " -", 2);
  164. offset += 2;
  165. } else
  166. offset += snprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i);
  167. }
  168. val = exca_readb(socket, i);
  169. offset += snprintf(buf + offset, PAGE_SIZE - offset, " %02x", val);
  170. }
  171. buf[offset++] = '\n';
  172. return offset;
  173. }
  174. static DEVICE_ATTR(yenta_registers, S_IRUSR, show_yenta_registers, NULL);
  175. /*
  176. * Ugh, mixed-mode cardbus and 16-bit pccard state: things depend
  177. * on what kind of card is inserted..
  178. */
  179. static int yenta_get_status(struct pcmcia_socket *sock, unsigned int *value)
  180. {
  181. struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
  182. unsigned int val;
  183. u32 state = cb_readl(socket, CB_SOCKET_STATE);
  184. val = (state & CB_3VCARD) ? SS_3VCARD : 0;
  185. val |= (state & CB_XVCARD) ? SS_XVCARD : 0;
  186. val |= (state & (CB_5VCARD | CB_3VCARD | CB_XVCARD | CB_YVCARD)) ? 0 : SS_PENDING;
  187. val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? SS_PENDING : 0;
  188. if (state & CB_CBCARD) {
  189. val |= SS_CARDBUS;
  190. val |= (state & CB_CARDSTS) ? SS_STSCHG : 0;
  191. val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? 0 : SS_DETECT;
  192. val |= (state & CB_PWRCYCLE) ? SS_POWERON | SS_READY : 0;
  193. } else if (state & CB_16BITCARD) {
  194. u8 status = exca_readb(socket, I365_STATUS);
  195. val |= ((status & I365_CS_DETECT) == I365_CS_DETECT) ? SS_DETECT : 0;
  196. if (exca_readb(socket, I365_INTCTL) & I365_PC_IOCARD) {
  197. val |= (status & I365_CS_STSCHG) ? 0 : SS_STSCHG;
  198. } else {
  199. val |= (status & I365_CS_BVD1) ? 0 : SS_BATDEAD;
  200. val |= (status & I365_CS_BVD2) ? 0 : SS_BATWARN;
  201. }
  202. val |= (status & I365_CS_WRPROT) ? SS_WRPROT : 0;
  203. val |= (status & I365_CS_READY) ? SS_READY : 0;
  204. val |= (status & I365_CS_POWERON) ? SS_POWERON : 0;
  205. }
  206. *value = val;
  207. return 0;
  208. }
  209. static void yenta_set_power(struct yenta_socket *socket, socket_state_t *state)
  210. {
  211. /* some birdges require to use the ExCA registers to power 16bit cards */
  212. if (!(cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) &&
  213. (socket->flags & YENTA_16BIT_POWER_EXCA)) {
  214. u8 reg, old;
  215. reg = old = exca_readb(socket, I365_POWER);
  216. reg &= ~(I365_VCC_MASK | I365_VPP1_MASK | I365_VPP2_MASK);
  217. /* i82365SL-DF style */
  218. if (socket->flags & YENTA_16BIT_POWER_DF) {
  219. switch (state->Vcc) {
  220. case 33:
  221. reg |= I365_VCC_3V;
  222. break;
  223. case 50:
  224. reg |= I365_VCC_5V;
  225. break;
  226. default:
  227. reg = 0;
  228. break;
  229. }
  230. switch (state->Vpp) {
  231. case 33:
  232. case 50:
  233. reg |= I365_VPP1_5V;
  234. break;
  235. case 120:
  236. reg |= I365_VPP1_12V;
  237. break;
  238. }
  239. } else {
  240. /* i82365SL-B style */
  241. switch (state->Vcc) {
  242. case 50:
  243. reg |= I365_VCC_5V;
  244. break;
  245. default:
  246. reg = 0;
  247. break;
  248. }
  249. switch (state->Vpp) {
  250. case 50:
  251. reg |= I365_VPP1_5V | I365_VPP2_5V;
  252. break;
  253. case 120:
  254. reg |= I365_VPP1_12V | I365_VPP2_12V;
  255. break;
  256. }
  257. }
  258. if (reg != old)
  259. exca_writeb(socket, I365_POWER, reg);
  260. } else {
  261. u32 reg = 0; /* CB_SC_STPCLK? */
  262. switch (state->Vcc) {
  263. case 33:
  264. reg = CB_SC_VCC_3V;
  265. break;
  266. case 50:
  267. reg = CB_SC_VCC_5V;
  268. break;
  269. default:
  270. reg = 0;
  271. break;
  272. }
  273. switch (state->Vpp) {
  274. case 33:
  275. reg |= CB_SC_VPP_3V;
  276. break;
  277. case 50:
  278. reg |= CB_SC_VPP_5V;
  279. break;
  280. case 120:
  281. reg |= CB_SC_VPP_12V;
  282. break;
  283. }
  284. if (reg != cb_readl(socket, CB_SOCKET_CONTROL))
  285. cb_writel(socket, CB_SOCKET_CONTROL, reg);
  286. }
  287. }
  288. static int yenta_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
  289. {
  290. struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
  291. u16 bridge;
  292. /* if powering down: do it immediately */
  293. if (state->Vcc == 0)
  294. yenta_set_power(socket, state);
  295. socket->io_irq = state->io_irq;
  296. bridge = config_readw(socket, CB_BRIDGE_CONTROL) & ~(CB_BRIDGE_CRST | CB_BRIDGE_INTR);
  297. if (cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) {
  298. u8 intr;
  299. bridge |= (state->flags & SS_RESET) ? CB_BRIDGE_CRST : 0;
  300. /* ISA interrupt control? */
  301. intr = exca_readb(socket, I365_INTCTL);
  302. intr = (intr & ~0xf);
  303. if (!socket->dev->irq) {
  304. intr |= socket->cb_irq ? socket->cb_irq : state->io_irq;
  305. bridge |= CB_BRIDGE_INTR;
  306. }
  307. exca_writeb(socket, I365_INTCTL, intr);
  308. } else {
  309. u8 reg;
  310. reg = exca_readb(socket, I365_INTCTL) & (I365_RING_ENA | I365_INTR_ENA);
  311. reg |= (state->flags & SS_RESET) ? 0 : I365_PC_RESET;
  312. reg |= (state->flags & SS_IOCARD) ? I365_PC_IOCARD : 0;
  313. if (state->io_irq != socket->dev->irq) {
  314. reg |= state->io_irq;
  315. bridge |= CB_BRIDGE_INTR;
  316. }
  317. exca_writeb(socket, I365_INTCTL, reg);
  318. reg = exca_readb(socket, I365_POWER) & (I365_VCC_MASK|I365_VPP1_MASK);
  319. reg |= I365_PWR_NORESET;
  320. if (state->flags & SS_PWR_AUTO)
  321. reg |= I365_PWR_AUTO;
  322. if (state->flags & SS_OUTPUT_ENA)
  323. reg |= I365_PWR_OUT;
  324. if (exca_readb(socket, I365_POWER) != reg)
  325. exca_writeb(socket, I365_POWER, reg);
  326. /* CSC interrupt: no ISA irq for CSC */
  327. reg = exca_readb(socket, I365_CSCINT);
  328. reg &= I365_CSC_IRQ_MASK;
  329. reg |= I365_CSC_DETECT;
  330. if (state->flags & SS_IOCARD) {
  331. if (state->csc_mask & SS_STSCHG)
  332. reg |= I365_CSC_STSCHG;
  333. } else {
  334. if (state->csc_mask & SS_BATDEAD)
  335. reg |= I365_CSC_BVD1;
  336. if (state->csc_mask & SS_BATWARN)
  337. reg |= I365_CSC_BVD2;
  338. if (state->csc_mask & SS_READY)
  339. reg |= I365_CSC_READY;
  340. }
  341. exca_writeb(socket, I365_CSCINT, reg);
  342. exca_readb(socket, I365_CSC);
  343. if (sock->zoom_video)
  344. sock->zoom_video(sock, state->flags & SS_ZVCARD);
  345. }
  346. config_writew(socket, CB_BRIDGE_CONTROL, bridge);
  347. /* Socket event mask: get card insert/remove events.. */
  348. cb_writel(socket, CB_SOCKET_EVENT, -1);
  349. cb_writel(socket, CB_SOCKET_MASK, CB_CDMASK);
  350. /* if powering up: do it as the last step when the socket is configured */
  351. if (state->Vcc != 0)
  352. yenta_set_power(socket, state);
  353. return 0;
  354. }
  355. static int yenta_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io)
  356. {
  357. struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
  358. int map;
  359. unsigned char ioctl, addr, enable;
  360. map = io->map;
  361. if (map > 1)
  362. return -EINVAL;
  363. enable = I365_ENA_IO(map);
  364. addr = exca_readb(socket, I365_ADDRWIN);
  365. /* Disable the window before changing it.. */
  366. if (addr & enable) {
  367. addr &= ~enable;
  368. exca_writeb(socket, I365_ADDRWIN, addr);
  369. }
  370. exca_writew(socket, I365_IO(map)+I365_W_START, io->start);
  371. exca_writew(socket, I365_IO(map)+I365_W_STOP, io->stop);
  372. ioctl = exca_readb(socket, I365_IOCTL) & ~I365_IOCTL_MASK(map);
  373. if (io->flags & MAP_0WS)
  374. ioctl |= I365_IOCTL_0WS(map);
  375. if (io->flags & MAP_16BIT)
  376. ioctl |= I365_IOCTL_16BIT(map);
  377. if (io->flags & MAP_AUTOSZ)
  378. ioctl |= I365_IOCTL_IOCS16(map);
  379. exca_writeb(socket, I365_IOCTL, ioctl);
  380. if (io->flags & MAP_ACTIVE)
  381. exca_writeb(socket, I365_ADDRWIN, addr | enable);
  382. return 0;
  383. }
  384. static int yenta_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *mem)
  385. {
  386. struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
  387. struct pci_bus_region region;
  388. int map;
  389. unsigned char addr, enable;
  390. unsigned int start, stop, card_start;
  391. unsigned short word;
  392. pcibios_resource_to_bus(socket->dev->bus, &region, mem->res);
  393. map = mem->map;
  394. start = region.start;
  395. stop = region.end;
  396. card_start = mem->card_start;
  397. if (map > 4 || start > stop || ((start ^ stop) >> 24) ||
  398. (card_start >> 26) || mem->speed > 1000)
  399. return -EINVAL;
  400. enable = I365_ENA_MEM(map);
  401. addr = exca_readb(socket, I365_ADDRWIN);
  402. if (addr & enable) {
  403. addr &= ~enable;
  404. exca_writeb(socket, I365_ADDRWIN, addr);
  405. }
  406. exca_writeb(socket, CB_MEM_PAGE(map), start >> 24);
  407. word = (start >> 12) & 0x0fff;
  408. if (mem->flags & MAP_16BIT)
  409. word |= I365_MEM_16BIT;
  410. if (mem->flags & MAP_0WS)
  411. word |= I365_MEM_0WS;
  412. exca_writew(socket, I365_MEM(map) + I365_W_START, word);
  413. word = (stop >> 12) & 0x0fff;
  414. switch (to_cycles(mem->speed)) {
  415. case 0:
  416. break;
  417. case 1:
  418. word |= I365_MEM_WS0;
  419. break;
  420. case 2:
  421. word |= I365_MEM_WS1;
  422. break;
  423. default:
  424. word |= I365_MEM_WS1 | I365_MEM_WS0;
  425. break;
  426. }
  427. exca_writew(socket, I365_MEM(map) + I365_W_STOP, word);
  428. word = ((card_start - start) >> 12) & 0x3fff;
  429. if (mem->flags & MAP_WRPROT)
  430. word |= I365_MEM_WRPROT;
  431. if (mem->flags & MAP_ATTRIB)
  432. word |= I365_MEM_REG;
  433. exca_writew(socket, I365_MEM(map) + I365_W_OFF, word);
  434. if (mem->flags & MAP_ACTIVE)
  435. exca_writeb(socket, I365_ADDRWIN, addr | enable);
  436. return 0;
  437. }
  438. static irqreturn_t yenta_interrupt(int irq, void *dev_id)
  439. {
  440. unsigned int events;
  441. struct yenta_socket *socket = (struct yenta_socket *) dev_id;
  442. u8 csc;
  443. u32 cb_event;
  444. /* Clear interrupt status for the event */
  445. cb_event = cb_readl(socket, CB_SOCKET_EVENT);
  446. cb_writel(socket, CB_SOCKET_EVENT, cb_event);
  447. csc = exca_readb(socket, I365_CSC);
  448. if (!(cb_event || csc))
  449. return IRQ_NONE;
  450. events = (cb_event & (CB_CD1EVENT | CB_CD2EVENT)) ? SS_DETECT : 0 ;
  451. events |= (csc & I365_CSC_DETECT) ? SS_DETECT : 0;
  452. if (exca_readb(socket, I365_INTCTL) & I365_PC_IOCARD) {
  453. events |= (csc & I365_CSC_STSCHG) ? SS_STSCHG : 0;
  454. } else {
  455. events |= (csc & I365_CSC_BVD1) ? SS_BATDEAD : 0;
  456. events |= (csc & I365_CSC_BVD2) ? SS_BATWARN : 0;
  457. events |= (csc & I365_CSC_READY) ? SS_READY : 0;
  458. }
  459. if (events)
  460. pcmcia_parse_events(&socket->socket, events);
  461. return IRQ_HANDLED;
  462. }
  463. static void yenta_interrupt_wrapper(unsigned long data)
  464. {
  465. struct yenta_socket *socket = (struct yenta_socket *) data;
  466. yenta_interrupt(0, (void *)socket);
  467. socket->poll_timer.expires = jiffies + HZ;
  468. add_timer(&socket->poll_timer);
  469. }
  470. static void yenta_clear_maps(struct yenta_socket *socket)
  471. {
  472. int i;
  473. struct resource res = { .start = 0, .end = 0x0fff };
  474. pccard_io_map io = { 0, 0, 0, 0, 1 };
  475. pccard_mem_map mem = { .res = &res, };
  476. yenta_set_socket(&socket->socket, &dead_socket);
  477. for (i = 0; i < 2; i++) {
  478. io.map = i;
  479. yenta_set_io_map(&socket->socket, &io);
  480. }
  481. for (i = 0; i < 5; i++) {
  482. mem.map = i;
  483. yenta_set_mem_map(&socket->socket, &mem);
  484. }
  485. }
  486. /* redoes voltage interrogation if required */
  487. static void yenta_interrogate(struct yenta_socket *socket)
  488. {
  489. u32 state;
  490. state = cb_readl(socket, CB_SOCKET_STATE);
  491. if (!(state & (CB_5VCARD | CB_3VCARD | CB_XVCARD | CB_YVCARD)) ||
  492. (state & (CB_CDETECT1 | CB_CDETECT2 | CB_NOTACARD | CB_BADVCCREQ)) ||
  493. ((state & (CB_16BITCARD | CB_CBCARD)) == (CB_16BITCARD | CB_CBCARD)))
  494. cb_writel(socket, CB_SOCKET_FORCE, CB_CVSTEST);
  495. }
  496. /* Called at resume and initialization events */
  497. static int yenta_sock_init(struct pcmcia_socket *sock)
  498. {
  499. struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
  500. exca_writeb(socket, I365_GBLCTL, 0x00);
  501. exca_writeb(socket, I365_GENCTL, 0x00);
  502. /* Redo card voltage interrogation */
  503. yenta_interrogate(socket);
  504. yenta_clear_maps(socket);
  505. if (socket->type && socket->type->sock_init)
  506. socket->type->sock_init(socket);
  507. /* Re-enable CSC interrupts */
  508. cb_writel(socket, CB_SOCKET_MASK, CB_CDMASK);
  509. return 0;
  510. }
  511. static int yenta_sock_suspend(struct pcmcia_socket *sock)
  512. {
  513. struct yenta_socket *socket = container_of(sock, struct yenta_socket, socket);
  514. /* Disable CSC interrupts */
  515. cb_writel(socket, CB_SOCKET_MASK, 0x0);
  516. return 0;
  517. }
  518. /*
  519. * Use an adaptive allocation for the memory resource,
  520. * sometimes the memory behind pci bridges is limited:
  521. * 1/8 of the size of the io window of the parent.
  522. * max 4 MB, min 16 kB. We try very hard to not get below
  523. * the "ACC" values, though.
  524. */
  525. #define BRIDGE_MEM_MAX (4*1024*1024)
  526. #define BRIDGE_MEM_ACC (128*1024)
  527. #define BRIDGE_MEM_MIN (16*1024)
  528. #define BRIDGE_IO_MAX 512
  529. #define BRIDGE_IO_ACC 256
  530. #define BRIDGE_IO_MIN 32
  531. #ifndef PCIBIOS_MIN_CARDBUS_IO
  532. #define PCIBIOS_MIN_CARDBUS_IO PCIBIOS_MIN_IO
  533. #endif
  534. static int yenta_search_one_res(struct resource *root, struct resource *res,
  535. u32 min)
  536. {
  537. u32 align, size, start, end;
  538. if (res->flags & IORESOURCE_IO) {
  539. align = 1024;
  540. size = BRIDGE_IO_MAX;
  541. start = PCIBIOS_MIN_CARDBUS_IO;
  542. end = ~0U;
  543. } else {
  544. unsigned long avail = root->end - root->start;
  545. int i;
  546. size = BRIDGE_MEM_MAX;
  547. if (size > avail/8) {
  548. size = (avail+1)/8;
  549. /* round size down to next power of 2 */
  550. i = 0;
  551. while ((size /= 2) != 0)
  552. i++;
  553. size = 1 << i;
  554. }
  555. if (size < min)
  556. size = min;
  557. align = size;
  558. start = PCIBIOS_MIN_MEM;
  559. end = ~0U;
  560. }
  561. do {
  562. if (allocate_resource(root, res, size, start, end, align,
  563. NULL, NULL) == 0) {
  564. return 1;
  565. }
  566. size = size/2;
  567. align = size;
  568. } while (size >= min);
  569. return 0;
  570. }
  571. static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
  572. u32 min)
  573. {
  574. struct resource *root;
  575. int i;
  576. pci_bus_for_each_resource(socket->dev->bus, root, i) {
  577. if (!root)
  578. continue;
  579. if ((res->flags ^ root->flags) &
  580. (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH))
  581. continue; /* Wrong type */
  582. if (yenta_search_one_res(root, res, min))
  583. return 1;
  584. }
  585. return 0;
  586. }
  587. static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type, int addr_start, int addr_end)
  588. {
  589. struct pci_dev *dev = socket->dev;
  590. struct resource *res;
  591. struct pci_bus_region region;
  592. unsigned mask;
  593. res = dev->resource + PCI_BRIDGE_RESOURCES + nr;
  594. /* Already allocated? */
  595. if (res->parent)
  596. return 0;
  597. /* The granularity of the memory limit is 4kB, on IO it's 4 bytes */
  598. mask = ~0xfff;
  599. if (type & IORESOURCE_IO)
  600. mask = ~3;
  601. res->name = dev->subordinate->name;
  602. res->flags = type;
  603. region.start = config_readl(socket, addr_start) & mask;
  604. region.end = config_readl(socket, addr_end) | ~mask;
  605. if (region.start && region.end > region.start && !override_bios) {
  606. pcibios_bus_to_resource(dev->bus, res, &region);
  607. if (pci_claim_resource(dev, PCI_BRIDGE_RESOURCES + nr) == 0)
  608. return 0;
  609. dev_info(&dev->dev,
  610. "Preassigned resource %d busy or not available, reconfiguring...\n",
  611. nr);
  612. }
  613. if (type & IORESOURCE_IO) {
  614. if ((yenta_search_res(socket, res, BRIDGE_IO_MAX)) ||
  615. (yenta_search_res(socket, res, BRIDGE_IO_ACC)) ||
  616. (yenta_search_res(socket, res, BRIDGE_IO_MIN)))
  617. return 1;
  618. } else {
  619. if (type & IORESOURCE_PREFETCH) {
  620. if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
  621. (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
  622. (yenta_search_res(socket, res, BRIDGE_MEM_MIN)))
  623. return 1;
  624. /* Approximating prefetchable by non-prefetchable */
  625. res->flags = IORESOURCE_MEM;
  626. }
  627. if ((yenta_search_res(socket, res, BRIDGE_MEM_MAX)) ||
  628. (yenta_search_res(socket, res, BRIDGE_MEM_ACC)) ||
  629. (yenta_search_res(socket, res, BRIDGE_MEM_MIN)))
  630. return 1;
  631. }
  632. dev_info(&dev->dev,
  633. "no resource of type %x available, trying to continue...\n",
  634. type);
  635. res->start = res->end = res->flags = 0;
  636. return 0;
  637. }
  638. /*
  639. * Allocate the bridge mappings for the device..
  640. */
  641. static void yenta_allocate_resources(struct yenta_socket *socket)
  642. {
  643. int program = 0;
  644. program += yenta_allocate_res(socket, 0, IORESOURCE_IO,
  645. PCI_CB_IO_BASE_0, PCI_CB_IO_LIMIT_0);
  646. program += yenta_allocate_res(socket, 1, IORESOURCE_IO,
  647. PCI_CB_IO_BASE_1, PCI_CB_IO_LIMIT_1);
  648. program += yenta_allocate_res(socket, 2, IORESOURCE_MEM|IORESOURCE_PREFETCH,
  649. PCI_CB_MEMORY_BASE_0, PCI_CB_MEMORY_LIMIT_0);
  650. program += yenta_allocate_res(socket, 3, IORESOURCE_MEM,
  651. PCI_CB_MEMORY_BASE_1, PCI_CB_MEMORY_LIMIT_1);
  652. if (program)
  653. pci_setup_cardbus(socket->dev->subordinate);
  654. }
  655. /*
  656. * Free the bridge mappings for the device..
  657. */
  658. static void yenta_free_resources(struct yenta_socket *socket)
  659. {
  660. int i;
  661. for (i = 0; i < 4; i++) {
  662. struct resource *res;
  663. res = socket->dev->resource + PCI_BRIDGE_RESOURCES + i;
  664. if (res->start != 0 && res->end != 0)
  665. release_resource(res);
  666. res->start = res->end = res->flags = 0;
  667. }
  668. }
  669. /*
  670. * Close it down - release our resources and go home..
  671. */
  672. static void yenta_close(struct pci_dev *dev)
  673. {
  674. struct yenta_socket *sock = pci_get_drvdata(dev);
  675. /* Remove the register attributes */
  676. device_remove_file(&dev->dev, &dev_attr_yenta_registers);
  677. /* we don't want a dying socket registered */
  678. pcmcia_unregister_socket(&sock->socket);
  679. /* Disable all events so we don't die in an IRQ storm */
  680. cb_writel(sock, CB_SOCKET_MASK, 0x0);
  681. exca_writeb(sock, I365_CSCINT, 0);
  682. if (sock->cb_irq)
  683. free_irq(sock->cb_irq, sock);
  684. else
  685. del_timer_sync(&sock->poll_timer);
  686. iounmap(sock->base);
  687. yenta_free_resources(sock);
  688. pci_release_regions(dev);
  689. pci_disable_device(dev);
  690. pci_set_drvdata(dev, NULL);
  691. kfree(sock);
  692. }
  693. static struct pccard_operations yenta_socket_operations = {
  694. .init = yenta_sock_init,
  695. .suspend = yenta_sock_suspend,
  696. .get_status = yenta_get_status,
  697. .set_socket = yenta_set_socket,
  698. .set_io_map = yenta_set_io_map,
  699. .set_mem_map = yenta_set_mem_map,
  700. };
  701. #ifdef CONFIG_YENTA_TI
  702. #include "ti113x.h"
  703. #endif
  704. #ifdef CONFIG_YENTA_RICOH
  705. #include "ricoh.h"
  706. #endif
  707. #ifdef CONFIG_YENTA_TOSHIBA
  708. #include "topic.h"
  709. #endif
  710. #ifdef CONFIG_YENTA_O2
  711. #include "o2micro.h"
  712. #endif
  713. enum {
  714. CARDBUS_TYPE_DEFAULT = -1,
  715. CARDBUS_TYPE_TI,
  716. CARDBUS_TYPE_TI113X,
  717. CARDBUS_TYPE_TI12XX,
  718. CARDBUS_TYPE_TI1250,
  719. CARDBUS_TYPE_RICOH,
  720. CARDBUS_TYPE_TOPIC95,
  721. CARDBUS_TYPE_TOPIC97,
  722. CARDBUS_TYPE_O2MICRO,
  723. CARDBUS_TYPE_ENE,
  724. };
  725. /*
  726. * Different cardbus controllers have slightly different
  727. * initialization sequences etc details. List them here..
  728. */
  729. static struct cardbus_type cardbus_type[] = {
  730. #ifdef CONFIG_YENTA_TI
  731. [CARDBUS_TYPE_TI] = {
  732. .override = ti_override,
  733. .save_state = ti_save_state,
  734. .restore_state = ti_restore_state,
  735. .sock_init = ti_init,
  736. },
  737. [CARDBUS_TYPE_TI113X] = {
  738. .override = ti113x_override,
  739. .save_state = ti_save_state,
  740. .restore_state = ti_restore_state,
  741. .sock_init = ti_init,
  742. },
  743. [CARDBUS_TYPE_TI12XX] = {
  744. .override = ti12xx_override,
  745. .save_state = ti_save_state,
  746. .restore_state = ti_restore_state,
  747. .sock_init = ti_init,
  748. },
  749. [CARDBUS_TYPE_TI1250] = {
  750. .override = ti1250_override,
  751. .save_state = ti_save_state,
  752. .restore_state = ti_restore_state,
  753. .sock_init = ti_init,
  754. },
  755. [CARDBUS_TYPE_ENE] = {
  756. .override = ene_override,
  757. .save_state = ti_save_state,
  758. .restore_state = ti_restore_state,
  759. .sock_init = ti_init,
  760. },
  761. #endif
  762. #ifdef CONFIG_YENTA_RICOH
  763. [CARDBUS_TYPE_RICOH] = {
  764. .override = ricoh_override,
  765. .save_state = ricoh_save_state,
  766. .restore_state = ricoh_restore_state,
  767. },
  768. #endif
  769. #ifdef CONFIG_YENTA_TOSHIBA
  770. [CARDBUS_TYPE_TOPIC95] = {
  771. .override = topic95_override,
  772. },
  773. [CARDBUS_TYPE_TOPIC97] = {
  774. .override = topic97_override,
  775. },
  776. #endif
  777. #ifdef CONFIG_YENTA_O2
  778. [CARDBUS_TYPE_O2MICRO] = {
  779. .override = o2micro_override,
  780. .restore_state = o2micro_restore_state,
  781. },
  782. #endif
  783. };
  784. static unsigned int yenta_probe_irq(struct yenta_socket *socket, u32 isa_irq_mask)
  785. {
  786. int i;
  787. unsigned long val;
  788. u32 mask;
  789. u8 reg;
  790. /*
  791. * Probe for usable interrupts using the force
  792. * register to generate bogus card status events.
  793. */
  794. cb_writel(socket, CB_SOCKET_EVENT, -1);
  795. cb_writel(socket, CB_SOCKET_MASK, CB_CSTSMASK);
  796. reg = exca_readb(socket, I365_CSCINT);
  797. exca_writeb(socket, I365_CSCINT, 0);
  798. val = probe_irq_on() & isa_irq_mask;
  799. for (i = 1; i < 16; i++) {
  800. if (!((val >> i) & 1))
  801. continue;
  802. exca_writeb(socket, I365_CSCINT, I365_CSC_STSCHG | (i << 4));
  803. cb_writel(socket, CB_SOCKET_FORCE, CB_FCARDSTS);
  804. udelay(100);
  805. cb_writel(socket, CB_SOCKET_EVENT, -1);
  806. }
  807. cb_writel(socket, CB_SOCKET_MASK, 0);
  808. exca_writeb(socket, I365_CSCINT, reg);
  809. mask = probe_irq_mask(val) & 0xffff;
  810. return mask;
  811. }
  812. /*
  813. * yenta PCI irq probing.
  814. * currently only used in the TI/EnE initialization code
  815. */
  816. #ifdef CONFIG_YENTA_TI
  817. /* interrupt handler, only used during probing */
  818. static irqreturn_t yenta_probe_handler(int irq, void *dev_id)
  819. {
  820. struct yenta_socket *socket = (struct yenta_socket *) dev_id;
  821. u8 csc;
  822. u32 cb_event;
  823. /* Clear interrupt status for the event */
  824. cb_event = cb_readl(socket, CB_SOCKET_EVENT);
  825. cb_writel(socket, CB_SOCKET_EVENT, -1);
  826. csc = exca_readb(socket, I365_CSC);
  827. if (cb_event || csc) {
  828. socket->probe_status = 1;
  829. return IRQ_HANDLED;
  830. }
  831. return IRQ_NONE;
  832. }
  833. /* probes the PCI interrupt, use only on override functions */
  834. static int yenta_probe_cb_irq(struct yenta_socket *socket)
  835. {
  836. u8 reg = 0;
  837. if (!socket->cb_irq)
  838. return -1;
  839. socket->probe_status = 0;
  840. if (request_irq(socket->cb_irq, yenta_probe_handler, IRQF_SHARED, "yenta", socket)) {
  841. dev_warn(&socket->dev->dev,
  842. "request_irq() in yenta_probe_cb_irq() failed!\n");
  843. return -1;
  844. }
  845. /* generate interrupt, wait */
  846. if (!socket->dev->irq)
  847. reg = exca_readb(socket, I365_CSCINT);
  848. exca_writeb(socket, I365_CSCINT, reg | I365_CSC_STSCHG);
  849. cb_writel(socket, CB_SOCKET_EVENT, -1);
  850. cb_writel(socket, CB_SOCKET_MASK, CB_CSTSMASK);
  851. cb_writel(socket, CB_SOCKET_FORCE, CB_FCARDSTS);
  852. msleep(100);
  853. /* disable interrupts */
  854. cb_writel(socket, CB_SOCKET_MASK, 0);
  855. exca_writeb(socket, I365_CSCINT, reg);
  856. cb_writel(socket, CB_SOCKET_EVENT, -1);
  857. exca_readb(socket, I365_CSC);
  858. free_irq(socket->cb_irq, socket);
  859. return (int) socket->probe_status;
  860. }
  861. #endif /* CONFIG_YENTA_TI */
  862. /*
  863. * Set static data that doesn't need re-initializing..
  864. */
  865. static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_irq_mask)
  866. {
  867. socket->socket.pci_irq = socket->cb_irq;
  868. if (isa_probe)
  869. socket->socket.irq_mask = yenta_probe_irq(socket, isa_irq_mask);
  870. else
  871. socket->socket.irq_mask = 0;
  872. dev_info(&socket->dev->dev, "ISA IRQ mask 0x%04x, PCI irq %d\n",
  873. socket->socket.irq_mask, socket->cb_irq);
  874. }
  875. /*
  876. * Initialize the standard cardbus registers
  877. */
  878. static void yenta_config_init(struct yenta_socket *socket)
  879. {
  880. u16 bridge;
  881. struct pci_dev *dev = socket->dev;
  882. struct pci_bus_region region;
  883. pcibios_resource_to_bus(socket->dev->bus, &region, &dev->resource[0]);
  884. config_writel(socket, CB_LEGACY_MODE_BASE, 0);
  885. config_writel(socket, PCI_BASE_ADDRESS_0, region.start);
  886. config_writew(socket, PCI_COMMAND,
  887. PCI_COMMAND_IO |
  888. PCI_COMMAND_MEMORY |
  889. PCI_COMMAND_MASTER |
  890. PCI_COMMAND_WAIT);
  891. /* MAGIC NUMBERS! Fixme */
  892. config_writeb(socket, PCI_CACHE_LINE_SIZE, L1_CACHE_BYTES / 4);
  893. config_writeb(socket, PCI_LATENCY_TIMER, 168);
  894. config_writel(socket, PCI_PRIMARY_BUS,
  895. (176 << 24) | /* sec. latency timer */
  896. ((unsigned int)dev->subordinate->busn_res.end << 16) | /* subordinate bus */
  897. ((unsigned int)dev->subordinate->busn_res.start << 8) | /* secondary bus */
  898. dev->subordinate->primary); /* primary bus */
  899. /*
  900. * Set up the bridging state:
  901. * - enable write posting.
  902. * - memory window 0 prefetchable, window 1 non-prefetchable
  903. * - PCI interrupts enabled if a PCI interrupt exists..
  904. */
  905. bridge = config_readw(socket, CB_BRIDGE_CONTROL);
  906. bridge &= ~(CB_BRIDGE_CRST | CB_BRIDGE_PREFETCH1 | CB_BRIDGE_ISAEN | CB_BRIDGE_VGAEN);
  907. bridge |= CB_BRIDGE_PREFETCH0 | CB_BRIDGE_POSTEN;
  908. config_writew(socket, CB_BRIDGE_CONTROL, bridge);
  909. }
  910. /**
  911. * yenta_fixup_parent_bridge - Fix subordinate bus# of the parent bridge
  912. * @cardbus_bridge: The PCI bus which the CardBus bridge bridges to
  913. *
  914. * Checks if devices on the bus which the CardBus bridge bridges to would be
  915. * invisible during PCI scans because of a misconfigured subordinate number
  916. * of the parent brige - some BIOSes seem to be too lazy to set it right.
  917. * Does the fixup carefully by checking how far it can go without conflicts.
  918. * See http://bugzilla.kernel.org/show_bug.cgi?id=2944 for more information.
  919. */
  920. static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
  921. {
  922. struct pci_bus *sibling;
  923. unsigned char upper_limit;
  924. /*
  925. * We only check and fix the parent bridge: All systems which need
  926. * this fixup that have been reviewed are laptops and the only bridge
  927. * which needed fixing was the parent bridge of the CardBus bridge:
  928. */
  929. struct pci_bus *bridge_to_fix = cardbus_bridge->parent;
  930. /* Check bus numbers are already set up correctly: */
  931. if (bridge_to_fix->busn_res.end >= cardbus_bridge->busn_res.end)
  932. return; /* The subordinate number is ok, nothing to do */
  933. if (!bridge_to_fix->parent)
  934. return; /* Root bridges are ok */
  935. /* stay within the limits of the bus range of the parent: */
  936. upper_limit = bridge_to_fix->parent->busn_res.end;
  937. /* check the bus ranges of all sibling bridges to prevent overlap */
  938. list_for_each_entry(sibling, &bridge_to_fix->parent->children,
  939. node) {
  940. /*
  941. * If the sibling has a higher secondary bus number
  942. * and it's secondary is equal or smaller than our
  943. * current upper limit, set the new upper limit to
  944. * the bus number below the sibling's range:
  945. */
  946. if (sibling->busn_res.start > bridge_to_fix->busn_res.end
  947. && sibling->busn_res.start <= upper_limit)
  948. upper_limit = sibling->busn_res.start - 1;
  949. }
  950. /* Show that the wanted subordinate number is not possible: */
  951. if (cardbus_bridge->busn_res.end > upper_limit)
  952. dev_warn(&cardbus_bridge->dev,
  953. "Upper limit for fixing this bridge's parent bridge: #%02x\n",
  954. upper_limit);
  955. /* If we have room to increase the bridge's subordinate number, */
  956. if (bridge_to_fix->busn_res.end < upper_limit) {
  957. /* use the highest number of the hidden bus, within limits */
  958. unsigned char subordinate_to_assign =
  959. min_t(int, cardbus_bridge->busn_res.end, upper_limit);
  960. dev_info(&bridge_to_fix->dev,
  961. "Raising subordinate bus# of parent bus (#%02x) from #%02x to #%02x\n",
  962. bridge_to_fix->number,
  963. (int)bridge_to_fix->busn_res.end,
  964. subordinate_to_assign);
  965. /* Save the new subordinate in the bus struct of the bridge */
  966. bridge_to_fix->busn_res.end = subordinate_to_assign;
  967. /* and update the PCI config space with the new subordinate */
  968. pci_write_config_byte(bridge_to_fix->self,
  969. PCI_SUBORDINATE_BUS, bridge_to_fix->busn_res.end);
  970. }
  971. }
  972. /*
  973. * Initialize a cardbus controller. Make sure we have a usable
  974. * interrupt, and that we can map the cardbus area. Fill in the
  975. * socket information structure..
  976. */
  977. static int yenta_probe(struct pci_dev *dev, const struct pci_device_id *id)
  978. {
  979. struct yenta_socket *socket;
  980. int ret;
  981. /*
  982. * If we failed to assign proper bus numbers for this cardbus
  983. * controller during PCI probe, its subordinate pci_bus is NULL.
  984. * Bail out if so.
  985. */
  986. if (!dev->subordinate) {
  987. dev_err(&dev->dev, "no bus associated! (try 'pci=assign-busses')\n");
  988. return -ENODEV;
  989. }
  990. socket = kzalloc(sizeof(struct yenta_socket), GFP_KERNEL);
  991. if (!socket)
  992. return -ENOMEM;
  993. /* prepare pcmcia_socket */
  994. socket->socket.ops = &yenta_socket_operations;
  995. socket->socket.resource_ops = &pccard_nonstatic_ops;
  996. socket->socket.dev.parent = &dev->dev;
  997. socket->socket.driver_data = socket;
  998. socket->socket.owner = THIS_MODULE;
  999. socket->socket.features = SS_CAP_PAGE_REGS | SS_CAP_PCCARD;
  1000. socket->socket.map_size = 0x1000;
  1001. socket->socket.cb_dev = dev;
  1002. /* prepare struct yenta_socket */
  1003. socket->dev = dev;
  1004. pci_set_drvdata(dev, socket);
  1005. /*
  1006. * Do some basic sanity checking..
  1007. */
  1008. if (pci_enable_device(dev)) {
  1009. ret = -EBUSY;
  1010. goto free;
  1011. }
  1012. ret = pci_request_regions(dev, "yenta_socket");
  1013. if (ret)
  1014. goto disable;
  1015. if (!pci_resource_start(dev, 0)) {
  1016. dev_err(&dev->dev, "No cardbus resource!\n");
  1017. ret = -ENODEV;
  1018. goto release;
  1019. }
  1020. /*
  1021. * Ok, start setup.. Map the cardbus registers,
  1022. * and request the IRQ.
  1023. */
  1024. socket->base = ioremap(pci_resource_start(dev, 0), 0x1000);
  1025. if (!socket->base) {
  1026. ret = -ENOMEM;
  1027. goto release;
  1028. }
  1029. /*
  1030. * report the subsystem vendor and device for help debugging
  1031. * the irq stuff...
  1032. */
  1033. dev_info(&dev->dev, "CardBus bridge found [%04x:%04x]\n",
  1034. dev->subsystem_vendor, dev->subsystem_device);
  1035. yenta_config_init(socket);
  1036. /* Disable all events */
  1037. cb_writel(socket, CB_SOCKET_MASK, 0x0);
  1038. /* Set up the bridge regions.. */
  1039. yenta_allocate_resources(socket);
  1040. socket->cb_irq = dev->irq;
  1041. /* Do we have special options for the device? */
  1042. if (id->driver_data != CARDBUS_TYPE_DEFAULT &&
  1043. id->driver_data < ARRAY_SIZE(cardbus_type)) {
  1044. socket->type = &cardbus_type[id->driver_data];
  1045. ret = socket->type->override(socket);
  1046. if (ret < 0)
  1047. goto unmap;
  1048. }
  1049. /* We must finish initialization here */
  1050. if (!socket->cb_irq || request_irq(socket->cb_irq, yenta_interrupt, IRQF_SHARED, "yenta", socket)) {
  1051. /* No IRQ or request_irq failed. Poll */
  1052. socket->cb_irq = 0; /* But zero is a valid IRQ number. */
  1053. setup_timer(&socket->poll_timer, yenta_interrupt_wrapper,
  1054. (unsigned long)socket);
  1055. mod_timer(&socket->poll_timer, jiffies + HZ);
  1056. dev_info(&dev->dev,
  1057. "no PCI IRQ, CardBus support disabled for this socket.\n");
  1058. dev_info(&dev->dev,
  1059. "check your BIOS CardBus, BIOS IRQ or ACPI settings.\n");
  1060. } else {
  1061. socket->socket.features |= SS_CAP_CARDBUS;
  1062. }
  1063. /* Figure out what the dang thing can do for the PCMCIA layer... */
  1064. yenta_interrogate(socket);
  1065. yenta_get_socket_capabilities(socket, isa_interrupts);
  1066. dev_info(&dev->dev, "Socket status: %08x\n",
  1067. cb_readl(socket, CB_SOCKET_STATE));
  1068. yenta_fixup_parent_bridge(dev->subordinate);
  1069. /* Register it with the pcmcia layer.. */
  1070. ret = pcmcia_register_socket(&socket->socket);
  1071. if (ret)
  1072. goto free_irq;
  1073. /* Add the yenta register attributes */
  1074. ret = device_create_file(&dev->dev, &dev_attr_yenta_registers);
  1075. if (ret)
  1076. goto unregister_socket;
  1077. return ret;
  1078. /* error path... */
  1079. unregister_socket:
  1080. pcmcia_unregister_socket(&socket->socket);
  1081. free_irq:
  1082. if (socket->cb_irq)
  1083. free_irq(socket->cb_irq, socket);
  1084. else
  1085. del_timer_sync(&socket->poll_timer);
  1086. unmap:
  1087. iounmap(socket->base);
  1088. yenta_free_resources(socket);
  1089. release:
  1090. pci_release_regions(dev);
  1091. disable:
  1092. pci_disable_device(dev);
  1093. free:
  1094. pci_set_drvdata(dev, NULL);
  1095. kfree(socket);
  1096. return ret;
  1097. }
  1098. #ifdef CONFIG_PM
  1099. static int yenta_dev_suspend_noirq(struct device *dev)
  1100. {
  1101. struct pci_dev *pdev = to_pci_dev(dev);
  1102. struct yenta_socket *socket = pci_get_drvdata(pdev);
  1103. if (!socket)
  1104. return 0;
  1105. if (socket->type && socket->type->save_state)
  1106. socket->type->save_state(socket);
  1107. pci_save_state(pdev);
  1108. pci_read_config_dword(pdev, 16*4, &socket->saved_state[0]);
  1109. pci_read_config_dword(pdev, 17*4, &socket->saved_state[1]);
  1110. pci_disable_device(pdev);
  1111. return 0;
  1112. }
  1113. static int yenta_dev_resume_noirq(struct device *dev)
  1114. {
  1115. struct pci_dev *pdev = to_pci_dev(dev);
  1116. struct yenta_socket *socket = pci_get_drvdata(pdev);
  1117. int ret;
  1118. if (!socket)
  1119. return 0;
  1120. pci_write_config_dword(pdev, 16*4, socket->saved_state[0]);
  1121. pci_write_config_dword(pdev, 17*4, socket->saved_state[1]);
  1122. ret = pci_enable_device(pdev);
  1123. if (ret)
  1124. return ret;
  1125. pci_set_master(pdev);
  1126. if (socket->type && socket->type->restore_state)
  1127. socket->type->restore_state(socket);
  1128. return 0;
  1129. }
  1130. static const struct dev_pm_ops yenta_pm_ops = {
  1131. .suspend_noirq = yenta_dev_suspend_noirq,
  1132. .resume_noirq = yenta_dev_resume_noirq,
  1133. .freeze_noirq = yenta_dev_suspend_noirq,
  1134. .thaw_noirq = yenta_dev_resume_noirq,
  1135. .poweroff_noirq = yenta_dev_suspend_noirq,
  1136. .restore_noirq = yenta_dev_resume_noirq,
  1137. };
  1138. #define YENTA_PM_OPS (&yenta_pm_ops)
  1139. #else
  1140. #define YENTA_PM_OPS NULL
  1141. #endif
  1142. #define CB_ID(vend, dev, type) \
  1143. { \
  1144. .vendor = vend, \
  1145. .device = dev, \
  1146. .subvendor = PCI_ANY_ID, \
  1147. .subdevice = PCI_ANY_ID, \
  1148. .class = PCI_CLASS_BRIDGE_CARDBUS << 8, \
  1149. .class_mask = ~0, \
  1150. .driver_data = CARDBUS_TYPE_##type, \
  1151. }
  1152. static const struct pci_device_id yenta_table[] = {
  1153. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1031, TI),
  1154. /*
  1155. * TBD: Check if these TI variants can use more
  1156. * advanced overrides instead. (I can't get the
  1157. * data sheets for these devices. --rmk)
  1158. */
  1159. #ifdef CONFIG_YENTA_TI
  1160. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1210, TI),
  1161. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1130, TI113X),
  1162. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1131, TI113X),
  1163. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1211, TI12XX),
  1164. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1220, TI12XX),
  1165. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1221, TI12XX),
  1166. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1225, TI12XX),
  1167. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1251A, TI12XX),
  1168. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1251B, TI12XX),
  1169. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1420, TI12XX),
  1170. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1450, TI12XX),
  1171. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1451A, TI12XX),
  1172. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1510, TI12XX),
  1173. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1520, TI12XX),
  1174. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1620, TI12XX),
  1175. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4410, TI12XX),
  1176. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4450, TI12XX),
  1177. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4451, TI12XX),
  1178. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4510, TI12XX),
  1179. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_4520, TI12XX),
  1180. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1250, TI1250),
  1181. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1410, TI1250),
  1182. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX21_XX11, TI12XX),
  1183. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X515, TI12XX),
  1184. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XX12, TI12XX),
  1185. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X420, TI12XX),
  1186. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_X620, TI12XX),
  1187. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7410, TI12XX),
  1188. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7510, TI12XX),
  1189. CB_ID(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_7610, TI12XX),
  1190. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_710, ENE),
  1191. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_712, ENE),
  1192. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_720, ENE),
  1193. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_722, ENE),
  1194. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1211, ENE),
  1195. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1225, ENE),
  1196. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1410, ENE),
  1197. CB_ID(PCI_VENDOR_ID_ENE, PCI_DEVICE_ID_ENE_1420, ENE),
  1198. #endif /* CONFIG_YENTA_TI */
  1199. #ifdef CONFIG_YENTA_RICOH
  1200. CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C465, RICOH),
  1201. CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C466, RICOH),
  1202. CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C475, RICOH),
  1203. CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, RICOH),
  1204. CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C478, RICOH),
  1205. #endif
  1206. #ifdef CONFIG_YENTA_TOSHIBA
  1207. CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC95, TOPIC95),
  1208. CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC97, TOPIC97),
  1209. CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC100, TOPIC97),
  1210. #endif
  1211. #ifdef CONFIG_YENTA_O2
  1212. CB_ID(PCI_VENDOR_ID_O2, PCI_ANY_ID, O2MICRO),
  1213. #endif
  1214. /* match any cardbus bridge */
  1215. CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
  1216. { /* all zeroes */ }
  1217. };
  1218. MODULE_DEVICE_TABLE(pci, yenta_table);
  1219. static struct pci_driver yenta_cardbus_driver = {
  1220. .name = "yenta_cardbus",
  1221. .id_table = yenta_table,
  1222. .probe = yenta_probe,
  1223. .remove = yenta_close,
  1224. .driver.pm = YENTA_PM_OPS,
  1225. };
  1226. module_pci_driver(yenta_cardbus_driver);
  1227. MODULE_LICENSE("GPL");