asic3.c 26.7 KB
Newer Older
S
Samuel Ortiz 已提交
1 2 3 4 5 6 7 8 9 10 11
/*
 * driver/mfd/asic3.c
 *
 * Compaq ASIC3 support.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * Copyright 2001 Compaq Computer Corporation.
 * Copyright 2004-2005 Phil Blundell
S
Samuel Ortiz 已提交
12
 * Copyright 2007-2008 OpenedHand Ltd.
S
Samuel Ortiz 已提交
13 14 15 16 17 18 19
 *
 * Authors: Phil Blundell <pb@handhelds.org>,
 *	    Samuel Ortiz <sameo@openedhand.com>
 *
 */

#include <linux/kernel.h>
P
Philipp Zabel 已提交
20
#include <linux/delay.h>
S
Samuel Ortiz 已提交
21
#include <linux/irq.h>
S
Samuel Ortiz 已提交
22
#include <linux/gpio.h>
23
#include <linux/export.h>
S
Samuel Ortiz 已提交
24
#include <linux/io.h>
25
#include <linux/slab.h>
S
Samuel Ortiz 已提交
26 27 28 29
#include <linux/spinlock.h>
#include <linux/platform_device.h>

#include <linux/mfd/asic3.h>
P
Philipp Zabel 已提交
30 31
#include <linux/mfd/core.h>
#include <linux/mfd/ds1wm.h>
P
Philipp Zabel 已提交
32
#include <linux/mfd/tmio.h>
S
Samuel Ortiz 已提交
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
enum {
	ASIC3_CLOCK_SPI,
	ASIC3_CLOCK_OWM,
	ASIC3_CLOCK_PWM0,
	ASIC3_CLOCK_PWM1,
	ASIC3_CLOCK_LED0,
	ASIC3_CLOCK_LED1,
	ASIC3_CLOCK_LED2,
	ASIC3_CLOCK_SD_HOST,
	ASIC3_CLOCK_SD_BUS,
	ASIC3_CLOCK_SMBUS,
	ASIC3_CLOCK_EX0,
	ASIC3_CLOCK_EX1,
};

struct asic3_clk {
	int enabled;
	unsigned int cdex;
	unsigned long rate;
};

#define INIT_CDEX(_name, _rate)	\
	[ASIC3_CLOCK_##_name] = {		\
		.cdex = CLOCK_CDEX_##_name,	\
		.rate = _rate,			\
	}

61
static struct asic3_clk asic3_clk_init[] __initdata = {
62 63 64 65 66 67 68 69 70 71 72 73 74 75
	INIT_CDEX(SPI, 0),
	INIT_CDEX(OWM, 5000000),
	INIT_CDEX(PWM0, 0),
	INIT_CDEX(PWM1, 0),
	INIT_CDEX(LED0, 0),
	INIT_CDEX(LED1, 0),
	INIT_CDEX(LED2, 0),
	INIT_CDEX(SD_HOST, 24576000),
	INIT_CDEX(SD_BUS, 12288000),
	INIT_CDEX(SMBUS, 0),
	INIT_CDEX(EX0, 32768),
	INIT_CDEX(EX1, 24576000),
};

S
Samuel Ortiz 已提交
76 77 78 79 80 81 82 83 84
struct asic3 {
	void __iomem *mapping;
	unsigned int bus_shift;
	unsigned int irq_nr;
	unsigned int irq_base;
	spinlock_t lock;
	u16 irq_bothedge[4];
	struct gpio_chip gpio;
	struct device *dev;
85
	void __iomem *tmio_cnf;
86 87

	struct asic3_clk clocks[ARRAY_SIZE(asic3_clk_init)];
S
Samuel Ortiz 已提交
88 89 90 91
};

static int asic3_gpio_get(struct gpio_chip *chip, unsigned offset);

P
Paul Parsons 已提交
92
void asic3_write_register(struct asic3 *asic, unsigned int reg, u32 value)
S
Samuel Ortiz 已提交
93
{
94
	iowrite16(value, asic->mapping +
S
Samuel Ortiz 已提交
95 96
		  (reg >> asic->bus_shift));
}
P
Paul Parsons 已提交
97
EXPORT_SYMBOL_GPL(asic3_write_register);
S
Samuel Ortiz 已提交
98

P
Paul Parsons 已提交
99
u32 asic3_read_register(struct asic3 *asic, unsigned int reg)
S
Samuel Ortiz 已提交
100
{
101
	return ioread16(asic->mapping +
S
Samuel Ortiz 已提交
102 103
			(reg >> asic->bus_shift));
}
P
Paul Parsons 已提交
104
EXPORT_SYMBOL_GPL(asic3_read_register);
S
Samuel Ortiz 已提交
105

106
static void asic3_set_register(struct asic3 *asic, u32 reg, u32 bits, bool set)
107 108 109 110 111 112 113 114 115 116 117 118 119 120
{
	unsigned long flags;
	u32 val;

	spin_lock_irqsave(&asic->lock, flags);
	val = asic3_read_register(asic, reg);
	if (set)
		val |= bits;
	else
		val &= ~bits;
	asic3_write_register(asic, reg, val);
	spin_unlock_irqrestore(&asic->lock, flags);
}

S
Samuel Ortiz 已提交
121 122
/* IRQs */
#define MAX_ASIC_ISR_LOOPS    20
123 124
#define ASIC3_GPIO_BASE_INCR \
	(ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE)
S
Samuel Ortiz 已提交
125 126 127 128 129 130 131 132 133

static void asic3_irq_flip_edge(struct asic3 *asic,
				u32 base, int bit)
{
	u16 edge;
	unsigned long flags;

	spin_lock_irqsave(&asic->lock, flags);
	edge = asic3_read_register(asic,
134
				   base + ASIC3_GPIO_EDGE_TRIGGER);
S
Samuel Ortiz 已提交
135 136
	edge ^= bit;
	asic3_write_register(asic,
137
			     base + ASIC3_GPIO_EDGE_TRIGGER, edge);
S
Samuel Ortiz 已提交
138 139 140 141 142
	spin_unlock_irqrestore(&asic->lock, flags);
}

