Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: asic3: add clock handling for MFD cells

Since ASIC3 has to work on both PXA and S3C and since their
struct clk implementations differ, we can't register out
clocks with the clkdev mechanism (yet?).
For now we have to keep clock handling internal to this
driver and enable/disable the clocks via the
mfd_cell->enable/disable functions.

Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Philipp Zabel and committed by
Samuel Ortiz
e956a2a8 6483c1b5

+80
+80
drivers/mfd/asic3.c
··· 25 25 26 26 #include <linux/mfd/asic3.h> 27 27 28 + enum { 29 + ASIC3_CLOCK_SPI, 30 + ASIC3_CLOCK_OWM, 31 + ASIC3_CLOCK_PWM0, 32 + ASIC3_CLOCK_PWM1, 33 + ASIC3_CLOCK_LED0, 34 + ASIC3_CLOCK_LED1, 35 + ASIC3_CLOCK_LED2, 36 + ASIC3_CLOCK_SD_HOST, 37 + ASIC3_CLOCK_SD_BUS, 38 + ASIC3_CLOCK_SMBUS, 39 + ASIC3_CLOCK_EX0, 40 + ASIC3_CLOCK_EX1, 41 + }; 42 + 43 + struct asic3_clk { 44 + int enabled; 45 + unsigned int cdex; 46 + unsigned long rate; 47 + }; 48 + 49 + #define INIT_CDEX(_name, _rate) \ 50 + [ASIC3_CLOCK_##_name] = { \ 51 + .cdex = CLOCK_CDEX_##_name, \ 52 + .rate = _rate, \ 53 + } 54 + 55 + struct asic3_clk asic3_clk_init[] __initdata = { 56 + INIT_CDEX(SPI, 0), 57 + INIT_CDEX(OWM, 5000000), 58 + INIT_CDEX(PWM0, 0), 59 + INIT_CDEX(PWM1, 0), 60 + INIT_CDEX(LED0, 0), 61 + INIT_CDEX(LED1, 0), 62 + INIT_CDEX(LED2, 0), 63 + INIT_CDEX(SD_HOST, 24576000), 64 + INIT_CDEX(SD_BUS, 12288000), 65 + INIT_CDEX(SMBUS, 0), 66 + INIT_CDEX(EX0, 32768), 67 + INIT_CDEX(EX1, 24576000), 68 + }; 69 + 28 70 struct asic3 { 29 71 void __iomem *mapping; 30 72 unsigned int bus_shift; ··· 76 34 u16 irq_bothedge[4]; 77 35 struct gpio_chip gpio; 78 36 struct device *dev; 37 + 38 + struct asic3_clk clocks[ARRAY_SIZE(asic3_clk_init)]; 79 39 }; 80 40 81 41 static int asic3_gpio_get(struct gpio_chip *chip, unsigned offset); ··· 584 540 return gpiochip_remove(&asic->gpio); 585 541 } 586 542 543 + static int asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk) 544 + { 545 + unsigned long flags; 546 + u32 cdex; 547 + 548 + spin_lock_irqsave(&asic->lock, flags); 549 + if (clk->enabled++ == 0) { 550 + cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX)); 551 + cdex |= clk->cdex; 552 + asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex); 553 + } 554 + spin_unlock_irqrestore(&asic->lock, flags); 555 + 556 + return 0; 557 + } 558 + 559 + static void asic3_clk_disable(struct asic3 *asic, struct asic3_clk *clk) 560 + { 561 + unsigned long flags; 562 + u32 cdex; 563 + 564 + WARN_ON(clk->enabled == 0); 565 + 566 + spin_lock_irqsave(&asic->lock, flags); 567 + if (--clk->enabled == 0) { 568 + cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX)); 569 + cdex &= ~clk->cdex; 570 + asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex); 571 + } 572 + spin_unlock_irqrestore(&asic->lock, flags); 573 + } 587 574 588 575 /* Core */ 589 576 static int __init asic3_probe(struct platform_device *pdev) ··· 679 604 dev_err(asic->dev, "GPIO probe failed\n"); 680 605 goto out_irq; 681 606 } 607 + 608 + /* Making a per-device copy is only needed for the 609 + * theoretical case of multiple ASIC3s on one board: 610 + */ 611 + memcpy(asic->clocks, asic3_clk_init, sizeof(asic3_clk_init)); 682 612 683 613 dev_info(asic->dev, "ASIC3 Core driver\n"); 684 614