locomo.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /*
  2. * linux/arch/arm/common/locomo.c
  3. *
  4. * Sharp LoCoMo support
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This file contains all generic LoCoMo support.
  11. *
  12. * All initialization functions provided here are intended to be called
  13. * from machine specific code with proper arguments when required.
  14. *
  15. * Based on sa1111.c
  16. */
  17. #include <linux/config.h>
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/delay.h>
  22. #include <linux/errno.h>
  23. #include <linux/ioport.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include <linux/spinlock.h>
  27. #include <asm/hardware.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/mach/irq.h>
  31. #include <asm/hardware/locomo.h>
  32. /* M62332 output channel selection */
  33. #define M62332_EVR_CH 1 /* M62332 volume channel number */
  34. /* 0 : CH.1 , 1 : CH. 2 */
  35. /* DAC send data */
  36. #define M62332_SLAVE_ADDR 0x4e /* Slave address */
  37. #define M62332_W_BIT 0x00 /* W bit (0 only) */
  38. #define M62332_SUB_ADDR 0x00 /* Sub address */
  39. #define M62332_A_BIT 0x00 /* A bit (0 only) */
  40. /* DAC setup and hold times (expressed in us) */
  41. #define DAC_BUS_FREE_TIME 5 /* 4.7 us */
  42. #define DAC_START_SETUP_TIME 5 /* 4.7 us */
  43. #define DAC_STOP_SETUP_TIME 4 /* 4.0 us */
  44. #define DAC_START_HOLD_TIME 5 /* 4.7 us */
  45. #define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */
  46. #define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */
  47. #define DAC_DATA_SETUP_TIME 1 /* 250 ns */
  48. #define DAC_DATA_HOLD_TIME 1 /* 300 ns */
  49. #define DAC_LOW_SETUP_TIME 1 /* 300 ns */
  50. #define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */
  51. /* the following is the overall data for the locomo chip */
  52. struct locomo {
  53. struct device *dev;
  54. unsigned long phys;
  55. unsigned int irq;
  56. spinlock_t lock;
  57. void *base;
  58. };
  59. struct locomo_dev_info {
  60. unsigned long offset;
  61. unsigned long length;
  62. unsigned int devid;
  63. unsigned int irq[1];
  64. const char * name;
  65. };
  66. /* All the locomo devices. If offset is non-zero, the mapbase for the
  67. * locomo_dev will be set to the chip base plus offset. If offset is
  68. * zero, then the mapbase for the locomo_dev will be set to zero. An
  69. * offset of zero means the device only uses GPIOs or other helper
  70. * functions inside this file */
  71. static struct locomo_dev_info locomo_devices[] = {
  72. {
  73. .devid = LOCOMO_DEVID_KEYBOARD,
  74. .irq = {
  75. IRQ_LOCOMO_KEY,
  76. },
  77. .name = "locomo-keyboard",
  78. .offset = LOCOMO_KEYBOARD,
  79. .length = 16,
  80. },
  81. {
  82. .devid = LOCOMO_DEVID_FRONTLIGHT,
  83. .irq = {},
  84. .name = "locomo-frontlight",
  85. .offset = LOCOMO_FRONTLIGHT,
  86. .length = 8,
  87. },
  88. {
  89. .devid = LOCOMO_DEVID_BACKLIGHT,
  90. .irq = {},
  91. .name = "locomo-backlight",
  92. .offset = LOCOMO_BACKLIGHT,
  93. .length = 8,
  94. },
  95. {
  96. .devid = LOCOMO_DEVID_AUDIO,
  97. .irq = {},
  98. .name = "locomo-audio",
  99. .offset = LOCOMO_AUDIO,
  100. .length = 4,
  101. },
  102. {
  103. .devid = LOCOMO_DEVID_LED,
  104. .irq = {},
  105. .name = "locomo-led",
  106. .offset = LOCOMO_LED,
  107. .length = 8,
  108. },
  109. {
  110. .devid = LOCOMO_DEVID_UART,
  111. .irq = {},
  112. .name = "locomo-uart",
  113. .offset = 0,
  114. .length = 0,
  115. },
  116. };
  117. /** LoCoMo interrupt handling stuff.
  118. * NOTE: LoCoMo has a 1 to many mapping on all of its IRQs.
  119. * that is, there is only one real hardware interrupt
  120. * we determine which interrupt it is by reading some IO memory.
  121. * We have two levels of expansion, first in the handler for the
  122. * hardware interrupt we generate an interrupt
  123. * IRQ_LOCOMO_*_BASE and those handlers generate more interrupts
  124. *
  125. * hardware irq reads LOCOMO_ICR & 0x0f00
  126. * IRQ_LOCOMO_KEY_BASE
  127. * IRQ_LOCOMO_GPIO_BASE
  128. * IRQ_LOCOMO_LT_BASE
  129. * IRQ_LOCOMO_SPI_BASE
  130. * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
  131. * IRQ_LOCOMO_KEY
  132. * IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff
  133. * IRQ_LOCOMO_GPIO[0-15]
  134. * IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001
  135. * IRQ_LOCOMO_LT
  136. * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
  137. * IRQ_LOCOMO_SPI_RFR
  138. * IRQ_LOCOMO_SPI_RFW
  139. * IRQ_LOCOMO_SPI_OVRN
  140. * IRQ_LOCOMO_SPI_TEND
  141. */
  142. #define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE)
  143. #define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY)
  144. #define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0)
  145. #define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT)
  146. #define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR)
  147. static void locomo_handler(unsigned int irq, struct irqdesc *desc,
  148. struct pt_regs *regs)
  149. {
  150. int req, i;
  151. struct irqdesc *d;
  152. void *mapbase = get_irq_chipdata(irq);
  153. /* Acknowledge the parent IRQ */
  154. desc->chip->ack(irq);
  155. /* check why this interrupt was generated */
  156. req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00;
  157. if (req) {
  158. /* generate the next interrupt(s) */
  159. irq = LOCOMO_IRQ_START;
  160. d = irq_desc + irq;
  161. for (i = 0; i <= 3; i++, d++, irq++) {
  162. if (req & (0x0100 << i)) {
  163. desc_handle_irq(irq, d, regs);
  164. }
  165. }
  166. }
  167. }
  168. static void locomo_ack_irq(unsigned int irq)
  169. {
  170. }
  171. static void locomo_mask_irq(unsigned int irq)
  172. {
  173. void *mapbase = get_irq_chipdata(irq);
  174. unsigned int r;
  175. r = locomo_readl(mapbase + LOCOMO_ICR);
  176. r &= ~(0x0010 << (irq - LOCOMO_IRQ_START));
  177. locomo_writel(r, mapbase + LOCOMO_ICR);
  178. }
  179. static void locomo_unmask_irq(unsigned int irq)
  180. {
  181. void *mapbase = get_irq_chipdata(irq);
  182. unsigned int r;
  183. r = locomo_readl(mapbase + LOCOMO_ICR);
  184. r |= (0x0010 << (irq - LOCOMO_IRQ_START));
  185. locomo_writel(r, mapbase + LOCOMO_ICR);
  186. }
  187. static struct irqchip locomo_chip = {
  188. .ack = locomo_ack_irq,
  189. .mask = locomo_mask_irq,
  190. .unmask = locomo_unmask_irq,
  191. };
  192. static void locomo_key_handler(unsigned int irq, struct irqdesc *desc,
  193. struct pt_regs *regs)
  194. {
  195. struct irqdesc *d;
  196. void *mapbase = get_irq_chipdata(irq);
  197. if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) {
  198. d = irq_desc + LOCOMO_IRQ_KEY_START;
  199. desc_handle_irq(LOCOMO_IRQ_KEY_START, d, regs);
  200. }
  201. }
  202. static void locomo_key_ack_irq(unsigned int irq)
  203. {
  204. void *mapbase = get_irq_chipdata(irq);
  205. unsigned int r;
  206. r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
  207. r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START));
  208. locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
  209. }
  210. static void locomo_key_mask_irq(unsigned int irq)
  211. {
  212. void *mapbase = get_irq_chipdata(irq);
  213. unsigned int r;
  214. r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
  215. r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START));
  216. locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
  217. }
  218. static void locomo_key_unmask_irq(unsigned int irq)
  219. {
  220. void *mapbase = get_irq_chipdata(irq);
  221. unsigned int r;
  222. r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
  223. r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START));
  224. locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
  225. }
  226. static struct irqchip locomo_key_chip = {
  227. .ack = locomo_key_ack_irq,
  228. .mask = locomo_key_mask_irq,
  229. .unmask = locomo_key_unmask_irq,
  230. };
  231. static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc,
  232. struct pt_regs *regs)
  233. {
  234. int req, i;
  235. struct irqdesc *d;
  236. void *mapbase = get_irq_chipdata(irq);
  237. req = locomo_readl(mapbase + LOCOMO_GIR) &
  238. locomo_readl(mapbase + LOCOMO_GPD) &
  239. 0xffff;
  240. if (req) {
  241. irq = LOCOMO_IRQ_GPIO_START;
  242. d = irq_desc + LOCOMO_IRQ_GPIO_START;
  243. for (i = 0; i <= 15; i++, irq++, d++) {
  244. if (req & (0x0001 << i)) {
  245. desc_handle_irq(irq, d, regs);
  246. }
  247. }
  248. }
  249. }
  250. static void locomo_gpio_ack_irq(unsigned int irq)
  251. {
  252. void *mapbase = get_irq_chipdata(irq);
  253. unsigned int r;
  254. r = locomo_readl(mapbase + LOCOMO_GWE);
  255. r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
  256. locomo_writel(r, mapbase + LOCOMO_GWE);
  257. r = locomo_readl(mapbase + LOCOMO_GIS);
  258. r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
  259. locomo_writel(r, mapbase + LOCOMO_GIS);
  260. r = locomo_readl(mapbase + LOCOMO_GWE);
  261. r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
  262. locomo_writel(r, mapbase + LOCOMO_GWE);
  263. }
  264. static void locomo_gpio_mask_irq(unsigned int irq)
  265. {
  266. void *mapbase = get_irq_chipdata(irq);
  267. unsigned int r;
  268. r = locomo_readl(mapbase + LOCOMO_GIE);
  269. r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
  270. locomo_writel(r, mapbase + LOCOMO_GIE);
  271. }
  272. static void locomo_gpio_unmask_irq(unsigned int irq)
  273. {
  274. void *mapbase = get_irq_chipdata(irq);
  275. unsigned int r;
  276. r = locomo_readl(mapbase + LOCOMO_GIE);
  277. r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
  278. locomo_writel(r, mapbase + LOCOMO_GIE);
  279. }
  280. static struct irqchip locomo_gpio_chip = {
  281. .ack = locomo_gpio_ack_irq,
  282. .mask = locomo_gpio_mask_irq,
  283. .unmask = locomo_gpio_unmask_irq,
  284. };
  285. static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc,
  286. struct pt_regs *regs)
  287. {
  288. struct irqdesc *d;
  289. void *mapbase = get_irq_chipdata(irq);
  290. if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) {
  291. d = irq_desc + LOCOMO_IRQ_LT_START;
  292. desc_handle_irq(LOCOMO_IRQ_LT_START, d, regs);
  293. }
  294. }
  295. static void locomo_lt_ack_irq(unsigned int irq)
  296. {
  297. void *mapbase = get_irq_chipdata(irq);
  298. unsigned int r;
  299. r = locomo_readl(mapbase + LOCOMO_LTINT);
  300. r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START));
  301. locomo_writel(r, mapbase + LOCOMO_LTINT);
  302. }
  303. static void locomo_lt_mask_irq(unsigned int irq)
  304. {
  305. void *mapbase = get_irq_chipdata(irq);
  306. unsigned int r;
  307. r = locomo_readl(mapbase + LOCOMO_LTINT);
  308. r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START));
  309. locomo_writel(r, mapbase + LOCOMO_LTINT);
  310. }
  311. static void locomo_lt_unmask_irq(unsigned int irq)
  312. {
  313. void *mapbase = get_irq_chipdata(irq);
  314. unsigned int r;
  315. r = locomo_readl(mapbase + LOCOMO_LTINT);
  316. r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START));
  317. locomo_writel(r, mapbase + LOCOMO_LTINT);
  318. }
  319. static struct irqchip locomo_lt_chip = {
  320. .ack = locomo_lt_ack_irq,
  321. .mask = locomo_lt_mask_irq,
  322. .unmask = locomo_lt_unmask_irq,
  323. };
  324. static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc,
  325. struct pt_regs *regs)
  326. {
  327. int req, i;
  328. struct irqdesc *d;
  329. void *mapbase = get_irq_chipdata(irq);
  330. req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F;
  331. if (req) {
  332. irq = LOCOMO_IRQ_SPI_START;
  333. d = irq_desc + irq;
  334. for (i = 0; i <= 3; i++, irq++, d++) {
  335. if (req & (0x0001 << i)) {
  336. desc_handle_irq(irq, d, regs);
  337. }
  338. }
  339. }
  340. }
  341. static void locomo_spi_ack_irq(unsigned int irq)
  342. {
  343. void *mapbase = get_irq_chipdata(irq);
  344. unsigned int r;
  345. r = locomo_readl(mapbase + LOCOMO_SPIWE);
  346. r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
  347. locomo_writel(r, mapbase + LOCOMO_SPIWE);
  348. r = locomo_readl(mapbase + LOCOMO_SPIIS);
  349. r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
  350. locomo_writel(r, mapbase + LOCOMO_SPIIS);
  351. r = locomo_readl(mapbase + LOCOMO_SPIWE);
  352. r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
  353. locomo_writel(r, mapbase + LOCOMO_SPIWE);
  354. }
  355. static void locomo_spi_mask_irq(unsigned int irq)
  356. {
  357. void *mapbase = get_irq_chipdata(irq);
  358. unsigned int r;
  359. r = locomo_readl(mapbase + LOCOMO_SPIIE);
  360. r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
  361. locomo_writel(r, mapbase + LOCOMO_SPIIE);
  362. }
  363. static void locomo_spi_unmask_irq(unsigned int irq)
  364. {
  365. void *mapbase = get_irq_chipdata(irq);
  366. unsigned int r;
  367. r = locomo_readl(mapbase + LOCOMO_SPIIE);
  368. r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
  369. locomo_writel(r, mapbase + LOCOMO_SPIIE);
  370. }
  371. static struct irqchip locomo_spi_chip = {
  372. .ack = locomo_spi_ack_irq,
  373. .mask = locomo_spi_mask_irq,
  374. .unmask = locomo_spi_unmask_irq,
  375. };
  376. static void locomo_setup_irq(struct locomo *lchip)
  377. {
  378. int irq;
  379. void *irqbase = lchip->base;
  380. /*
  381. * Install handler for IRQ_LOCOMO_HW.
  382. */
  383. set_irq_type(lchip->irq, IRQT_FALLING);
  384. set_irq_chipdata(lchip->irq, irqbase);
  385. set_irq_chained_handler(lchip->irq, locomo_handler);
  386. /* Install handlers for IRQ_LOCOMO_*_BASE */
  387. set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip);
  388. set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase);
  389. set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler);
  390. set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE);
  391. set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip);
  392. set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase);
  393. set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler);
  394. set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE);
  395. set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip);
  396. set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase);
  397. set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler);
  398. set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE);
  399. set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip);
  400. set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase);
  401. set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler);
  402. set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE);
  403. /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
  404. set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip);
  405. set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase);
  406. set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ);
  407. set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE);
  408. /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
  409. for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) {
  410. set_irq_chip(irq, &locomo_gpio_chip);
  411. set_irq_chipdata(irq, irqbase);
  412. set_irq_handler(irq, do_edge_IRQ);
  413. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  414. }
  415. /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
  416. set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip);
  417. set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase);
  418. set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ);
  419. set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE);
  420. /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
  421. for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) {
  422. set_irq_chip(irq, &locomo_spi_chip);
  423. set_irq_chipdata(irq, irqbase);
  424. set_irq_handler(irq, do_edge_IRQ);
  425. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  426. }
  427. }
  428. static void locomo_dev_release(struct device *_dev)
  429. {
  430. struct locomo_dev *dev = LOCOMO_DEV(_dev);
  431. kfree(dev);
  432. }
  433. static int
  434. locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
  435. {
  436. struct locomo_dev *dev;
  437. int ret;
  438. dev = kmalloc(sizeof(struct locomo_dev), GFP_KERNEL);
  439. if (!dev) {
  440. ret = -ENOMEM;
  441. goto out;
  442. }
  443. memset(dev, 0, sizeof(struct locomo_dev));
  444. strncpy(dev->dev.bus_id,info->name,sizeof(dev->dev.bus_id));
  445. /*
  446. * If the parent device has a DMA mask associated with it,
  447. * propagate it down to the children.
  448. */
  449. if (lchip->dev->dma_mask) {
  450. dev->dma_mask = *lchip->dev->dma_mask;
  451. dev->dev.dma_mask = &dev->dma_mask;
  452. }
  453. dev->devid = info->devid;
  454. dev->dev.parent = lchip->dev;
  455. dev->dev.bus = &locomo_bus_type;
  456. dev->dev.release = locomo_dev_release;
  457. dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
  458. if (info->offset)
  459. dev->mapbase = lchip->base + info->offset;
  460. else
  461. dev->mapbase = 0;
  462. dev->length = info->length;
  463. memmove(dev->irq, info->irq, sizeof(dev->irq));
  464. ret = device_register(&dev->dev);
  465. if (ret) {
  466. out:
  467. kfree(dev);
  468. }
  469. return ret;
  470. }
  471. #ifdef CONFIG_PM
  472. struct locomo_save_data {
  473. u16 LCM_GPO;
  474. u16 LCM_SPICT;
  475. u16 LCM_GPE;
  476. u16 LCM_ASD;
  477. u16 LCM_SPIMD;
  478. };
  479. static int locomo_suspend(struct platform_device *dev, pm_message_t state)
  480. {
  481. struct locomo *lchip = platform_get_drvdata(dev);
  482. struct locomo_save_data *save;
  483. unsigned long flags;
  484. save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
  485. if (!save)
  486. return -ENOMEM;
  487. dev->dev.power.saved_state = (void *) save;
  488. spin_lock_irqsave(&lchip->lock, flags);
  489. save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */
  490. locomo_writel(0x00, lchip->base + LOCOMO_GPO);
  491. save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPICT); /* SPI */
  492. locomo_writel(0x40, lchip->base + LOCOMO_SPICT);
  493. save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */
  494. locomo_writel(0x00, lchip->base + LOCOMO_GPE);
  495. save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */
  496. locomo_writel(0x00, lchip->base + LOCOMO_ASD);
  497. save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPIMD); /* SPI */
  498. locomo_writel(0x3C14, lchip->base + LOCOMO_SPIMD);
  499. locomo_writel(0x00, lchip->base + LOCOMO_PAIF);
  500. locomo_writel(0x00, lchip->base + LOCOMO_DAC);
  501. locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC);
  502. if ( (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88) )
  503. locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */
  504. else
  505. /* 18MHz already enabled, so no wait */
  506. locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */
  507. locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/
  508. locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */
  509. locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */
  510. spin_unlock_irqrestore(&lchip->lock, flags);
  511. return 0;
  512. }
  513. static int locomo_resume(struct platform_device *dev)
  514. {
  515. struct locomo *lchip = platform_get_drvdata(dev);
  516. struct locomo_save_data *save;
  517. unsigned long r;
  518. unsigned long flags;
  519. save = (struct locomo_save_data *) dev->dev.power.saved_state;
  520. if (!save)
  521. return 0;
  522. spin_lock_irqsave(&lchip->lock, flags);
  523. locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
  524. locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPICT);
  525. locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
  526. locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
  527. locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPIMD);
  528. locomo_writel(0x00, lchip->base + LOCOMO_C32K);
  529. locomo_writel(0x90, lchip->base + LOCOMO_TADC);
  530. locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
  531. r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
  532. r &= 0xFEFF;
  533. locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
  534. locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
  535. spin_unlock_irqrestore(&lchip->lock, flags);
  536. kfree(save);
  537. return 0;
  538. }
  539. #endif
  540. #define LCM_ALC_EN 0x8000
  541. void frontlight_set(struct locomo *lchip, int duty, int vr, int bpwf)
  542. {
  543. unsigned long flags;
  544. spin_lock_irqsave(&lchip->lock, flags);
  545. locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
  546. udelay(100);
  547. locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
  548. locomo_writel(bpwf | LCM_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
  549. spin_unlock_irqrestore(&lchip->lock, flags);
  550. }
  551. /**
  552. * locomo_probe - probe for a single LoCoMo chip.
  553. * @phys_addr: physical address of device.
  554. *
  555. * Probe for a LoCoMo chip. This must be called
  556. * before any other locomo-specific code.
  557. *
  558. * Returns:
  559. * %-ENODEV device not found.
  560. * %-EBUSY physical address already marked in-use.
  561. * %0 successful.
  562. */
  563. static int
  564. __locomo_probe(struct device *me, struct resource *mem, int irq)
  565. {
  566. struct locomo *lchip;
  567. unsigned long r;
  568. int i, ret = -ENODEV;
  569. lchip = kmalloc(sizeof(struct locomo), GFP_KERNEL);
  570. if (!lchip)
  571. return -ENOMEM;
  572. memset(lchip, 0, sizeof(struct locomo));
  573. spin_lock_init(&lchip->lock);
  574. lchip->dev = me;
  575. dev_set_drvdata(lchip->dev, lchip);
  576. lchip->phys = mem->start;
  577. lchip->irq = irq;
  578. /*
  579. * Map the whole region. This also maps the
  580. * registers for our children.
  581. */
  582. lchip->base = ioremap(mem->start, PAGE_SIZE);
  583. if (!lchip->base) {
  584. ret = -ENOMEM;
  585. goto out;
  586. }
  587. /* locomo initialize */
  588. locomo_writel(0, lchip->base + LOCOMO_ICR);
  589. /* KEYBOARD */
  590. locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
  591. /* GPIO */
  592. locomo_writel(0, lchip->base + LOCOMO_GPO);
  593. locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
  594. , lchip->base + LOCOMO_GPE);
  595. locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
  596. , lchip->base + LOCOMO_GPD);
  597. locomo_writel(0, lchip->base + LOCOMO_GIE);
  598. /* FrontLight */
  599. locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
  600. locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
  601. /* Same constants can be used for collie and poodle
  602. (depending on CONFIG options in original sharp code)? */
  603. frontlight_set(lchip, 163, 0, 148);
  604. /* Longtime timer */
  605. locomo_writel(0, lchip->base + LOCOMO_LTINT);
  606. /* SPI */
  607. locomo_writel(0, lchip->base + LOCOMO_SPIIE);
  608. locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
  609. r = locomo_readl(lchip->base + LOCOMO_ASD);
  610. r |= 0x8000;
  611. locomo_writel(r, lchip->base + LOCOMO_ASD);
  612. locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
  613. r = locomo_readl(lchip->base + LOCOMO_HSD);
  614. r |= 0x8000;
  615. locomo_writel(r, lchip->base + LOCOMO_HSD);
  616. locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
  617. /* XON */
  618. locomo_writel(0x80, lchip->base + LOCOMO_TADC);
  619. udelay(1000);
  620. /* CLK9MEN */
  621. r = locomo_readl(lchip->base + LOCOMO_TADC);
  622. r |= 0x10;
  623. locomo_writel(r, lchip->base + LOCOMO_TADC);
  624. udelay(100);
  625. /* init DAC */
  626. r = locomo_readl(lchip->base + LOCOMO_DAC);
  627. r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
  628. locomo_writel(r, lchip->base + LOCOMO_DAC);
  629. r = locomo_readl(lchip->base + LOCOMO_VER);
  630. printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
  631. /*
  632. * The interrupt controller must be initialised before any
  633. * other device to ensure that the interrupts are available.
  634. */
  635. if (lchip->irq != NO_IRQ)
  636. locomo_setup_irq(lchip);
  637. for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
  638. locomo_init_one_child(lchip, &locomo_devices[i]);
  639. return 0;
  640. out:
  641. kfree(lchip);
  642. return ret;
  643. }
  644. static int locomo_remove_child(struct device *dev, void *data)
  645. {
  646. device_unregister(dev);
  647. return 0;
  648. }
  649. static void __locomo_remove(struct locomo *lchip)
  650. {
  651. device_for_each_child(lchip->dev, NULL, locomo_remove_child);
  652. if (lchip->irq != NO_IRQ) {
  653. set_irq_chained_handler(lchip->irq, NULL);
  654. set_irq_data(lchip->irq, NULL);
  655. }
  656. iounmap(lchip->base);
  657. kfree(lchip);
  658. }
  659. static int locomo_probe(struct platform_device *dev)
  660. {
  661. struct resource *mem;
  662. int irq;
  663. mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  664. if (!mem)
  665. return -EINVAL;
  666. irq = platform_get_irq(dev, 0);
  667. return __locomo_probe(&dev->dev, mem, irq);
  668. }
  669. static int locomo_remove(struct platform_device *dev)
  670. {
  671. struct locomo *lchip = platform_get_drvdata(dev);
  672. if (lchip) {
  673. __locomo_remove(lchip);
  674. platform_set_drvdata(dev, NULL);
  675. }
  676. return 0;
  677. }
  678. /*
  679. * Not sure if this should be on the system bus or not yet.
  680. * We really want some way to register a system device at
  681. * the per-machine level, and then have this driver pick
  682. * up the registered devices.
  683. */
  684. static struct platform_driver locomo_device_driver = {
  685. .probe = locomo_probe,
  686. .remove = locomo_remove,
  687. #ifdef CONFIG_PM
  688. .suspend = locomo_suspend,
  689. .resume = locomo_resume,
  690. #endif
  691. .driver = {
  692. .name = "locomo",
  693. },
  694. };
  695. /*
  696. * Get the parent device driver (us) structure
  697. * from a child function device
  698. */
  699. static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
  700. {
  701. return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
  702. }
  703. void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir)
  704. {
  705. struct locomo *lchip = locomo_chip_driver(ldev);
  706. unsigned long flags;
  707. unsigned int r;
  708. spin_lock_irqsave(&lchip->lock, flags);
  709. r = locomo_readl(lchip->base + LOCOMO_GPD);
  710. r &= ~bits;
  711. locomo_writel(r, lchip->base + LOCOMO_GPD);
  712. r = locomo_readl(lchip->base + LOCOMO_GPE);
  713. if (dir)
  714. r |= bits;
  715. else
  716. r &= ~bits;
  717. locomo_writel(r, lchip->base + LOCOMO_GPE);
  718. spin_unlock_irqrestore(&lchip->lock, flags);
  719. }
  720. unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits)
  721. {
  722. struct locomo *lchip = locomo_chip_driver(ldev);
  723. unsigned long flags;
  724. unsigned int ret;
  725. spin_lock_irqsave(&lchip->lock, flags);
  726. ret = locomo_readl(lchip->base + LOCOMO_GPL);
  727. spin_unlock_irqrestore(&lchip->lock, flags);
  728. ret &= bits;
  729. return ret;
  730. }
  731. unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits)
  732. {
  733. struct locomo *lchip = locomo_chip_driver(ldev);
  734. unsigned long flags;
  735. unsigned int ret;
  736. spin_lock_irqsave(&lchip->lock, flags);
  737. ret = locomo_readl(lchip->base + LOCOMO_GPO);
  738. spin_unlock_irqrestore(&lchip->lock, flags);
  739. ret &= bits;
  740. return ret;
  741. }
  742. void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set)
  743. {
  744. struct locomo *lchip = locomo_chip_driver(ldev);
  745. unsigned long flags;
  746. unsigned int r;
  747. spin_lock_irqsave(&lchip->lock, flags);
  748. r = locomo_readl(lchip->base + LOCOMO_GPO);
  749. if (set)
  750. r |= bits;
  751. else
  752. r &= ~bits;
  753. locomo_writel(r, lchip->base + LOCOMO_GPO);
  754. spin_unlock_irqrestore(&lchip->lock, flags);
  755. }
  756. static void locomo_m62332_sendbit(void *mapbase, int bit)
  757. {
  758. unsigned int r;
  759. r = locomo_readl(mapbase + LOCOMO_DAC);
  760. r &= ~(LOCOMO_DAC_SCLOEB);
  761. locomo_writel(r, mapbase + LOCOMO_DAC);
  762. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  763. udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
  764. r = locomo_readl(mapbase + LOCOMO_DAC);
  765. r &= ~(LOCOMO_DAC_SCLOEB);
  766. locomo_writel(r, mapbase + LOCOMO_DAC);
  767. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  768. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  769. if (bit & 1) {
  770. r = locomo_readl(mapbase + LOCOMO_DAC);
  771. r |= LOCOMO_DAC_SDAOEB;
  772. locomo_writel(r, mapbase + LOCOMO_DAC);
  773. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  774. } else {
  775. r = locomo_readl(mapbase + LOCOMO_DAC);
  776. r &= ~(LOCOMO_DAC_SDAOEB);
  777. locomo_writel(r, mapbase + LOCOMO_DAC);
  778. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  779. }
  780. udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */
  781. r = locomo_readl(mapbase + LOCOMO_DAC);
  782. r |= LOCOMO_DAC_SCLOEB;
  783. locomo_writel(r, mapbase + LOCOMO_DAC);
  784. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  785. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
  786. }
  787. void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
  788. {
  789. struct locomo *lchip = locomo_chip_driver(ldev);
  790. int i;
  791. unsigned char data;
  792. unsigned int r;
  793. void *mapbase = lchip->base;
  794. unsigned long flags;
  795. spin_lock_irqsave(&lchip->lock, flags);
  796. /* Start */
  797. udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */
  798. r = locomo_readl(mapbase + LOCOMO_DAC);
  799. r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
  800. locomo_writel(r, mapbase + LOCOMO_DAC);
  801. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  802. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
  803. r = locomo_readl(mapbase + LOCOMO_DAC);
  804. r &= ~(LOCOMO_DAC_SDAOEB);
  805. locomo_writel(r, mapbase + LOCOMO_DAC);
  806. udelay(DAC_START_HOLD_TIME); /* 5.0 usec */
  807. udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
  808. /* Send slave address and W bit (LSB is W bit) */
  809. data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
  810. for (i = 1; i <= 8; i++) {
  811. locomo_m62332_sendbit(mapbase, data >> (8 - i));
  812. }
  813. /* Check A bit */
  814. r = locomo_readl(mapbase + LOCOMO_DAC);
  815. r &= ~(LOCOMO_DAC_SCLOEB);
  816. locomo_writel(r, mapbase + LOCOMO_DAC);
  817. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  818. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  819. r = locomo_readl(mapbase + LOCOMO_DAC);
  820. r &= ~(LOCOMO_DAC_SDAOEB);
  821. locomo_writel(r, mapbase + LOCOMO_DAC);
  822. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  823. r = locomo_readl(mapbase + LOCOMO_DAC);
  824. r |= LOCOMO_DAC_SCLOEB;
  825. locomo_writel(r, mapbase + LOCOMO_DAC);
  826. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  827. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
  828. if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
  829. printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
  830. return;
  831. }
  832. /* Send Sub address (LSB is channel select) */
  833. /* channel = 0 : ch1 select */
  834. /* = 1 : ch2 select */
  835. data = M62332_SUB_ADDR + channel;
  836. for (i = 1; i <= 8; i++) {
  837. locomo_m62332_sendbit(mapbase, data >> (8 - i));
  838. }
  839. /* Check A bit */
  840. r = locomo_readl(mapbase + LOCOMO_DAC);
  841. r &= ~(LOCOMO_DAC_SCLOEB);
  842. locomo_writel(r, mapbase + LOCOMO_DAC);
  843. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  844. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  845. r = locomo_readl(mapbase + LOCOMO_DAC);
  846. r &= ~(LOCOMO_DAC_SDAOEB);
  847. locomo_writel(r, mapbase + LOCOMO_DAC);
  848. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  849. r = locomo_readl(mapbase + LOCOMO_DAC);
  850. r |= LOCOMO_DAC_SCLOEB;
  851. locomo_writel(r, mapbase + LOCOMO_DAC);
  852. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  853. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
  854. if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
  855. printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
  856. return;
  857. }
  858. /* Send DAC data */
  859. for (i = 1; i <= 8; i++) {
  860. locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
  861. }
  862. /* Check A bit */
  863. r = locomo_readl(mapbase + LOCOMO_DAC);
  864. r &= ~(LOCOMO_DAC_SCLOEB);
  865. locomo_writel(r, mapbase + LOCOMO_DAC);
  866. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  867. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  868. r = locomo_readl(mapbase + LOCOMO_DAC);
  869. r &= ~(LOCOMO_DAC_SDAOEB);
  870. locomo_writel(r, mapbase + LOCOMO_DAC);
  871. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  872. r = locomo_readl(mapbase + LOCOMO_DAC);
  873. r |= LOCOMO_DAC_SCLOEB;
  874. locomo_writel(r, mapbase + LOCOMO_DAC);
  875. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  876. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
  877. if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
  878. printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
  879. return;
  880. }
  881. /* stop */
  882. r = locomo_readl(mapbase + LOCOMO_DAC);
  883. r &= ~(LOCOMO_DAC_SCLOEB);
  884. locomo_writel(r, mapbase + LOCOMO_DAC);
  885. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  886. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  887. r = locomo_readl(mapbase + LOCOMO_DAC);
  888. r |= LOCOMO_DAC_SCLOEB;
  889. locomo_writel(r, mapbase + LOCOMO_DAC);
  890. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  891. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
  892. r = locomo_readl(mapbase + LOCOMO_DAC);
  893. r |= LOCOMO_DAC_SDAOEB;
  894. locomo_writel(r, mapbase + LOCOMO_DAC);
  895. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  896. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
  897. r = locomo_readl(mapbase + LOCOMO_DAC);
  898. r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
  899. locomo_writel(r, mapbase + LOCOMO_DAC);
  900. udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */
  901. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  902. spin_unlock_irqrestore(&lchip->lock, flags);
  903. }
  904. /*
  905. * LoCoMo "Register Access Bus."
  906. *
  907. * We model this as a regular bus type, and hang devices directly
  908. * off this.
  909. */
  910. static int locomo_match(struct device *_dev, struct device_driver *_drv)
  911. {
  912. struct locomo_dev *dev = LOCOMO_DEV(_dev);
  913. struct locomo_driver *drv = LOCOMO_DRV(_drv);
  914. return dev->devid == drv->devid;
  915. }
  916. static int locomo_bus_suspend(struct device *dev, pm_message_t state)
  917. {
  918. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  919. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  920. int ret = 0;
  921. if (drv && drv->suspend)
  922. ret = drv->suspend(ldev, state);
  923. return ret;
  924. }
  925. static int locomo_bus_resume(struct device *dev)
  926. {
  927. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  928. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  929. int ret = 0;
  930. if (drv && drv->resume)
  931. ret = drv->resume(ldev);
  932. return ret;
  933. }
  934. static int locomo_bus_probe(struct device *dev)
  935. {
  936. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  937. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  938. int ret = -ENODEV;
  939. if (drv->probe)
  940. ret = drv->probe(ldev);
  941. return ret;
  942. }
  943. static int locomo_bus_remove(struct device *dev)
  944. {
  945. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  946. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  947. int ret = 0;
  948. if (drv->remove)
  949. ret = drv->remove(ldev);
  950. return ret;
  951. }
  952. struct bus_type locomo_bus_type = {
  953. .name = "locomo-bus",
  954. .match = locomo_match,
  955. .probe = locomo_bus_probe,
  956. .remove = locomo_bus_remove,
  957. .suspend = locomo_bus_suspend,
  958. .resume = locomo_bus_resume,
  959. };
  960. int locomo_driver_register(struct locomo_driver *driver)
  961. {
  962. driver->drv.bus = &locomo_bus_type;
  963. return driver_register(&driver->drv);
  964. }
  965. void locomo_driver_unregister(struct locomo_driver *driver)
  966. {
  967. driver_unregister(&driver->drv);
  968. }
  969. static int __init locomo_init(void)
  970. {
  971. int ret = bus_register(&locomo_bus_type);
  972. if (ret == 0)
  973. platform_driver_register(&locomo_device_driver);
  974. return ret;
  975. }
  976. static void __exit locomo_exit(void)
  977. {
  978. platform_driver_unregister(&locomo_device_driver);
  979. bus_unregister(&locomo_bus_type);
  980. }
  981. module_init(locomo_init);
  982. module_exit(locomo_exit);
  983. MODULE_DESCRIPTION("Sharp LoCoMo core driver");
  984. MODULE_LICENSE("GPL");
  985. MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
  986. EXPORT_SYMBOL(locomo_driver_register);
  987. EXPORT_SYMBOL(locomo_driver_unregister);
  988. EXPORT_SYMBOL(locomo_gpio_set_dir);
  989. EXPORT_SYMBOL(locomo_gpio_read_level);
  990. EXPORT_SYMBOL(locomo_gpio_read_output);
  991. EXPORT_SYMBOL(locomo_gpio_write);
  992. EXPORT_SYMBOL(locomo_m62332_senddata);