static void asic3_irq_demux(unsigned int irq, struct irq_desc *desc)
{
143 144
	struct asic3 *asic = irq_desc_get_handler_data(desc);
	struct irq_data *data = irq_desc_get_irq_data(desc);
S
Samuel Ortiz 已提交
145 146 147
	int iter, i;
	unsigned long flags;

A
Axel Lin 已提交
148
	data->chip->irq_ack(data);
S
Samuel Ortiz 已提交
149 150 151 152 153 154 155

	for (iter = 0 ; iter < MAX_ASIC_ISR_LOOPS; iter++) {
		u32 status;
		int bank;

		spin_lock_irqsave(&asic->lock, flags);
		status = asic3_read_register(asic,
156
					     ASIC3_OFFSET(INTR, P_INT_STAT));
S
Samuel Ortiz 已提交
157 158 159 160 161 162 163 164 165 166 167
		spin_unlock_irqrestore(&asic->lock, flags);

		/* Check all ten register bits */
		if ((status & 0x3ff) == 0)
			break;

		/* Handle GPIO IRQs */
		for (bank = 0; bank < ASIC3_NUM_GPIO_BANKS; bank++) {
			if (status & (1 << bank)) {
				unsigned long base, istat;

168 169
				base = ASIC3_GPIO_A_BASE
				       + bank * ASIC3_GPIO_BASE_INCR;
S
Samuel Ortiz 已提交
170 171 172 173

				spin_lock_irqsave(&asic->lock, flags);
				istat = asic3_read_register(asic,
							    base +
174
							    ASIC3_GPIO_INT_STATUS);
S
Samuel Ortiz 已提交
175 176 177
				/* Clearing IntStatus */
				asic3_write_register(asic,
						     base +
178
						     ASIC3_GPIO_INT_STATUS, 0);
S
Samuel Ortiz 已提交
179 180 181 182 183 184 185 186 187 188 189 190
				spin_unlock_irqrestore(&asic->lock, flags);

				for (i = 0; i < ASIC3_GPIOS_PER_BANK; i++) {
					int bit = (1 << i);
					unsigned int irqnr;

					if (!(istat & bit))
						continue;

					irqnr = asic->irq_base +
						(ASIC3_GPIOS_PER_BANK * bank)
						+ i;
191
					generic_handle_irq(irqnr);
S
Samuel Ortiz 已提交
192 193 194 195 196 197 198 199 200 201
					if (asic->irq_bothedge[bank] & bit)
						asic3_irq_flip_edge(asic, base,
								    bit);
				}
			}
		}

		/* Handle remaining IRQs in the status register */
		for (i = ASIC3_NUM_GPIOS; i < ASIC3_NR_IRQS; i++) {
			/* They start at bit 4 and go up */
202 203
			if (status & (1 << (i - ASIC3_NUM_GPIOS + 4)))
				generic_handle_irq(asic->irq_base + i);
S
Samuel Ortiz 已提交
204 205 206 207
		}
	}

	if (iter >= MAX_ASIC_ISR_LOOPS)
208
		dev_err(asic->dev, "interrupt processing overrun\n");
S
Samuel Ortiz 已提交
209 210 211 212 213 214 215 216
}

static inline int asic3_irq_to_bank(struct asic3 *asic, int irq)
{
	int n;

	n = (irq - asic->irq_base) >> 4;

217
	return (n * (ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE));
S
Samuel Ortiz 已提交
218 219 220 221 222 223 224
}

static inline int asic3_irq_to_index(struct asic3 *asic, int irq)
{
	return (irq - asic->irq_base) & 0xf;
}

M
Mark Brown 已提交
225
static void asic3_mask_gpio_irq(struct irq_data *data)
S
Samuel Ortiz 已提交
226
{
M
Mark Brown 已提交
227
	struct asic3 *asic = irq_data_get_irq_chip_data(data);
S
Samuel Ortiz 已提交
228 229 230
	u32 val, bank, index;
	unsigned long flags;

M
Mark Brown 已提交
231 232
	bank = asic3_irq_to_bank(asic, data->irq);
	index = asic3_irq_to_index(asic, data->irq);
S
Samuel Ortiz 已提交
233 234

	spin_lock_irqsave(&asic->lock, flags);
235
	val = asic3_read_register(asic, bank + ASIC3_GPIO_MASK);
S
Samuel Ortiz 已提交
236
	val |= 1 << index;
237
	asic3_write_register(asic, bank + ASIC3_GPIO_MASK, val);
S
Samuel Ortiz 已提交
238 239 240
	spin_unlock_irqrestore(&asic->lock, flags);
}

M
Mark Brown 已提交
241
static void asic3_mask_irq(struct irq_data *data)
S
Samuel Ortiz 已提交
242
{
M
Mark Brown 已提交
243
	struct asic3 *asic = irq_data_get_irq_chip_data(data);
S
Samuel Ortiz 已提交
244 245 246 247 248
	int regval;
	unsigned long flags;

	spin_lock_irqsave(&asic->lock, flags);
	regval = asic3_read_register(asic,
249 250
				     ASIC3_INTR_BASE +
				     ASIC3_INTR_INT_MASK);
S
Samuel Ortiz 已提交
251 252

	regval &= ~(ASIC3_INTMASK_MASK0 <<
M
Mark Brown 已提交
253
		    (data->irq - (asic->irq_base + ASIC3_NUM_GPIOS)));
S
Samuel Ortiz 已提交
254 255

	asic3_write_register(asic,
256 257
			     ASIC3_INTR_BASE +
			     ASIC3_INTR_INT_MASK,
S
Samuel Ortiz 已提交
258 259 260 261
			     regval);
	spin_unlock_irqrestore(&asic->lock, flags);
}

