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