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