M
Mark Brown 已提交
262
static void asic3_unmask_gpio_irq(struct irq_data *data)
S
Samuel Ortiz 已提交
263
{
M
Mark Brown 已提交
264
	struct asic3 *asic = irq_data_get_irq_chip_data(data);
S
Samuel Ortiz 已提交
265 266 267
	u32 val, bank, index;
	unsigned long flags;

M
Mark Brown 已提交
268 269
	bank = asic3_irq_to_bank(asic, data->irq);
	index = asic3_irq_to_index(asic, data->irq);
S
Samuel Ortiz 已提交
270 271

	spin_lock_irqsave(&asic->lock, flags);
272
	val = asic3_read_register(asic, bank + ASIC3_GPIO_MASK);
S
Samuel Ortiz 已提交
273
	val &= ~(1 << index);
274
	asic3_write_register(asic, bank + ASIC3_GPIO_MASK, val);
S
Samuel Ortiz 已提交
275 276 277
	spin_unlock_irqrestore(&asic->lock, flags);
}

M
Mark Brown 已提交
278
static void asic3_unmask_irq(struct irq_data *data)
S
Samuel Ortiz 已提交
279
{
M
Mark Brown 已提交
280
	struct asic3 *asic = irq_data_get_irq_chip_data(data);
S
Samuel Ortiz 已提交
281 282 283 284 285
	int regval;
	unsigned long flags;

	spin_lock_irqsave(&asic->lock, flags);
	regval = asic3_read_register(asic,
286 287
				     ASIC3_INTR_BASE +
				     ASIC3_INTR_INT_MASK);
S
Samuel Ortiz 已提交
288 289

	regval |= (ASIC3_INTMASK_MASK0 <<
M
Mark Brown 已提交
290
		   (data->irq - (asic->irq_base + ASIC3_NUM_GPIOS)));
S
Samuel Ortiz 已提交
291 292

	asic3_write_register(asic,
293 294
			     ASIC3_INTR_BASE +
			     ASIC3_INTR_INT_MASK,
S
Samuel Ortiz 已提交
295 296 297 298
			     regval);
	spin_unlock_irqrestore(&asic->lock, flags);
}

M
Mark Brown 已提交
299
static int asic3_gpio_irq_type(struct irq_data *data, unsigned int type)
S
Samuel Ortiz 已提交
300
{
M
Mark Brown 已提交
301
	struct asic3 *asic = irq_data_get_irq_chip_data(data);
S
Samuel Ortiz 已提交
302 303 304 305
	u32 bank, index;
	u16 trigger, level, edge, bit;
	unsigned long flags;

M
Mark Brown 已提交
306 307
	bank = asic3_irq_to_bank(asic, data->irq);
	index = asic3_irq_to_index(asic, data->irq);
S
Samuel Ortiz 已提交
308 309 310 311
	bit = 1<<index;

	spin_lock_irqsave(&asic->lock, flags);
	level = asic3_read_register(asic,
312
				    bank + ASIC3_GPIO_LEVEL_TRIGGER);
S
Samuel Ortiz 已提交
313
	edge = asic3_read_register(asic,
314
				   bank + ASIC3_GPIO_EDGE_TRIGGER);
S
Samuel Ortiz 已提交
315
	trigger = asic3_read_register(asic,
316
				      bank + ASIC3_GPIO_TRIGGER_TYPE);
M
Mark Brown 已提交
317
	asic->irq_bothedge[(data->irq - asic->irq_base) >> 4] &= ~bit;
S
Samuel Ortiz 已提交
318

319
	if (type == IRQ_TYPE_EDGE_RISING) {
S
Samuel Ortiz 已提交
320 321
		trigger |= bit;
		edge |= bit;
322
	} else if (type == IRQ_TYPE_EDGE_FALLING) {
S
Samuel Ortiz 已提交
323 324
		trigger |= bit;
		edge &= ~bit;
325
	} else if (type == IRQ_TYPE_EDGE_BOTH) {
S
Samuel Ortiz 已提交
326
		trigger |= bit;
M
Mark Brown 已提交
327
		if (asic3_gpio_get(&asic->gpio, data->irq - asic->irq_base))
S
Samuel Ortiz 已提交
328 329 330
			edge &= ~bit;
		else
			edge |= bit;
M
Mark Brown 已提交
331
		asic->irq_bothedge[(data->irq - asic->irq_base) >> 4] |= bit;
332
	} else if (type == IRQ_TYPE_LEVEL_LOW) {
S
Samuel Ortiz 已提交
333 334
		trigger &= ~bit;
		level &= ~bit;
335
	} else if (type == IRQ_TYPE_LEVEL_HIGH) {
S
Samuel Ortiz 已提交
336 337 338 339
		trigger &= ~bit;
		level |= bit;
	} else {
		/*
340
		 * if type == IRQ_TYPE_NONE, we should mask interrupts, but
S
Samuel Ortiz 已提交
341 342 343
		 * be careful to not unmask them if mask was also called.
		 * Probably need internal state for mask.
		 */
344
		dev_notice(asic->dev, "irq type not changed\n");
S
Samuel Ortiz 已提交
345
	}
346
	asic3_write_register(asic, bank + ASIC3_GPIO_LEVEL_TRIGGER,
S
Samuel Ortiz 已提交
347
			     level);
348
	asic3_write_register(asic, bank + ASIC3_GPIO_EDGE_TRIGGER,
S
Samuel Ortiz 已提交
349
			     edge);
350
	asic3_write_register(asic, bank + ASIC3_GPIO_TRIGGER_TYPE,
S
Samuel Ortiz 已提交
351 352 353 354 355
			     trigger);
	spin_unlock_irqrestore(&asic->lock, flags);
	return 0;
}

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
static int asic3_gpio_irq_set_wake(struct irq_data *data, unsigned int on)
{
	struct asic3 *asic = irq_data_get_irq_chip_data(data);
	u32 bank, index;
	u16 bit;

	bank = asic3_irq_to_bank(asic, data->irq);
	index = asic3_irq_to_index(asic, data->irq);
	bit = 1<<index;

	asic3_set_register(asic, bank + ASIC3_GPIO_SLEEP_MASK, bit, !on);

	return 0;
}

