19 #include <linux/kernel.h>
23 #include <linux/export.h>
25 #include <linux/slab.h>
55 #define INIT_CDEX(_name, _rate) \
56 [ASIC3_CLOCK_##_name] = { \
57 .cdex = CLOCK_CDEX_##_name, \
90 static int asic3_gpio_get(
struct gpio_chip *
chip,
unsigned offset);
118 spin_unlock_irqrestore(&asic->
lock, flags);
122 #define MAX_ASIC_ISR_LOOPS 20
123 #define ASIC3_GPIO_BASE_INCR \
124 (ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE)
126 static void asic3_irq_flip_edge(
struct asic3 *asic,
138 spin_unlock_irqrestore(&asic->
lock, flags);
141 static void asic3_irq_demux(
unsigned int irq,
struct irq_desc *
desc)
143 struct asic3 *asic = irq_desc_get_handler_data(desc);
148 data->
chip->irq_ack(data);
157 spin_unlock_irqrestore(&asic->
lock, flags);
160 if ((status & 0x3ff) == 0)
165 if (status & (1 << bank)) {
166 unsigned long base, istat;
179 spin_unlock_irqrestore(&asic->
lock, flags);
189 (ASIC3_GPIOS_PER_BANK * bank)
193 asic3_irq_flip_edge(asic, base,
207 if (iter >= MAX_ASIC_ISR_LOOPS)
208 dev_err(asic->
dev,
"interrupt processing overrun\n");
211 static inline int asic3_irq_to_bank(
struct asic3 *asic,
int irq)
220 static inline int asic3_irq_to_index(
struct asic3 *asic,
int irq)
222 return (irq - asic->
irq_base) & 0xf;
225 static void asic3_mask_gpio_irq(
struct irq_data *data)
227 struct asic3 *asic = irq_data_get_irq_chip_data(data);
231 bank = asic3_irq_to_bank(asic, data->
irq);
232 index = asic3_irq_to_index(asic, data->
irq);
238 spin_unlock_irqrestore(&asic->
lock, flags);
241 static void asic3_mask_irq(
struct irq_data *data)
243 struct asic3 *asic = irq_data_get_irq_chip_data(data);
259 spin_unlock_irqrestore(&asic->
lock, flags);
262 static void asic3_unmask_gpio_irq(
struct irq_data *data)
264 struct asic3 *asic = irq_data_get_irq_chip_data(data);
268 bank = asic3_irq_to_bank(asic, data->
irq);
269 index = asic3_irq_to_index(asic, data->
irq);
273 val &= ~(1 <<
index);
275 spin_unlock_irqrestore(&asic->
lock, flags);
278 static void asic3_unmask_irq(
struct irq_data *data)
280 struct asic3 *asic = irq_data_get_irq_chip_data(data);
296 spin_unlock_irqrestore(&asic->
lock, flags);
299 static int asic3_gpio_irq_type(
struct irq_data *data,
unsigned int type)
301 struct asic3 *asic = irq_data_get_irq_chip_data(data);
306 bank = asic3_irq_to_bank(asic, data->
irq);
307 index = asic3_irq_to_index(asic, data->
irq);
344 dev_notice(asic->
dev,
"irq type not changed\n");
352 spin_unlock_irqrestore(&asic->
lock, flags);
356 static int asic3_gpio_irq_set_wake(
struct irq_data *data,
unsigned int on)
358 struct asic3 *asic = irq_data_get_irq_chip_data(data);
362 bank = asic3_irq_to_bank(asic, data->
irq);
363 index = asic3_irq_to_index(asic, data->
irq);
371 static struct irq_chip asic3_gpio_irq_chip = {
372 .name =
"ASIC3-GPIO",
373 .irq_ack = asic3_mask_gpio_irq,
374 .irq_mask = asic3_mask_gpio_irq,
375 .irq_unmask = asic3_unmask_gpio_irq,
376 .irq_set_type = asic3_gpio_irq_type,
377 .irq_set_wake = asic3_gpio_irq_set_wake,
380 static struct irq_chip asic3_irq_chip = {
382 .irq_ack = asic3_mask_irq,
383 .irq_mask = asic3_mask_irq,
384 .irq_unmask = asic3_unmask_irq,
389 struct asic3 *asic = platform_get_drvdata(pdev);
390 unsigned long clksel = 0;
406 for (irq = irq_base; irq < irq_base +
ASIC3_NR_IRQS; irq++) {
420 irq_set_chained_handler(asic->
irq_nr, asic3_irq_demux);
429 struct asic3 *asic = platform_get_drvdata(pdev);
434 for (irq = irq_base; irq < irq_base +
ASIC3_NR_IRQS; irq++) {
436 irq_set_chip_and_handler(irq,
NULL,
NULL);
443 static int asic3_gpio_direction(
struct gpio_chip *
chip,
455 dev_err(asic->
dev,
"Invalid base (0x%x) for gpio %d\n",
472 spin_unlock_irqrestore(&asic->
lock, flags);
478 static int asic3_gpio_direction_input(
struct gpio_chip *chip,
481 return asic3_gpio_direction(chip, offset, 0);
484 static int asic3_gpio_direction_output(
struct gpio_chip *chip,
485 unsigned offset,
int value)
487 return asic3_gpio_direction(chip, offset, 1);
490 static int asic3_gpio_get(
struct gpio_chip *chip,
501 dev_err(asic->
dev,
"Invalid base (0x%x) for gpio %d\n",
509 static void asic3_gpio_set(
struct gpio_chip *chip,
510 unsigned offset,
int value)
521 dev_err(asic->
dev,
"Invalid base (0x%x) for gpio %d\n",
539 spin_unlock_irqrestore(&asic->
lock, flags);
544 static int asic3_gpio_to_irq(
struct gpio_chip *chip,
unsigned offset)
552 u16 *gpio_config,
int num)
554 struct asic3 *asic = platform_get_drvdata(pdev);
560 memset(alt_reg, 0, ASIC3_NUM_GPIO_BANKS *
sizeof(
u16));
561 memset(out_reg, 0, ASIC3_NUM_GPIO_BANKS *
sizeof(
u16));
562 memset(dir_reg, 0, ASIC3_NUM_GPIO_BANKS *
sizeof(
u16));
570 for (i = 0; i < num; i++) {
582 alt_reg[bank_num] |= (alt << bit_num);
583 out_reg[bank_num] |= (init << bit_num);
584 dir_reg[bank_num] |= (dir << bit_num);
606 struct asic3 *asic = platform_get_drvdata(pdev);
622 spin_unlock_irqrestore(&asic->
lock, flags);
625 static void asic3_clk_disable(
struct asic3 *asic,
struct asic3_clk *clk)
638 spin_unlock_irqrestore(&asic->
lock, flags);
644 .reset_recover_delay = 1,
647 static struct resource ds1wm_resources[] = {
698 static struct mfd_cell asic3_cell_ds1wm = {
700 .enable = ds1wm_enable,
701 .disable = ds1wm_disable,
702 .platform_data = &ds1wm_pdata,
703 .pdata_size =
sizeof(ds1wm_pdata),
705 .resources = ds1wm_resources,
724 .set_pwr = asic3_mmc_pwr,
725 .set_clk_div = asic3_mmc_clk_div,
728 static struct resource asic3_mmc_resources[] = {
800 static struct mfd_cell asic3_cell_mmc = {
802 .enable = asic3_mmc_enable,
803 .disable = asic3_mmc_disable,
804 .suspend = asic3_mmc_disable,
805 .resume = asic3_mmc_enable,
806 .platform_data = &asic3_mmc_data,
807 .pdata_size =
sizeof(asic3_mmc_data),
809 .resources = asic3_mmc_resources,
820 const struct mfd_cell *cell = mfd_get_cell(pdev);
823 asic3_clk_enable(asic, &asic->
clocks[clock_ledn[cell->
id]]);
830 const struct mfd_cell *cell = mfd_get_cell(pdev);
833 asic3_clk_disable(asic, &asic->
clocks[clock_ledn[cell->
id]]);
840 const struct mfd_cell *cell = mfd_get_cell(pdev);
846 asic3_clk_disable(asic, &asic->
clocks[clock_ledn[cell->
id]]);
853 .name =
"leds-asic3",
855 .enable = asic3_leds_enable,
856 .disable = asic3_leds_disable,
857 .suspend = asic3_leds_suspend,
858 .resume = asic3_leds_enable,
861 .name =
"leds-asic3",
863 .enable = asic3_leds_enable,
864 .disable = asic3_leds_disable,
865 .suspend = asic3_leds_suspend,
866 .resume = asic3_leds_enable,
869 .name =
"leds-asic3",
871 .enable = asic3_leds_enable,
872 .disable = asic3_leds_disable,
873 .suspend = asic3_leds_suspend,
874 .resume = asic3_leds_enable,
882 struct asic3 *asic = platform_get_drvdata(pdev);
907 dev_dbg(asic->
dev,
"Couldn't ioremap SD_CONFIG\n");
921 if (mem_sdio && (irq >= 0)) {
923 &asic3_cell_mmc, 1, mem_sdio, irq,
NULL);
937 asic3_cell_leds, ASIC3_NUM_LEDS,
NULL, 0,
NULL);
946 struct asic3 *asic = platform_get_drvdata(pdev);
958 unsigned long clksel;
968 platform_set_drvdata(pdev, asic);
988 asic->
bus_shift = 2 - (resource_size(mem) >> 12);
993 ret = asic3_irq_probe(pdev);
999 asic->
gpio.label =
"asic3";
1002 asic->
gpio.get = asic3_gpio_get;
1003 asic->
gpio.set = asic3_gpio_set;
1004 asic->
gpio.direction_input = asic3_gpio_direction_input;
1005 asic->
gpio.direction_output = asic3_gpio_direction_output;
1006 asic->
gpio.to_irq = asic3_gpio_to_irq;
1008 ret = asic3_gpio_probe(pdev,
1019 memcpy(asic->
clocks, asic3_clk_init,
sizeof(asic3_clk_init));
1021 asic3_mfd_probe(pdev, pdata, mem);
1031 asic3_irq_remove(pdev);
1045 struct asic3 *asic = platform_get_drvdata(pdev);
1050 asic3_mfd_remove(pdev);
1052 ret = asic3_gpio_remove(pdev);
1055 asic3_irq_remove(pdev);
1075 .shutdown = asic3_shutdown,
1078 static int __init asic3_init(
void)