locomo.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  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. if (irq < 0)
  668. return -ENXIO;
  669. return __locomo_probe(&dev->dev, mem, irq);
  670. }
  671. static int locomo_remove(struct platform_device *dev)
  672. {
  673. struct locomo *lchip = platform_get_drvdata(dev);
  674. if (lchip) {
  675. __locomo_remove(lchip);
  676. platform_set_drvdata(dev, NULL);
  677. }
  678. return 0;
  679. }
  680. /*
  681. * Not sure if this should be on the system bus or not yet.
  682. * We really want some way to register a system device at
  683. * the per-machine level, and then have this driver pick
  684. * up the registered devices.
  685. */
  686. static struct platform_driver locomo_device_driver = {
  687. .probe = locomo_probe,
  688. .remove = locomo_remove,
  689. #ifdef CONFIG_PM
  690. .suspend = locomo_suspend,
  691. .resume = locomo_resume,
  692. #endif
  693. .driver = {
  694. .name = "locomo",
  695. },
  696. };
  697. /*
  698. * Get the parent device driver (us) structure
  699. * from a child function device
  700. */
  701. static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
  702. {
  703. return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
  704. }
  705. void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir)
  706. {
  707. struct locomo *lchip = locomo_chip_driver(ldev);
  708. unsigned long flags;
  709. unsigned int r;
  710. spin_lock_irqsave(&lchip->lock, flags);
  711. r = locomo_readl(lchip->base + LOCOMO_GPD);
  712. r &= ~bits;
  713. locomo_writel(r, lchip->base + LOCOMO_GPD);
  714. r = locomo_readl(lchip->base + LOCOMO_GPE);
  715. if (dir)
  716. r |= bits;
  717. else
  718. r &= ~bits;
  719. locomo_writel(r, lchip->base + LOCOMO_GPE);
  720. spin_unlock_irqrestore(&lchip->lock, flags);
  721. }
  722. unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits)
  723. {
  724. struct locomo *lchip = locomo_chip_driver(ldev);
  725. unsigned long flags;
  726. unsigned int ret;
  727. spin_lock_irqsave(&lchip->lock, flags);
  728. ret = locomo_readl(lchip->base + LOCOMO_GPL);
  729. spin_unlock_irqrestore(&lchip->lock, flags);
  730. ret &= bits;
  731. return ret;
  732. }
  733. unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits)
  734. {
  735. struct locomo *lchip = locomo_chip_driver(ldev);
  736. unsigned long flags;
  737. unsigned int ret;
  738. spin_lock_irqsave(&lchip->lock, flags);
  739. ret = locomo_readl(lchip->base + LOCOMO_GPO);
  740. spin_unlock_irqrestore(&lchip->lock, flags);
  741. ret &= bits;
  742. return ret;
  743. }
  744. void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set)
  745. {
  746. struct locomo *lchip = locomo_chip_driver(ldev);
  747. unsigned long flags;
  748. unsigned int r;
  749. spin_lock_irqsave(&lchip->lock, flags);
  750. r = locomo_readl(lchip->base + LOCOMO_GPO);
  751. if (set)
  752. r |= bits;
  753. else
  754. r &= ~bits;
  755. locomo_writel(r, lchip->base + LOCOMO_GPO);
  756. spin_unlock_irqrestore(&lchip->lock, flags);
  757. }
  758. static void locomo_m62332_sendbit(void *mapbase, int bit)
  759. {
  760. unsigned int r;
  761. r = locomo_readl(mapbase + LOCOMO_DAC);
  762. r &= ~(LOCOMO_DAC_SCLOEB);
  763. locomo_writel(r, mapbase + LOCOMO_DAC);
  764. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  765. udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
  766. r = locomo_readl(mapbase + LOCOMO_DAC);
  767. r &= ~(LOCOMO_DAC_SCLOEB);
  768. locomo_writel(r, mapbase + LOCOMO_DAC);
  769. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  770. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  771. if (bit & 1) {
  772. r = locomo_readl(mapbase + LOCOMO_DAC);
  773. r |= LOCOMO_DAC_SDAOEB;
  774. locomo_writel(r, mapbase + LOCOMO_DAC);
  775. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  776. } else {
  777. r = locomo_readl(mapbase + LOCOMO_DAC);
  778. r &= ~(LOCOMO_DAC_SDAOEB);
  779. locomo_writel(r, mapbase + LOCOMO_DAC);
  780. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  781. }
  782. udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */
  783. r = locomo_readl(mapbase + LOCOMO_DAC);
  784. r |= LOCOMO_DAC_SCLOEB;
  785. locomo_writel(r, mapbase + LOCOMO_DAC);
  786. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  787. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
  788. }
  789. void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
  790. {
  791. struct locomo *lchip = locomo_chip_driver(ldev);
  792. int i;
  793. unsigned char data;
  794. unsigned int r;
  795. void *mapbase = lchip->base;
  796. unsigned long flags;
  797. spin_lock_irqsave(&lchip->lock, flags);
  798. /* Start */
  799. udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */
  800. r = locomo_readl(mapbase + LOCOMO_DAC);
  801. r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
  802. locomo_writel(r, mapbase + LOCOMO_DAC);
  803. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  804. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
  805. r = locomo_readl(mapbase + LOCOMO_DAC);
  806. r &= ~(LOCOMO_DAC_SDAOEB);
  807. locomo_writel(r, mapbase + LOCOMO_DAC);
  808. udelay(DAC_START_HOLD_TIME); /* 5.0 usec */
  809. udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
  810. /* Send slave address and W bit (LSB is W bit) */
  811. data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
  812. for (i = 1; i <= 8; i++) {
  813. locomo_m62332_sendbit(mapbase, data >> (8 - i));
  814. }
  815. /* Check A bit */
  816. r = locomo_readl(mapbase + LOCOMO_DAC);
  817. r &= ~(LOCOMO_DAC_SCLOEB);
  818. locomo_writel(r, mapbase + LOCOMO_DAC);
  819. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  820. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  821. r = locomo_readl(mapbase + LOCOMO_DAC);
  822. r &= ~(LOCOMO_DAC_SDAOEB);
  823. locomo_writel(r, mapbase + LOCOMO_DAC);
  824. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  825. r = locomo_readl(mapbase + LOCOMO_DAC);
  826. r |= LOCOMO_DAC_SCLOEB;
  827. locomo_writel(r, mapbase + LOCOMO_DAC);
  828. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  829. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
  830. if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
  831. printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
  832. return;
  833. }
  834. /* Send Sub address (LSB is channel select) */
  835. /* channel = 0 : ch1 select */
  836. /* = 1 : ch2 select */
  837. data = M62332_SUB_ADDR + channel;
  838. for (i = 1; i <= 8; i++) {
  839. locomo_m62332_sendbit(mapbase, data >> (8 - i));
  840. }
  841. /* Check A bit */
  842. r = locomo_readl(mapbase + LOCOMO_DAC);
  843. r &= ~(LOCOMO_DAC_SCLOEB);
  844. locomo_writel(r, mapbase + LOCOMO_DAC);
  845. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  846. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  847. r = locomo_readl(mapbase + LOCOMO_DAC);
  848. r &= ~(LOCOMO_DAC_SDAOEB);
  849. locomo_writel(r, mapbase + LOCOMO_DAC);
  850. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  851. r = locomo_readl(mapbase + LOCOMO_DAC);
  852. r |= LOCOMO_DAC_SCLOEB;
  853. locomo_writel(r, mapbase + LOCOMO_DAC);
  854. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  855. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
  856. if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
  857. printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
  858. return;
  859. }
  860. /* Send DAC data */
  861. for (i = 1; i <= 8; i++) {
  862. locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
  863. }
  864. /* Check A bit */
  865. r = locomo_readl(mapbase + LOCOMO_DAC);
  866. r &= ~(LOCOMO_DAC_SCLOEB);
  867. locomo_writel(r, mapbase + LOCOMO_DAC);
  868. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  869. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  870. r = locomo_readl(mapbase + LOCOMO_DAC);
  871. r &= ~(LOCOMO_DAC_SDAOEB);
  872. locomo_writel(r, mapbase + LOCOMO_DAC);
  873. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  874. r = locomo_readl(mapbase + LOCOMO_DAC);
  875. r |= LOCOMO_DAC_SCLOEB;
  876. locomo_writel(r, mapbase + LOCOMO_DAC);
  877. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  878. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
  879. if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
  880. printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
  881. return;
  882. }
  883. /* stop */
  884. r = locomo_readl(mapbase + LOCOMO_DAC);
  885. r &= ~(LOCOMO_DAC_SCLOEB);
  886. locomo_writel(r, mapbase + LOCOMO_DAC);
  887. udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
  888. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  889. r = locomo_readl(mapbase + LOCOMO_DAC);
  890. r |= LOCOMO_DAC_SCLOEB;
  891. locomo_writel(r, mapbase + LOCOMO_DAC);
  892. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  893. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
  894. r = locomo_readl(mapbase + LOCOMO_DAC);
  895. r |= LOCOMO_DAC_SDAOEB;
  896. locomo_writel(r, mapbase + LOCOMO_DAC);
  897. udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
  898. udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
  899. r = locomo_readl(mapbase + LOCOMO_DAC);
  900. r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
  901. locomo_writel(r, mapbase + LOCOMO_DAC);
  902. udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */
  903. udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
  904. spin_unlock_irqrestore(&lchip->lock, flags);
  905. }
  906. /*
  907. * LoCoMo "Register Access Bus."
  908. *
  909. * We model this as a regular bus type, and hang devices directly
  910. * off this.
  911. */
  912. static int locomo_match(struct device *_dev, struct device_driver *_drv)
  913. {
  914. struct locomo_dev *dev = LOCOMO_DEV(_dev);
  915. struct locomo_driver *drv = LOCOMO_DRV(_drv);
  916. return dev->devid == drv->devid;
  917. }
  918. static int locomo_bus_suspend(struct device *dev, pm_message_t state)
  919. {
  920. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  921. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  922. int ret = 0;
  923. if (drv && drv->suspend)
  924. ret = drv->suspend(ldev, state);
  925. return ret;
  926. }
  927. static int locomo_bus_resume(struct device *dev)
  928. {
  929. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  930. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  931. int ret = 0;
  932. if (drv && drv->resume)
  933. ret = drv->resume(ldev);
  934. return ret;
  935. }
  936. static int locomo_bus_probe(struct device *dev)
  937. {
  938. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  939. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  940. int ret = -ENODEV;
  941. if (drv->probe)
  942. ret = drv->probe(ldev);
  943. return ret;
  944. }
  945. static int locomo_bus_remove(struct device *dev)
  946. {
  947. struct locomo_dev *ldev = LOCOMO_DEV(dev);
  948. struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
  949. int ret = 0;
  950. if (drv->remove)
  951. ret = drv->remove(ldev);
  952. return ret;
  953. }
  954. struct bus_type locomo_bus_type = {
  955. .name = "locomo-bus",
  956. .match = locomo_match,
  957. .probe = locomo_bus_probe,
  958. .remove = locomo_bus_remove,
  959. .suspend = locomo_bus_suspend,
  960. .resume = locomo_bus_resume,
  961. };
  962. int locomo_driver_register(struct locomo_driver *driver)
  963. {
  964. driver->drv.bus = &locomo_bus_type;
  965. return driver_register(&driver->drv);
  966. }
  967. void locomo_driver_unregister(struct locomo_driver *driver)
  968. {
  969. driver_unregister(&driver->drv);
  970. }
  971. static int __init locomo_init(void)
  972. {
  973. int ret = bus_register(&locomo_bus_type);
  974. if (ret == 0)
  975. platform_driver_register(&locomo_device_driver);
  976. return ret;
  977. }
  978. static void __exit locomo_exit(void)
  979. {
  980. platform_driver_unregister(&locomo_device_driver);
  981. bus_unregister(&locomo_bus_type);
  982. }
  983. module_init(locomo_init);
  984. module_exit(locomo_exit);
  985. MODULE_DESCRIPTION("Sharp LoCoMo core driver");
  986. MODULE_LICENSE("GPL");
  987. MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
  988. EXPORT_SYMBOL(locomo_driver_register);
  989. EXPORT_SYMBOL(locomo_driver_unregister);
  990. EXPORT_SYMBOL(locomo_gpio_set_dir);
  991. EXPORT_SYMBOL(locomo_gpio_read_level);
  992. EXPORT_SYMBOL(locomo_gpio_read_output);
  993. EXPORT_SYMBOL(locomo_gpio_write);
  994. EXPORT_SYMBOL(locomo_m62332_senddata);