S
Samuel Ortiz 已提交
371 372
static struct irq_chip asic3_gpio_irq_chip = {
	.name		= "ASIC3-GPIO",
M
Mark Brown 已提交
373 374 375 376
	.irq_ack	= asic3_mask_gpio_irq,
	.irq_mask	= asic3_mask_gpio_irq,
	.irq_unmask	= asic3_unmask_gpio_irq,
	.irq_set_type	= asic3_gpio_irq_type,
377
	.irq_set_wake	= asic3_gpio_irq_set_wake,
S
Samuel Ortiz 已提交
378 379 380 381
};

static struct irq_chip asic3_irq_chip = {
	.name		= "ASIC3",
M
Mark Brown 已提交
382 383 384
	.irq_ack	= asic3_mask_irq,
	.irq_mask	= asic3_mask_irq,
	.irq_unmask	= asic3_unmask_irq,
S
Samuel Ortiz 已提交
385 386
};

387
static int __init asic3_irq_probe(struct platform_device *pdev)
S
Samuel Ortiz 已提交
388 389 390 391
{
	struct asic3 *asic = platform_get_drvdata(pdev);
	unsigned long clksel = 0;
	unsigned int irq, irq_base;
392
	int ret;
S
Samuel Ortiz 已提交
393

394 395 396 397
	ret = platform_get_irq(pdev, 0);
	if (ret < 0)
		return ret;
	asic->irq_nr = ret;
S
Samuel Ortiz 已提交
398 399 400 401 402 403 404 405 406 407

	/* turn on clock to IRQ controller */
	clksel |= CLOCK_SEL_CX;
	asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL),
			     clksel);

	irq_base = asic->irq_base;

	for (irq = irq_base; irq < irq_base + ASIC3_NR_IRQS; irq++) {
		if (irq < asic->irq_base + ASIC3_NUM_GPIOS)
T
Thomas Gleixner 已提交
408
			irq_set_chip(irq, &asic3_gpio_irq_chip);
S
Samuel Ortiz 已提交
409
		else
T
Thomas Gleixner 已提交
410
			irq_set_chip(irq, &asic3_irq_chip);
S
Samuel Ortiz 已提交
411

T
Thomas Gleixner 已提交
412 413
		irq_set_chip_data(irq, asic);
		irq_set_handler(irq, handle_level_irq);
S
Samuel Ortiz 已提交
414 415 416
		set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
	}

417
	asic3_write_register(asic, ASIC3_OFFSET(INTR, INT_MASK),
S
Samuel Ortiz 已提交
418 419
			     ASIC3_INTMASK_GINTMASK);

T
Thomas Gleixner 已提交
420 421 422
	irq_set_chained_handler(asic->irq_nr, asic3_irq_demux);
	irq_set_irq_type(asic->irq_nr, IRQ_TYPE_EDGE_RISING);
	irq_set_handler_data(asic->irq_nr, asic);
S
Samuel Ortiz 已提交
423 424 425 426 427 428 429 430 431 432 433 434 435

	return 0;
}

static void asic3_irq_remove(struct platform_device *pdev)
{
	struct asic3 *asic = platform_get_drvdata(pdev);
	unsigned int irq, irq_base;

	irq_base = asic->irq_base;

	for (irq = irq_base; irq < irq_base + ASIC3_NR_IRQS; irq++) {
		set_irq_flags(irq, 0);
436
		irq_set_chip_and_handler(irq, NULL, NULL);
T
Thomas Gleixner 已提交
437
		irq_set_chip_data(irq, NULL);
S
Samuel Ortiz 已提交
438
	}
T
Thomas Gleixner 已提交
439
	irq_set_chained_handler(asic->irq_nr, NULL);
S
Samuel Ortiz 已提交
440 441 442
}

/* GPIOs */
S
Samuel Ortiz 已提交
443 444 445 446 447 448 449 450 451 452 453
static int asic3_gpio_direction(struct gpio_chip *chip,
				unsigned offset, int out)
{
	u32 mask = ASIC3_GPIO_TO_MASK(offset), out_reg;
	unsigned int gpio_base;
	unsigned long flags;
	struct asic3 *asic;

	asic = container_of(chip, struct asic3, gpio);
	gpio_base = ASIC3_GPIO_TO_BASE(offset);

454
	if (gpio_base > ASIC3_GPIO_D_BASE) {
455 456
		dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
			gpio_base, offset);
S
Samuel Ortiz 已提交
457 458 459 460 461
		return -EINVAL;
	}

	spin_lock_irqsave(&asic->lock, flags);

462
	out_reg = asic3_read_register(asic, gpio_base + ASIC3_GPIO_DIRECTION);
S
Samuel Ortiz 已提交
463 464 465 466 467 468 469

	/* Input is 0, Output is 1 */
	if (out)
		out_reg |= mask;
	else
		out_reg &= ~mask;

470
	asic3_write_register(asic, gpio_base + ASIC3_GPIO_DIRECTION, out_reg);
S
Samuel Ortiz 已提交
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499

	spin_unlock_irqrestore(&asic->lock, flags);

	return 0;

}

static int asic3_gpio_direction_input(struct gpio_chip *chip,
				      unsigned offset)
{
	return asic3_gpio_direction(chip, offset, 0);
}

static int asic3_gpio_direction_output(struct gpio_chip *chip,
				       unsigned offset, int value)
{
	return asic3_gpio_direction(chip, offset, 1);
}

static int asic3_gpio_get(struct gpio_chip *chip,
			  unsigned offset)
{
	unsigned int gpio_base;
	u32 mask = ASIC3_GPIO_TO_MASK(offset);
	struct asic3 *asic;

	asic = container_of(chip, struct asic3, gpio);
	gpio_base = ASIC3_GPIO_TO_BASE(offset);

500
	if (gpio_base > ASIC3_GPIO_D_BASE) {
501 502
		dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
			gpio_base, offset);
S
Samuel Ortiz 已提交
503 504 505
		return -EINVAL;
	}

506
	return asic3_read_register(asic, gpio_base + ASIC3_GPIO_STATUS) & mask;
S
Samuel Ortiz 已提交
507 508 509 510 511 512 513 514 515 516 517 518 519
}

static void asic3_gpio_set(struct gpio_chip *chip,
			   unsigned offset, int value)
{
	u32 mask, out_reg;
	unsigned int gpio_base;
	unsigned long flags;
	struct asic3 *asic;

	asic = container_of(chip, struct asic3, gpio);
	gpio_base = ASIC3_GPIO_TO_BASE(offset);

520
	if (gpio_base > ASIC3_GPIO_D_BASE) {
521 522
		dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
			gpio_base, offset);
S
Samuel Ortiz 已提交
523 524 525 526 527 528 529
		return;
	}

	mask = ASIC3_GPIO_TO_MASK(offset);

	spin_lock_irqsave(&asic->lock, flags);

530
	out_reg = asic3_read_register(asic, gpio_base + ASIC3_GPIO_OUT);
S
Samuel Ortiz 已提交
531 532 533 534 535 536

	if (value)
		out_reg |= mask;
	else
		out_reg &= ~mask;

537
	asic3_write_register(asic, gpio_base + ASIC3_GPIO_OUT, out_reg);
S
Samuel Ortiz 已提交
538 539 540 541 542 543

	spin_unlock_irqrestore(&asic->lock, flags);

	return;
}

544 545
static int asic3_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
{
D
Dmitry Artamonow 已提交
546 547
	struct asic3 *asic = container_of(chip, struct asic3, gpio);

548
	return asic->irq_base + offset;
549 550
}

551 552
static __init int asic3_gpio_probe(struct platform_device *pdev,
				   u16 *gpio_config, int num)
S
Samuel Ortiz 已提交
553 554
{
	struct asic3 *asic = platform_get_drvdata(pdev);
555 556 557 558
	u16 alt_reg[ASIC3_NUM_GPIO_BANKS];
	u16 out_reg[ASIC3_NUM_GPIO_BANKS];
	u16 dir_reg[ASIC3_NUM_GPIO_BANKS];
	int i;
S
Samuel Ortiz 已提交
559

R
Russell King 已提交
560 561 562
	memset(alt_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
	memset(out_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
	memset(dir_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
563 564

	/* Enable all GPIOs */
565 566 567 568
	asic3_write_register(asic, ASIC3_GPIO_OFFSET(A, MASK), 0xffff);
	asic3_write_register(asic, ASIC3_GPIO_OFFSET(B, MASK), 0xffff);
	asic3_write_register(asic, ASIC3_GPIO_OFFSET(C, MASK), 0xffff);
	asic3_write_register(asic, ASIC3_GPIO_OFFSET(D, MASK), 0xffff);
S
Samuel Ortiz 已提交
569

570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
	for (i = 0; i < num; i++) {
		u8 alt, pin, dir, init, bank_num, bit_num;
		u16 config = gpio_config[i];

		pin = ASIC3_CONFIG_GPIO_PIN(config);
		alt = ASIC3_CONFIG_GPIO_ALT(config);
		dir = ASIC3_CONFIG_GPIO_DIR(config);
		init = ASIC3_CONFIG_GPIO_INIT(config);

		bank_num = ASIC3_GPIO_TO_BANK(pin);
		bit_num = ASIC3_GPIO_TO_BIT(pin);

		alt_reg[bank_num] |= (alt << bit_num);
		out_reg[bank_num] |= (init << bit_num);
		dir_reg[bank_num] |= (dir << bit_num);
	}

	for (i = 0; i < ASIC3_NUM_GPIO_BANKS; i++) {
		asic3_write_register(asic,
				     ASIC3_BANK_TO_BASE(i) +
590
				     ASIC3_GPIO_DIRECTION,
591 592
				     dir_reg[i]);
		asic3_write_register(asic,
593
				     ASIC3_BANK_TO_BASE(i) + ASIC3_GPIO_OUT,
594 595 596
				     out_reg[i]);
		asic3_write_register(asic,
				     ASIC3_BANK_TO_BASE(i) +
597
				     ASIC3_GPIO_ALT_FUNCTION,
598
				     alt_reg[i]);
S
Samuel Ortiz 已提交
599 600
	}

S
Samuel Ortiz 已提交
601
	return gpiochip_add(&asic->gpio);
S
Samuel Ortiz 已提交
602 603
}

S
Samuel Ortiz 已提交
604
static int asic3_gpio_remove(struct platform_device *pdev)
S
Samuel Ortiz 已提交
605
{
S
Samuel Ortiz 已提交
606 607 608
	struct asic3 *asic = platform_get_drvdata(pdev);

	return gpiochip_remove(&asic->gpio);
S
Samuel Ortiz 已提交
609 610
}

611
static void asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk)
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
{
	unsigned long flags;
	u32 cdex;

	spin_lock_irqsave(&asic->lock, flags);
	if (clk->enabled++ == 0) {
		cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX));
		cdex |= clk->cdex;
		asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex);
	}
	spin_unlock_irqrestore(&asic->lock, flags);
}

static void asic3_clk_disable(struct asic3 *asic, struct asic3_clk *clk)
{
	unsigned long flags;
	u32 cdex;

	WARN_ON(clk->enabled == 0);

	spin_lock_irqsave(&asic->lock, flags);
	if (--clk->enabled == 0) {
		cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX));
		cdex &= ~clk->cdex;
		asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex);
	}
	spin_unlock_irqrestore(&asic->lock, flags);
}
S
Samuel Ortiz 已提交
640

P
Philipp Zabel 已提交
641 642 643
/* MFD cells (SPI, PWM, LED, DS1WM, MMC) */
static struct ds1wm_driver_data ds1wm_pdata = {
	.active_high = 1,
644
	.reset_recover_delay = 1,
P
Philipp Zabel 已提交
645 646 647 648 649 650 651 652 653 654
};

static struct resource ds1wm_resources[] = {
	{
		.start = ASIC3_OWM_BASE,
		.end   = ASIC3_OWM_BASE + 0x13,
		.flags = IORESOURCE_MEM,
	},
	{
		.start = ASIC3_IRQ_OWM,
655
		.end   = ASIC3_IRQ_OWM,
P
Philipp Zabel 已提交
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
		.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
	},
};

static int ds1wm_enable(struct platform_device *pdev)
{
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	/* Turn on external clocks and the OWM clock */
	asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
	asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
	asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_OWM]);
	msleep(1);

	/* Reset and enable DS1WM */
	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, RESET),
			   ASIC3_EXTCF_OWM_RESET, 1);
	msleep(1);
	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, RESET),
			   ASIC3_EXTCF_OWM_RESET, 0);
	msleep(1);
	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
			   ASIC3_EXTCF_OWM_EN, 1);
	msleep(1);

	return 0;
}

static int ds1wm_disable(struct platform_device *pdev)
{
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
			   ASIC3_EXTCF_OWM_EN, 0);

	asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_OWM]);
	asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
	asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);

	return 0;
}

static struct mfd_cell asic3_cell_ds1wm = {
	.name          = "ds1wm",
	.enable        = ds1wm_enable,
	.disable       = ds1wm_disable,
702 703
	.platform_data = &ds1wm_pdata,
	.pdata_size    = sizeof(ds1wm_pdata),
P
Philipp Zabel 已提交
704 705 706 707
	.num_resources = ARRAY_SIZE(ds1wm_resources),
	.resources     = ds1wm_resources,
};

708 709 710 711 712 713 714 715 716 717 718 719 720 721
static void asic3_mmc_pwr(struct platform_device *pdev, int state)
{
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	tmio_core_mmc_pwr(asic->tmio_cnf, 1 - asic->bus_shift, state);
}

static void asic3_mmc_clk_div(struct platform_device *pdev, int state)
{
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	tmio_core_mmc_clk_div(asic->tmio_cnf, 1 - asic->bus_shift, state);
}

P
Philipp Zabel 已提交
722
static struct tmio_mmc_data asic3_mmc_data = {
723 724 725
	.hclk           = 24576000,
	.set_pwr        = asic3_mmc_pwr,
	.set_clk_div    = asic3_mmc_clk_div,
P
Philipp Zabel 已提交
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
};

static struct resource asic3_mmc_resources[] = {
	{
		.start = ASIC3_SD_CTRL_BASE,
		.end   = ASIC3_SD_CTRL_BASE + 0x3ff,
		.flags = IORESOURCE_MEM,
	},
	{
		.start = 0,
		.end   = 0,
		.flags = IORESOURCE_IRQ,
	},
};

static int asic3_mmc_enable(struct platform_device *pdev)
{
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	/* Not sure if it must be done bit by bit, but leaving as-is */
	asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
			   ASIC3_SDHWCTRL_LEVCD, 1);
	asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
			   ASIC3_SDHWCTRL_LEVWP, 1);
	asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
			   ASIC3_SDHWCTRL_SUSPEND, 0);
	asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
			   ASIC3_SDHWCTRL_PCLR, 0);

	asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
	/* CLK32 used for card detection and for interruption detection
	 * when HCLK is stopped.
	 */
	asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
	msleep(1);

	/* HCLK 24.576 MHz, BCLK 12.288 MHz: */
	asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL),
		CLOCK_SEL_CX | CLOCK_SEL_SD_HCLK_SEL);

	asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_SD_HOST]);
	asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_SD_BUS]);
	msleep(1);

	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
			   ASIC3_EXTCF_SD_MEM_ENABLE, 1);

	/* Enable SD card slot 3.3V power supply */
	asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
			   ASIC3_SDHWCTRL_SDPWR, 1);

777 778 779 780
	/* ASIC3_SD_CTRL_BASE assumes 32-bit addressing, TMIO is 16-bit */
	tmio_core_mmc_enable(asic->tmio_cnf, 1 - asic->bus_shift,
			     ASIC3_SD_CTRL_BASE >> 1);

P
Philipp Zabel 已提交
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
	return 0;
}

static int asic3_mmc_disable(struct platform_device *pdev)
{
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	/* Put in suspend mode */
	asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
			   ASIC3_SDHWCTRL_SUSPEND, 1);

	/* Disable clocks */
	asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_SD_HOST]);
	asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_SD_BUS]);
	asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
	asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
	return 0;
}

static struct mfd_cell asic3_cell_mmc = {
	.name          = "tmio-mmc",
	.enable        = asic3_mmc_enable,
	.disable       = asic3_mmc_disable,
804 805
	.suspend       = asic3_mmc_disable,
	.resume        = asic3_mmc_enable,
806 807
	.platform_data = &asic3_mmc_data,
	.pdata_size    = sizeof(asic3_mmc_data),
P
Philipp Zabel 已提交
808 809 810 811
	.num_resources = ARRAY_SIZE(asic3_mmc_resources),
	.resources     = asic3_mmc_resources,
};

P
Paul Parsons 已提交
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
static const int clock_ledn[ASIC3_NUM_LEDS] = {
	[0] = ASIC3_CLOCK_LED0,
	[1] = ASIC3_CLOCK_LED1,
	[2] = ASIC3_CLOCK_LED2,
};

static int asic3_leds_enable(struct platform_device *pdev)
{
	const struct mfd_cell *cell = mfd_get_cell(pdev);
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	asic3_clk_enable(asic, &asic->clocks[clock_ledn[cell->id]]);

	return 0;
}

static int asic3_leds_disable(struct platform_device *pdev)
{
	const struct mfd_cell *cell = mfd_get_cell(pdev);
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	asic3_clk_disable(asic, &asic->clocks[clock_ledn[cell->id]]);

	return 0;
}

838 839 840 841 842 843 844 845 846 847 848 849 850
static int asic3_leds_suspend(struct platform_device *pdev)
{
	const struct mfd_cell *cell = mfd_get_cell(pdev);
	struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);

	while (asic3_gpio_get(&asic->gpio, ASIC3_GPIO(C, cell->id)) != 0)
		msleep(1);

	asic3_clk_disable(asic, &asic->clocks[clock_ledn[cell->id]]);

	return 0;
}

P
Paul Parsons 已提交
851 852 853 854 855 856
static struct mfd_cell asic3_cell_leds[ASIC3_NUM_LEDS] = {
	[0] = {
		.name          = "leds-asic3",
		.id            = 0,
		.enable        = asic3_leds_enable,
		.disable       = asic3_leds_disable,
857 858
		.suspend       = asic3_leds_suspend,
		.resume        = asic3_leds_enable,
P
Paul Parsons 已提交
859 860 861 862 863 864
	},
	[1] = {
		.name          = "leds-asic3",
		.id            = 1,
		.enable        = asic3_leds_enable,
		.disable       = asic3_leds_disable,
865 866
		.suspend       = asic3_leds_suspend,
		.resume        = asic3_leds_enable,
P
Paul Parsons 已提交
867 868 869 870 871 872
	},
	[2] = {
		.name          = "leds-asic3",
		.id            = 2,
		.enable        = asic3_leds_enable,
		.disable       = asic3_leds_disable,
873 874
		.suspend       = asic3_leds_suspend,
		.resume        = asic3_leds_enable,
P
Paul Parsons 已提交
875 876 877
	},
};

P
Philipp Zabel 已提交
878
static int __init asic3_mfd_probe(struct platform_device *pdev,
P
Paul Parsons 已提交
879
				  struct asic3_platform_data *pdata,
P
Philipp Zabel 已提交
880 881 882
				  struct resource *mem)
{
	struct asic3 *asic = platform_get_drvdata(pdev);
P
Philipp Zabel 已提交
883 884 885 886 887 888 889 890 891 892
	struct resource *mem_sdio;
	int irq, ret;

	mem_sdio = platform_get_resource(pdev, IORESOURCE_MEM, 1);
	if (!mem_sdio)
		dev_dbg(asic->dev, "no SDIO MEM resource\n");

	irq = platform_get_irq(pdev, 1);
	if (irq < 0)
		dev_dbg(asic->dev, "no SDIO IRQ resource\n");
P
Philipp Zabel 已提交
893 894 895 896 897 898 899 900

	/* DS1WM */
	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
			   ASIC3_EXTCF_OWM_SMB, 0);

	ds1wm_resources[0].start >>= asic->bus_shift;
	ds1wm_resources[0].end   >>= asic->bus_shift;

P
Philipp Zabel 已提交
901
	/* MMC */
902
	asic->tmio_cnf = ioremap((ASIC3_SD_CONFIG_BASE >> asic->bus_shift) +
903 904
				 mem_sdio->start,
				 ASIC3_SD_CONFIG_SIZE >> asic->bus_shift);
905 906 907 908 909
	if (!asic->tmio_cnf) {
		ret = -ENOMEM;
		dev_dbg(asic->dev, "Couldn't ioremap SD_CONFIG\n");
		goto out;
	}
P
Philipp Zabel 已提交
910 911 912
	asic3_mmc_resources[0].start >>= asic->bus_shift;
	asic3_mmc_resources[0].end   >>= asic->bus_shift;

P
Paul Parsons 已提交
913 914 915
	if (pdata->clock_rate) {
		ds1wm_pdata.clock_rate = pdata->clock_rate;
		ret = mfd_add_devices(&pdev->dev, pdev->id,
916
			&asic3_cell_ds1wm, 1, mem, asic->irq_base, NULL);
P
Paul Parsons 已提交
917 918 919
		if (ret < 0)
			goto out;
	}
P
Philipp Zabel 已提交
920

P
Paul Parsons 已提交
921
	if (mem_sdio && (irq >= 0)) {
P
Philipp Zabel 已提交
922
		ret = mfd_add_devices(&pdev->dev, pdev->id,
923
			&asic3_cell_mmc, 1, mem_sdio, irq, NULL);
P
Paul Parsons 已提交
924 925 926 927
		if (ret < 0)
			goto out;
	}

928
	ret = 0;
P
Paul Parsons 已提交
929 930 931 932 933 934 935 936
	if (pdata->leds) {
		int i;

		for (i = 0; i < ASIC3_NUM_LEDS; ++i) {
			asic3_cell_leds[i].platform_data = &pdata->leds[i];
			asic3_cell_leds[i].pdata_size = sizeof(pdata->leds[i]);
		}
		ret = mfd_add_devices(&pdev->dev, 0,
937
			asic3_cell_leds, ASIC3_NUM_LEDS, NULL, 0, NULL);
P
Paul Parsons 已提交
938
	}
P
Philipp Zabel 已提交
939

P
Philipp Zabel 已提交
940
 out:
P
Philipp Zabel 已提交
941 942 943 944 945
	return ret;
}

static void asic3_mfd_remove(struct platform_device *pdev)
{
946 947
	struct asic3 *asic = platform_get_drvdata(pdev);

P
Philipp Zabel 已提交
948
	mfd_remove_devices(&pdev->dev);
949
	iounmap(asic->tmio_cnf);
P
Philipp Zabel 已提交
950 951
}

S
Samuel Ortiz 已提交
952
/* Core */
953
static int __init asic3_probe(struct platform_device *pdev)
S
Samuel Ortiz 已提交
954
{
J
Jingoo Han 已提交
955
	struct asic3_platform_data *pdata = dev_get_platdata(&pdev->dev);
S
Samuel Ortiz 已提交
956 957 958
	struct asic3 *asic;
	struct resource *mem;
	unsigned long clksel;
S
Samuel Ortiz 已提交
959
	int ret = 0;
S
Samuel Ortiz 已提交
960

961 962
	asic = devm_kzalloc(&pdev->dev,
			    sizeof(struct asic3), GFP_KERNEL);
S
Samuel Ortiz 已提交
963 964
	if (asic == NULL) {
		printk(KERN_ERR "kzalloc failed\n");
S
Samuel Ortiz 已提交
965
		return -ENOMEM;
S
Samuel Ortiz 已提交
966
	}
S
Samuel Ortiz 已提交
967 968 969 970 971 972 973

	spin_lock_init(&asic->lock);
	platform_set_drvdata(pdev, asic);
	asic->dev = &pdev->dev;

	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!mem) {
974
		dev_err(asic->dev, "no MEM resource\n");
975
		return -ENOMEM;
S
Samuel Ortiz 已提交
976 977
	}

978
	asic->mapping = ioremap(mem->start, resource_size(mem));
S
Samuel Ortiz 已提交
979
	if (!asic->mapping) {
980
		dev_err(asic->dev, "Couldn't ioremap\n");
981
		return -ENOMEM;
S
Samuel Ortiz 已提交
982 983 984 985
	}

	asic->irq_base = pdata->irq_base;

986
	/* calculate bus shift from mem resource */
987
	asic->bus_shift = 2 - (resource_size(mem) >> 12);
S
Samuel Ortiz 已提交
988 989 990 991 992 993

	clksel = 0;
	asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL), clksel);

	ret = asic3_irq_probe(pdev);
	if (ret < 0) {
994
		dev_err(asic->dev, "Couldn't probe IRQs\n");
S
Samuel Ortiz 已提交
995 996 997
		goto out_unmap;
	}

P
Paul Parsons 已提交
998
	asic->gpio.label = "asic3";
S
Samuel Ortiz 已提交
999 1000 1001 1002 1003 1004
	asic->gpio.base = pdata->gpio_base;
	asic->gpio.ngpio = ASIC3_NUM_GPIOS;
	asic->gpio.get = asic3_gpio_get;
	asic->gpio.set = asic3_gpio_set;
	asic->gpio.direction_input = asic3_gpio_direction_input;
	asic->gpio.direction_output = asic3_gpio_direction_output;
1005
	asic->gpio.to_irq = asic3_gpio_to_irq;
S
Samuel Ortiz 已提交
1006

1007 1008 1009
	ret = asic3_gpio_probe(pdev,
			       pdata->gpio_config,
			       pdata->gpio_config_num);
S
Samuel Ortiz 已提交
1010
	if (ret < 0) {
1011
		dev_err(asic->dev, "GPIO probe failed\n");
S
Samuel Ortiz 已提交
1012
		goto out_irq;
S
Samuel Ortiz 已提交
1013 1014
	}

1015 1016 1017 1018 1019
	/* Making a per-device copy is only needed for the
	 * theoretical case of multiple ASIC3s on one board:
	 */
	memcpy(asic->clocks, asic3_clk_init, sizeof(asic3_clk_init));

P
Paul Parsons 已提交
1020
	asic3_mfd_probe(pdev, pdata, mem);
P
Philipp Zabel 已提交
1021

1022 1023 1024
	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
		(ASIC3_EXTCF_CF0_BUF_EN|ASIC3_EXTCF_CF0_PWAIT_EN), 1);

1025
	dev_info(asic->dev, "ASIC3 Core driver\n");
S
Samuel Ortiz 已提交
1026 1027 1028

	return 0;

S
Samuel Ortiz 已提交
1029 1030 1031 1032
 out_irq:
	asic3_irq_remove(pdev);

 out_unmap:
S
Samuel Ortiz 已提交
1033
	iounmap(asic->mapping);
S
Samuel Ortiz 已提交
1034

S
Samuel Ortiz 已提交
1035 1036 1037
	return ret;
}

B
Bill Pemberton 已提交
1038
static int asic3_remove(struct platform_device *pdev)
S
Samuel Ortiz 已提交
1039
{
S
Samuel Ortiz 已提交
1040
	int ret;
S
Samuel Ortiz 已提交
1041 1042
	struct asic3 *asic = platform_get_drvdata(pdev);

1043 1044 1045
	asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
		(ASIC3_EXTCF_CF0_BUF_EN|ASIC3_EXTCF_CF0_PWAIT_EN), 0);

P
Philipp Zabel 已提交
1046 1047
	asic3_mfd_remove(pdev);

S
Samuel Ortiz 已提交
1048 1049 1050
	ret = asic3_gpio_remove(pdev);
	if (ret < 0)
		return ret;
S
Samuel Ortiz 已提交
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
	asic3_irq_remove(pdev);

	asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL), 0);

	iounmap(asic->mapping);

	return 0;
}

static void asic3_shutdown(struct platform_device *pdev)
{
}

static struct platform_driver asic3_device_driver = {
	.driver		= {
		.name	= "asic3",
	},
B
Bill Pemberton 已提交
1068
	.remove		= asic3_remove,
S
Samuel Ortiz 已提交
1069 1070 1071 1072 1073 1074
	.shutdown	= asic3_shutdown,
};

static int __init asic3_init(void)
{
	int retval = 0;
1075
	retval = platform_driver_probe(&asic3_device_driver, asic3_probe);
S
Samuel Ortiz 已提交
1076 1077 1078 1079
	return retval;
}

subsys_initcall(asic3_init);