ab8500-core.c 44.8 KB
Newer Older
R
Rabin Vincent 已提交
1 2 3 4 5 6
/*
 * Copyright (C) ST-Ericsson SA 2010
 *
 * License Terms: GNU General Public License v2
 * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
 * Author: Rabin Vincent <rabin.vincent@stericsson.com>
7
 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
R
Rabin Vincent 已提交
8 9 10 11 12 13
 */

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/irq.h>
14
#include <linux/irqdomain.h>
R
Rabin Vincent 已提交
15 16 17 18 19
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/mfd/core.h>
20
#include <linux/mfd/abx500.h>
21
#include <linux/mfd/abx500/ab8500.h>
22
#include <linux/mfd/abx500/ab8500-bm.h>
23
#include <linux/mfd/dbx500-prcmu.h>
24
#include <linux/regulator/ab8500.h>
25 26
#include <linux/of.h>
#include <linux/of_device.h>
R
Rabin Vincent 已提交
27 28 29 30 31

/*
 * Interrupt register offsets
 * Bank : 0x0E
 */
32 33 34 35 36 37 38 39
#define AB8500_IT_SOURCE1_REG		0x00
#define AB8500_IT_SOURCE2_REG		0x01
#define AB8500_IT_SOURCE3_REG		0x02
#define AB8500_IT_SOURCE4_REG		0x03
#define AB8500_IT_SOURCE5_REG		0x04
#define AB8500_IT_SOURCE6_REG		0x05
#define AB8500_IT_SOURCE7_REG		0x06
#define AB8500_IT_SOURCE8_REG		0x07
40
#define AB9540_IT_SOURCE13_REG		0x0C
41 42 43 44 45 46
#define AB8500_IT_SOURCE19_REG		0x12
#define AB8500_IT_SOURCE20_REG		0x13
#define AB8500_IT_SOURCE21_REG		0x14
#define AB8500_IT_SOURCE22_REG		0x15
#define AB8500_IT_SOURCE23_REG		0x16
#define AB8500_IT_SOURCE24_REG		0x17
R
Rabin Vincent 已提交
47 48 49 50

/*
 * latch registers
 */
51 52 53 54 55 56 57 58 59 60
#define AB8500_IT_LATCH1_REG		0x20
#define AB8500_IT_LATCH2_REG		0x21
#define AB8500_IT_LATCH3_REG		0x22
#define AB8500_IT_LATCH4_REG		0x23
#define AB8500_IT_LATCH5_REG		0x24
#define AB8500_IT_LATCH6_REG		0x25
#define AB8500_IT_LATCH7_REG		0x26
#define AB8500_IT_LATCH8_REG		0x27
#define AB8500_IT_LATCH9_REG		0x28
#define AB8500_IT_LATCH10_REG		0x29
61
#define AB8500_IT_LATCH12_REG		0x2B
62
#define AB9540_IT_LATCH13_REG		0x2C
63 64 65 66 67 68
#define AB8500_IT_LATCH19_REG		0x32
#define AB8500_IT_LATCH20_REG		0x33
#define AB8500_IT_LATCH21_REG		0x34
#define AB8500_IT_LATCH22_REG		0x35
#define AB8500_IT_LATCH23_REG		0x36
#define AB8500_IT_LATCH24_REG		0x37
R
Rabin Vincent 已提交
69 70 71 72 73

/*
 * mask registers
 */

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
#define AB8500_IT_MASK1_REG		0x40
#define AB8500_IT_MASK2_REG		0x41
#define AB8500_IT_MASK3_REG		0x42
#define AB8500_IT_MASK4_REG		0x43
#define AB8500_IT_MASK5_REG		0x44
#define AB8500_IT_MASK6_REG		0x45
#define AB8500_IT_MASK7_REG		0x46
#define AB8500_IT_MASK8_REG		0x47
#define AB8500_IT_MASK9_REG		0x48
#define AB8500_IT_MASK10_REG		0x49
#define AB8500_IT_MASK11_REG		0x4A
#define AB8500_IT_MASK12_REG		0x4B
#define AB8500_IT_MASK13_REG		0x4C
#define AB8500_IT_MASK14_REG		0x4D
#define AB8500_IT_MASK15_REG		0x4E
#define AB8500_IT_MASK16_REG		0x4F
#define AB8500_IT_MASK17_REG		0x50
#define AB8500_IT_MASK18_REG		0x51
#define AB8500_IT_MASK19_REG		0x52
#define AB8500_IT_MASK20_REG		0x53
#define AB8500_IT_MASK21_REG		0x54
#define AB8500_IT_MASK22_REG		0x55
#define AB8500_IT_MASK23_REG		0x56
#define AB8500_IT_MASK24_REG		0x57
98
#define AB8500_IT_MASK25_REG		0x58
99

100 101 102 103 104 105
/*
 * latch hierarchy registers
 */
#define AB8500_IT_LATCHHIER1_REG	0x60
#define AB8500_IT_LATCHHIER2_REG	0x61
#define AB8500_IT_LATCHHIER3_REG	0x62
106
#define AB8540_IT_LATCHHIER4_REG	0x63
107 108

#define AB8500_IT_LATCHHIER_NUM		3
109
#define AB8540_IT_LATCHHIER_NUM		4
110

111
#define AB8500_REV_REG			0x80
112
#define AB8500_IC_NAME_REG		0x82
113
#define AB8500_SWITCH_OFF_STATUS	0x00
R
Rabin Vincent 已提交
114

115
#define AB8500_TURN_ON_STATUS		0x00
116
#define AB8505_TURN_ON_STATUS_2	0x04
117

118 119 120 121 122 123 124
#define AB8500_CH_USBCH_STAT1_REG	0x02
#define VBUS_DET_DBNC100		0x02
#define VBUS_DET_DBNC1			0x01

static DEFINE_SPINLOCK(on_stat_lock);
static u8 turn_on_stat_mask = 0xFF;
static u8 turn_on_stat_set;
125 126 127
static bool no_bm; /* No battery management */
module_param(no_bm, bool, S_IRUGO);

128 129 130
#define AB9540_MODEM_CTRL2_REG			0x23
#define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT	BIT(2)

R
Rabin Vincent 已提交
131 132
/*
 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
133 134
 * numbers are indexed into this array with (num / 8). The interupts are
 * defined in linux/mfd/ab8500.h
R
Rabin Vincent 已提交
135 136 137 138
 *
 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
 * offset 0.
 */
139
/* AB8500 support */
R
Rabin Vincent 已提交
140
static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
141
	0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
R
Rabin Vincent 已提交
142 143
};

144
/* AB9540 / AB8505 support */
145
static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
146
	0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22, 23
147 148
};

149 150 151 152 153 154
/* AB8540 support */
static const int ab8540_irq_regoffset[AB8540_NUM_IRQ_REGS] = {
	0, 1, 2, 3, 4, -1, -1, -1, -1, 11, 18, 19, 20, 21, 12, 13, 24, 5, 22, 23,
	25, 26, 27, 28, 29, 30, 31,
};

155 156 157 158 159 160 161
static const char ab8500_version_str[][7] = {
	[AB8500_VERSION_AB8500] = "AB8500",
	[AB8500_VERSION_AB8505] = "AB8505",
	[AB8500_VERSION_AB9540] = "AB9540",
	[AB8500_VERSION_AB8540] = "AB8540",
};

162
static int ab8500_prcmu_write(struct ab8500 *ab8500, u16 addr, u8 data)
163 164 165 166 167 168 169 170 171
{
	int ret;

	ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
	if (ret < 0)
		dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
	return ret;
}

172
static int ab8500_prcmu_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask,
173 174 175 176 177 178 179 180 181 182 183
	u8 data)
{
	int ret;

	ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data,
		&mask, 1);
	if (ret < 0)
		dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
	return ret;
}

184
static int ab8500_prcmu_read(struct ab8500 *ab8500, u16 addr)
185 186 187 188 189 190 191 192 193 194 195 196
{
	int ret;
	u8 data;

	ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
	if (ret < 0) {
		dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
		return ret;
	}
	return (int)data;
}

197 198
static int ab8500_get_chip_id(struct device *dev)
{
199 200 201 202 203 204
	struct ab8500 *ab8500;

	if (!dev)
		return -EINVAL;
	ab8500 = dev_get_drvdata(dev->parent);
	return ab8500 ? (int)ab8500->chip_id : -EINVAL;
205 206 207 208
}

static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
	u8 reg, u8 data)
R
Rabin Vincent 已提交
209 210
{
	int ret;
211 212 213 214 215
	/*
	 * Put the u8 bank and u8 register together into a an u16.
	 * The bank on higher 8 bits and register in lower 8 bits.
	 * */
	u16 addr = ((u16)bank) << 8 | reg;
R
Rabin Vincent 已提交
216 217 218

	dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);

219
	mutex_lock(&ab8500->lock);
220

R
Rabin Vincent 已提交
221 222 223 224
	ret = ab8500->write(ab8500, addr, data);
	if (ret < 0)
		dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
			addr, ret);
225
	mutex_unlock(&ab8500->lock);
R
Rabin Vincent 已提交
226 227 228 229

	return ret;
}

230 231
static int ab8500_set_register(struct device *dev, u8 bank,
	u8 reg, u8 value)
R
Rabin Vincent 已提交
232
{
233
	int ret;
234
	struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
R
Rabin Vincent 已提交
235

236 237 238 239
	atomic_inc(&ab8500->transfer_ongoing);
	ret = set_register_interruptible(ab8500, bank, reg, value);
	atomic_dec(&ab8500->transfer_ongoing);
	return ret;
R
Rabin Vincent 已提交
240 241
}

242 243
static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
	u8 reg, u8 *value)
R
Rabin Vincent 已提交
244 245
{
	int ret;
246 247 248 249
	/* put the u8 bank and u8 reg together into a an u16.
	 * bank on higher 8 bits and reg in lower */
	u16 addr = ((u16)bank) << 8 | reg;

250
	mutex_lock(&ab8500->lock);
R
Rabin Vincent 已提交
251 252 253 254 255

	ret = ab8500->read(ab8500, addr);
	if (ret < 0)
		dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
			addr, ret);
256 257
	else
		*value = ret;
R
Rabin Vincent 已提交
258

259
	mutex_unlock(&ab8500->lock);
R
Rabin Vincent 已提交
260 261 262 263 264
	dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);

	return ret;
}

265 266
static int ab8500_get_register(struct device *dev, u8 bank,
	u8 reg, u8 *value)
R
Rabin Vincent 已提交
267
{
268
	int ret;
269
	struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
R
Rabin Vincent 已提交
270

271 272 273 274
	atomic_inc(&ab8500->transfer_ongoing);
	ret = get_register_interruptible(ab8500, bank, reg, value);
	atomic_dec(&ab8500->transfer_ongoing);
	return ret;
R
Rabin Vincent 已提交
275
}
276 277 278

static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
	u8 reg, u8 bitmask, u8 bitvalues)
R
Rabin Vincent 已提交
279 280
{
	int ret;
281 282 283
	/* put the u8 bank and u8 reg together into a an u16.
	 * bank on higher 8 bits and reg in lower */
	u16 addr = ((u16)bank) << 8 | reg;
R
Rabin Vincent 已提交
284

285
	mutex_lock(&ab8500->lock);
R
Rabin Vincent 已提交
286

287 288
	if (ab8500->write_masked == NULL) {
		u8 data;
R
Rabin Vincent 已提交
289

290 291 292 293 294 295
		ret = ab8500->read(ab8500, addr);
		if (ret < 0) {
			dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
				addr, ret);
			goto out;
		}
R
Rabin Vincent 已提交
296

297 298 299 300 301 302 303
		data = (u8)ret;
		data = (~bitmask & data) | (bitmask & bitvalues);

		ret = ab8500->write(ab8500, addr, data);
		if (ret < 0)
			dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
				addr, ret);
R
Rabin Vincent 已提交
304

305 306 307 308 309 310 311 312
		dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr,
			data);
		goto out;
	}
	ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues);
	if (ret < 0)
		dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr,
			ret);
R
Rabin Vincent 已提交
313 314 315 316
out:
	mutex_unlock(&ab8500->lock);
	return ret;
}
317 318 319 320

static int ab8500_mask_and_set_register(struct device *dev,
	u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
{
321
	int ret;
322 323
	struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);

324 325 326 327 328
	atomic_inc(&ab8500->transfer_ongoing);
	ret= mask_and_set_register_interruptible(ab8500, bank, reg,
						 bitmask, bitvalues);
	atomic_dec(&ab8500->transfer_ongoing);
	return ret;
329 330 331 332 333 334 335 336 337 338 339
}

static struct abx500_ops ab8500_ops = {
	.get_chip_id = ab8500_get_chip_id,
	.get_register = ab8500_get_register,
	.set_register = ab8500_set_register,
	.get_register_page = NULL,
	.set_register_page = NULL,
	.mask_and_set_register = ab8500_mask_and_set_register,
	.event_registers_startup_state_get = NULL,
	.startup_irq_enabled = NULL,
340
	.dump_all_banks = ab8500_dump_all_banks,
341
};
R
Rabin Vincent 已提交
342

343
static void ab8500_irq_lock(struct irq_data *data)
R
Rabin Vincent 已提交
344
{
345
	struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
R
Rabin Vincent 已提交
346 347

	mutex_lock(&ab8500->irq_lock);
348
	atomic_inc(&ab8500->transfer_ongoing);
R
Rabin Vincent 已提交
349 350
}

351
static void ab8500_irq_sync_unlock(struct irq_data *data)
R
Rabin Vincent 已提交
352
{
353
	struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
R
Rabin Vincent 已提交
354 355
	int i;

356
	for (i = 0; i < ab8500->mask_size; i++) {
R
Rabin Vincent 已提交
357 358 359 360 361 362 363
		u8 old = ab8500->oldmask[i];
		u8 new = ab8500->mask[i];
		int reg;

		if (new == old)
			continue;

364 365 366 367 368 369
		/*
		 * Interrupt register 12 doesn't exist prior to AB8500 version
		 * 2.0
		 */
		if (ab8500->irq_reg_offset[i] == 11 &&
			is_ab8500_1p1_or_earlier(ab8500))
370 371
			continue;

372 373 374
		if (ab8500->irq_reg_offset[i] < 0)
			continue;

R
Rabin Vincent 已提交
375 376
		ab8500->oldmask[i] = new;

377
		reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
378
		set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
R
Rabin Vincent 已提交
379
	}
380
	atomic_dec(&ab8500->transfer_ongoing);
R
Rabin Vincent 已提交
381 382 383
	mutex_unlock(&ab8500->irq_lock);
}

384
static void ab8500_irq_mask(struct irq_data *data)
R
Rabin Vincent 已提交
385
{
386
	struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
387
	int offset = data->hwirq;
R
Rabin Vincent 已提交
388 389 390 391
	int index = offset / 8;
	int mask = 1 << (offset % 8);

	ab8500->mask[index] |= mask;
392 393 394 395 396 397 398

	/* The AB8500 GPIOs have two interrupts each (rising & falling). */
	if (offset >= AB8500_INT_GPIO6R && offset <= AB8500_INT_GPIO41R)
		ab8500->mask[index + 2] |= mask;
	if (offset >= AB9540_INT_GPIO50R && offset <= AB9540_INT_GPIO54R)
		ab8500->mask[index + 1] |= mask;
	if (offset == AB8540_INT_GPIO43R || offset == AB8540_INT_GPIO44R)
399 400
		/* Here the falling IRQ is one bit lower */
		ab8500->mask[index] |= (mask << 1);
R
Rabin Vincent 已提交
401 402
}

403
static void ab8500_irq_unmask(struct irq_data *data)
R
Rabin Vincent 已提交
404
{
405
	struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
406
	unsigned int type = irqd_get_trigger_type(data);
407
	int offset = data->hwirq;
R
Rabin Vincent 已提交
408 409 410
	int index = offset / 8;
	int mask = 1 << (offset % 8);

411 412 413 414 415 416 417 418 419 420
	if (type & IRQ_TYPE_EDGE_RISING)
		ab8500->mask[index] &= ~mask;

	/* The AB8500 GPIOs have two interrupts each (rising & falling). */
	if (type & IRQ_TYPE_EDGE_FALLING) {
		if (offset >= AB8500_INT_GPIO6R && offset <= AB8500_INT_GPIO41R)
			ab8500->mask[index + 2] &= ~mask;
		else if (offset >= AB9540_INT_GPIO50R && offset <= AB9540_INT_GPIO54R)
			ab8500->mask[index + 1] &= ~mask;
		else if (offset == AB8540_INT_GPIO43R || offset == AB8540_INT_GPIO44R)
421 422
			/* Here the falling IRQ is one bit lower */
			ab8500->mask[index] &= ~(mask << 1);
423 424
		else
			ab8500->mask[index] &= ~mask;
425
	} else {
426 427
		/* Satisfies the case where type is not set. */
		ab8500->mask[index] &= ~mask;
428
	}
R
Rabin Vincent 已提交
429 430
}

431 432 433
static int ab8500_irq_set_type(struct irq_data *data, unsigned int type)
{
	return 0;
R
Rabin Vincent 已提交
434 435 436 437
}

static struct irq_chip ab8500_irq_chip = {
	.name			= "ab8500",
438 439 440
	.irq_bus_lock		= ab8500_irq_lock,
	.irq_bus_sync_unlock	= ab8500_irq_sync_unlock,
	.irq_mask		= ab8500_irq_mask,
441
	.irq_disable		= ab8500_irq_mask,
442
	.irq_unmask		= ab8500_irq_unmask,
443
	.irq_set_type		= ab8500_irq_set_type,
R
Rabin Vincent 已提交
444 445
};

446 447 448 449 450 451 452 453 454 455 456 457
static void update_latch_offset(u8 *offset, int i)
{
	/* Fix inconsistent ITFromLatch25 bit mapping... */
	if (unlikely(*offset == 17))
			*offset = 24;
	/* Fix inconsistent ab8540 bit mapping... */
	if (unlikely(*offset == 16))
			*offset = 25;
	if ((i==3) && (*offset >= 24))
			*offset += 2;
}

458 459 460
static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
					int latch_offset, u8 latch_val)
{
461
	int int_bit, line, i;
462

463 464 465
	for (i = 0; i < ab8500->mask_size; i++)
		if (ab8500->irq_reg_offset[i] == latch_offset)
			break;
466

467 468 469 470 471
	if (i >= ab8500->mask_size) {
		dev_err(ab8500->dev, "Register offset 0x%2x not declared\n",
				latch_offset);
		return -ENXIO;
	}
472

473 474
	/* ignore masked out interrupts */
	latch_val &= ~ab8500->mask[i];
475

476 477
	while (latch_val) {
		int_bit = __ffs(latch_val);
478 479 480
		line = (i << 3) + int_bit;
		latch_val &= ~(1 << int_bit);

481 482 483 484 485 486 487 488 489 490 491 492 493
		/*
		 * This handles the falling edge hwirqs from the GPIO
		 * lines. Route them back to the line registered for the
		 * rising IRQ, as this is merely a flag for the same IRQ
		 * in linux terms.
		 */
		if (line >= AB8500_INT_GPIO6F && line <= AB8500_INT_GPIO41F)
			line -= 16;
		if (line >= AB9540_INT_GPIO50F && line <= AB9540_INT_GPIO54F)
			line -= 8;
		if (line == AB8540_INT_GPIO43F || line == AB8540_INT_GPIO44F)
			line += 1;

494
		handle_nested_irq(ab8500->irq_base + line);
495
	}
496 497 498 499 500 501 502 503 504 505 506 507 508 509

	return 0;
}

static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
					int hier_offset, u8 hier_val)
{
	int latch_bit, status;
	u8 latch_offset, latch_val;

	do {
		latch_bit = __ffs(hier_val);
		latch_offset = (hier_offset << 3) + latch_bit;

510
		update_latch_offset(&latch_offset, hier_offset);
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537

		status = get_register_interruptible(ab8500,
				AB8500_INTERRUPT,
				AB8500_IT_LATCH1_REG + latch_offset,
				&latch_val);
		if (status < 0 || latch_val == 0)
			goto discard;

		status = ab8500_handle_hierarchical_line(ab8500,
				latch_offset, latch_val);
		if (status < 0)
			return status;
discard:
		hier_val &= ~(1 << latch_bit);
	} while (hier_val);

	return 0;
}

static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
{
	struct ab8500 *ab8500 = dev;
	u8 i;

	dev_vdbg(ab8500->dev, "interrupt\n");

	/*  Hierarchical interrupt version */
538
	for (i = 0; i < (ab8500->it_latchhier_num); i++) {
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
		int status;
		u8 hier_val;

		status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
			AB8500_IT_LATCHHIER1_REG + i, &hier_val);
		if (status < 0 || hier_val == 0)
			continue;

		status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val);
		if (status < 0)
			break;
	}
	return IRQ_HANDLED;
}

554 555 556 557 558 559 560 561 562 563 564 565
static int ab8500_irq_map(struct irq_domain *d, unsigned int virq,
				irq_hw_number_t hwirq)
{
	struct ab8500 *ab8500 = d->host_data;

	if (!ab8500)
		return -EINVAL;

	irq_set_chip_data(virq, ab8500);
	irq_set_chip_and_handler(virq, &ab8500_irq_chip,
				handle_simple_irq);
	irq_set_nested_thread(virq, 1);
R
Rabin Vincent 已提交
566
#ifdef CONFIG_ARM
567
	set_irq_flags(virq, IRQF_VALID);
R
Rabin Vincent 已提交
568
#else
569
	irq_set_noprobe(virq);
R
Rabin Vincent 已提交
570 571 572 573 574
#endif

	return 0;
}

575 576 577 578 579 580
static struct irq_domain_ops ab8500_irq_ops = {
        .map    = ab8500_irq_map,
        .xlate  = irq_domain_xlate_twocell,
};

static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np)
R
Rabin Vincent 已提交
581
{
582 583
	int num_irqs;

584 585 586
	if (is_ab8540(ab8500))
		num_irqs = AB8540_NR_IRQS;
	else if (is_ab9540(ab8500))
587
		num_irqs = AB9540_NR_IRQS;
588 589
	else if (is_ab8505(ab8500))
		num_irqs = AB8505_NR_IRQS;
590 591
	else
		num_irqs = AB8500_NR_IRQS;
R
Rabin Vincent 已提交
592

593 594 595 596
	/* If ->irq_base is zero this will give a linear mapping */
	ab8500->domain = irq_domain_add_simple(NULL,
			num_irqs, ab8500->irq_base,
			&ab8500_irq_ops, ab8500);
597 598 599 600 601 602 603

	if (!ab8500->domain) {
		dev_err(ab8500->dev, "Failed to create irqdomain\n");
		return -ENOSYS;
	}

	return 0;
R
Rabin Vincent 已提交
604 605
}

606 607 608 609 610 611 612 613
int ab8500_suspend(struct ab8500 *ab8500)
{
	if (atomic_read(&ab8500->transfer_ongoing))
		return -EINVAL;
	else
		return 0;
}

B
Bill Pemberton 已提交
614
static struct resource ab8500_gpadc_resources[] = {
R
Rabin Vincent 已提交
615 616 617 618 619 620 621 622 623 624 625 626 627 628
	{
		.name	= "HW_CONV_END",
		.start	= AB8500_INT_GP_HW_ADC_CONV_END,
		.end	= AB8500_INT_GP_HW_ADC_CONV_END,
		.flags	= IORESOURCE_IRQ,
	},
	{
		.name	= "SW_CONV_END",
		.start	= AB8500_INT_GP_SW_ADC_CONV_END,
		.end	= AB8500_INT_GP_SW_ADC_CONV_END,
		.flags	= IORESOURCE_IRQ,
	},
};

629
static struct resource ab8505_gpadc_resources[] = {
630 631 632 633 634 635 636 637
	{
		.name	= "SW_CONV_END",
		.start	= AB8500_INT_GP_SW_ADC_CONV_END,
		.end	= AB8500_INT_GP_SW_ADC_CONV_END,
		.flags	= IORESOURCE_IRQ,
	},
};

B
Bill Pemberton 已提交
638
static struct resource ab8500_rtc_resources[] = {
R
Rabin Vincent 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652
	{
		.name	= "60S",
		.start	= AB8500_INT_RTC_60S,
		.end	= AB8500_INT_RTC_60S,
		.flags	= IORESOURCE_IRQ,
	},
	{
		.name	= "ALARM",
		.start	= AB8500_INT_RTC_ALARM,
		.end	= AB8500_INT_RTC_ALARM,
		.flags	= IORESOURCE_IRQ,
	},
};

653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
static struct resource ab8540_rtc_resources[] = {
	{
		.name	= "1S",
		.start	= AB8540_INT_RTC_1S,
		.end	= AB8540_INT_RTC_1S,
		.flags	= IORESOURCE_IRQ,
	},
	{
		.name	= "ALARM",
		.start	= AB8500_INT_RTC_ALARM,
		.end	= AB8500_INT_RTC_ALARM,
		.flags	= IORESOURCE_IRQ,
	},
};

B
Bill Pemberton 已提交
668
static struct resource ab8500_poweronkey_db_resources[] = {
669 670 671 672 673 674 675 676 677 678 679 680 681 682
	{
		.name	= "ONKEY_DBF",
		.start	= AB8500_INT_PON_KEY1DB_F,
		.end	= AB8500_INT_PON_KEY1DB_F,
		.flags	= IORESOURCE_IRQ,
	},
	{
		.name	= "ONKEY_DBR",
		.start	= AB8500_INT_PON_KEY1DB_R,
		.end	= AB8500_INT_PON_KEY1DB_R,
		.flags	= IORESOURCE_IRQ,
	},
};

B
Bill Pemberton 已提交
683
static struct resource ab8500_av_acc_detect_resources[] = {
684
	{
685 686 687 688
	       .name = "ACC_DETECT_1DB_F",
	       .start = AB8500_INT_ACC_DETECT_1DB_F,
	       .end = AB8500_INT_ACC_DETECT_1DB_F,
	       .flags = IORESOURCE_IRQ,
689 690
	},
	{
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
	       .name = "ACC_DETECT_1DB_R",
	       .start = AB8500_INT_ACC_DETECT_1DB_R,
	       .end = AB8500_INT_ACC_DETECT_1DB_R,
	       .flags = IORESOURCE_IRQ,
	},
	{
	       .name = "ACC_DETECT_21DB_F",
	       .start = AB8500_INT_ACC_DETECT_21DB_F,
	       .end = AB8500_INT_ACC_DETECT_21DB_F,
	       .flags = IORESOURCE_IRQ,
	},
	{
	       .name = "ACC_DETECT_21DB_R",
	       .start = AB8500_INT_ACC_DETECT_21DB_R,
	       .end = AB8500_INT_ACC_DETECT_21DB_R,
	       .flags = IORESOURCE_IRQ,
	},
	{
	       .name = "ACC_DETECT_22DB_F",
	       .start = AB8500_INT_ACC_DETECT_22DB_F,
	       .end = AB8500_INT_ACC_DETECT_22DB_F,
	       .flags = IORESOURCE_IRQ,
713
	},
714 715 716 717 718 719 720 721
	{
	       .name = "ACC_DETECT_22DB_R",
	       .start = AB8500_INT_ACC_DETECT_22DB_R,
	       .end = AB8500_INT_ACC_DETECT_22DB_R,
	       .flags = IORESOURCE_IRQ,
	},
};

B
Bill Pemberton 已提交
722
static struct resource ab8500_charger_resources[] = {
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
	{
		.name = "MAIN_CH_UNPLUG_DET",
		.start = AB8500_INT_MAIN_CH_UNPLUG_DET,
		.end = AB8500_INT_MAIN_CH_UNPLUG_DET,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "MAIN_CHARGE_PLUG_DET",
		.start = AB8500_INT_MAIN_CH_PLUG_DET,
		.end = AB8500_INT_MAIN_CH_PLUG_DET,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "VBUS_DET_R",
		.start = AB8500_INT_VBUS_DET_R,
		.end = AB8500_INT_VBUS_DET_R,
		.flags = IORESOURCE_IRQ,
	},
	{
742 743 744
		.name = "VBUS_DET_F",
		.start = AB8500_INT_VBUS_DET_F,
		.end = AB8500_INT_VBUS_DET_F,
745 746 747
		.flags = IORESOURCE_IRQ,
	},
	{
748 749 750 751 752
		.name = "USB_LINK_STATUS",
		.start = AB8500_INT_USB_LINK_STATUS,
		.end = AB8500_INT_USB_LINK_STATUS,
		.flags = IORESOURCE_IRQ,
	},
753 754 755 756 757 758 759
	{
		.name = "VBUS_OVV",
		.start = AB8500_INT_VBUS_OVV,
		.end = AB8500_INT_VBUS_OVV,
		.flags = IORESOURCE_IRQ,
	},
	{
760 761 762
		.name = "USB_CH_TH_PROT_R",
		.start = AB8500_INT_USB_CH_TH_PROT_R,
		.end = AB8500_INT_USB_CH_TH_PROT_R,
763 764 765
		.flags = IORESOURCE_IRQ,
	},
	{
766 767 768
		.name = "USB_CH_TH_PROT_F",
		.start = AB8500_INT_USB_CH_TH_PROT_F,
		.end = AB8500_INT_USB_CH_TH_PROT_F,
769 770 771
		.flags = IORESOURCE_IRQ,
	},
	{
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
		.name = "MAIN_EXT_CH_NOT_OK",
		.start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
		.end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "MAIN_CH_TH_PROT_R",
		.start = AB8500_INT_MAIN_CH_TH_PROT_R,
		.end = AB8500_INT_MAIN_CH_TH_PROT_R,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "MAIN_CH_TH_PROT_F",
		.start = AB8500_INT_MAIN_CH_TH_PROT_F,
		.end = AB8500_INT_MAIN_CH_TH_PROT_F,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "USB_CHARGER_NOT_OKR",
791 792
		.start = AB8500_INT_USB_CHARGER_NOT_OKR,
		.end = AB8500_INT_USB_CHARGER_NOT_OKR,
793 794 795 796 797 798 799 800
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "CH_WD_EXP",
		.start = AB8500_INT_CH_WD_EXP,
		.end = AB8500_INT_CH_WD_EXP,
		.flags = IORESOURCE_IRQ,
	},
801 802 803 804 805 806
	{
		.name = "VBUS_CH_DROP_END",
		.start = AB8500_INT_VBUS_CH_DROP_END,
		.end = AB8500_INT_VBUS_CH_DROP_END,
		.flags = IORESOURCE_IRQ,
	},
807 808
};

B
Bill Pemberton 已提交
809
static struct resource ab8500_btemp_resources[] = {
810 811 812 813
	{
		.name = "BAT_CTRL_INDB",
		.start = AB8500_INT_BAT_CTRL_INDB,
		.end = AB8500_INT_BAT_CTRL_INDB,
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "BTEMP_LOW",
		.start = AB8500_INT_BTEMP_LOW,
		.end = AB8500_INT_BTEMP_LOW,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "BTEMP_HIGH",
		.start = AB8500_INT_BTEMP_HIGH,
		.end = AB8500_INT_BTEMP_HIGH,
		.flags = IORESOURCE_IRQ,
	},
	{
829 830 831
		.name = "BTEMP_LOW_MEDIUM",
		.start = AB8500_INT_BTEMP_LOW_MEDIUM,
		.end = AB8500_INT_BTEMP_LOW_MEDIUM,
832 833 834
		.flags = IORESOURCE_IRQ,
	},
	{
835 836 837
		.name = "BTEMP_MEDIUM_HIGH",
		.start = AB8500_INT_BTEMP_MEDIUM_HIGH,
		.end = AB8500_INT_BTEMP_MEDIUM_HIGH,
838 839
		.flags = IORESOURCE_IRQ,
	},
840 841
};

B
Bill Pemberton 已提交
842
static struct resource ab8500_fg_resources[] = {
843
	{
844 845 846
		.name = "NCONV_ACCU",
		.start = AB8500_INT_CCN_CONV_ACC,
		.end = AB8500_INT_CCN_CONV_ACC,
847 848 849
		.flags = IORESOURCE_IRQ,
	},
	{
850 851 852
		.name = "BATT_OVV",
		.start = AB8500_INT_BATT_OVV,
		.end = AB8500_INT_BATT_OVV,
853 854 855
		.flags = IORESOURCE_IRQ,
	},
	{
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
		.name = "LOW_BAT_F",
		.start = AB8500_INT_LOW_BAT_F,
		.end = AB8500_INT_LOW_BAT_F,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "LOW_BAT_R",
		.start = AB8500_INT_LOW_BAT_R,
		.end = AB8500_INT_LOW_BAT_R,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "CC_INT_CALIB",
		.start = AB8500_INT_CC_INT_CALIB,
		.end = AB8500_INT_CC_INT_CALIB,
871 872
		.flags = IORESOURCE_IRQ,
	},
873 874 875 876 877 878
	{
		.name = "CCEOC",
		.start = AB8500_INT_CCEOC,
		.end = AB8500_INT_CCEOC,
		.flags = IORESOURCE_IRQ,
	},
879 880
};

B
Bill Pemberton 已提交
881
static struct resource ab8500_chargalg_resources[] = {};
882

883
#ifdef CONFIG_DEBUG_FS
B
Bill Pemberton 已提交
884
static struct resource ab8500_debug_resources[] = {
885 886 887 888 889 890 891 892 893
	{
		.name	= "IRQ_AB8500",
		/*
		 * Number will be filled in. NOTE: this is deliberately
		 * not flagged as an IRQ in ordet to avoid remapping using
		 * the irqdomain in the MFD core, so that this IRQ passes
		 * unremapped to the debug code.
		 */
	},
894 895 896 897 898 899 900 901
	{
		.name	= "IRQ_FIRST",
		.start	= AB8500_INT_MAIN_EXT_CH_NOT_OK,
		.end	= AB8500_INT_MAIN_EXT_CH_NOT_OK,
		.flags	= IORESOURCE_IRQ,
	},
	{
		.name	= "IRQ_LAST",
902 903
		.start	= AB8500_INT_XTAL32K_KO,
		.end	= AB8500_INT_XTAL32K_KO,
904 905 906
		.flags	= IORESOURCE_IRQ,
	},
};
907
#endif
908

B
Bill Pemberton 已提交
909
static struct resource ab8500_usb_resources[] = {
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
	{
		.name = "ID_WAKEUP_R",
		.start = AB8500_INT_ID_WAKEUP_R,
		.end = AB8500_INT_ID_WAKEUP_R,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "ID_WAKEUP_F",
		.start = AB8500_INT_ID_WAKEUP_F,
		.end = AB8500_INT_ID_WAKEUP_F,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "VBUS_DET_F",
		.start = AB8500_INT_VBUS_DET_F,
		.end = AB8500_INT_VBUS_DET_F,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "VBUS_DET_R",
		.start = AB8500_INT_VBUS_DET_R,
		.end = AB8500_INT_VBUS_DET_R,
		.flags = IORESOURCE_IRQ,
	},
934 935 936 937 938 939
	{
		.name = "USB_LINK_STATUS",
		.start = AB8500_INT_USB_LINK_STATUS,
		.end = AB8500_INT_USB_LINK_STATUS,
		.flags = IORESOURCE_IRQ,
	},
940 941 942 943 944 945 946 947 948 949 950 951
	{
		.name = "USB_ADP_PROBE_PLUG",
		.start = AB8500_INT_ADP_PROBE_PLUG,
		.end = AB8500_INT_ADP_PROBE_PLUG,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "USB_ADP_PROBE_UNPLUG",
		.start = AB8500_INT_ADP_PROBE_UNPLUG,
		.end = AB8500_INT_ADP_PROBE_UNPLUG,
		.flags = IORESOURCE_IRQ,
	},
952 953
};

B
Bill Pemberton 已提交
954
static struct resource ab8505_iddet_resources[] = {
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
	{
		.name  = "KeyDeglitch",
		.start = AB8505_INT_KEYDEGLITCH,
		.end   = AB8505_INT_KEYDEGLITCH,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name  = "KP",
		.start = AB8505_INT_KP,
		.end   = AB8505_INT_KP,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name  = "IKP",
		.start = AB8505_INT_IKP,
		.end   = AB8505_INT_IKP,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name  = "IKR",
		.start = AB8505_INT_IKR,
		.end   = AB8505_INT_IKR,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name  = "KeyStuck",
		.start = AB8505_INT_KEYSTUCK,
		.end   = AB8505_INT_KEYSTUCK,
		.flags = IORESOURCE_IRQ,
	},
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
	{
		.name = "VBUS_DET_R",
		.start = AB8500_INT_VBUS_DET_R,
		.end = AB8500_INT_VBUS_DET_R,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "VBUS_DET_F",
		.start = AB8500_INT_VBUS_DET_F,
		.end = AB8500_INT_VBUS_DET_F,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "ID_DET_PLUGR",
		.start = AB8500_INT_ID_DET_PLUGR,
		.end = AB8500_INT_ID_DET_PLUGR,
		.flags = IORESOURCE_IRQ,
	},
	{
		.name = "ID_DET_PLUGF",
		.start = AB8500_INT_ID_DET_PLUGF,
		.end = AB8500_INT_ID_DET_PLUGF,
		.flags = IORESOURCE_IRQ,
	},
1009 1010
};

B
Bill Pemberton 已提交
1011
static struct resource ab8500_temp_resources[] = {
1012
	{
1013
		.name  = "ABX500_TEMP_WARM",
1014 1015 1016 1017 1018 1019
		.start = AB8500_INT_TEMP_WARM,
		.end   = AB8500_INT_TEMP_WARM,
		.flags = IORESOURCE_IRQ,
	},
};

1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
static struct mfd_cell ab8500_bm_devs[] = {
	{
		.name = "ab8500-charger",
		.of_compatible = "stericsson,ab8500-charger",
		.num_resources = ARRAY_SIZE(ab8500_charger_resources),
		.resources = ab8500_charger_resources,
		.platform_data = &ab8500_bm_data,
		.pdata_size = sizeof(ab8500_bm_data),
	},
	{
		.name = "ab8500-btemp",
		.of_compatible = "stericsson,ab8500-btemp",
		.num_resources = ARRAY_SIZE(ab8500_btemp_resources),
		.resources = ab8500_btemp_resources,
		.platform_data = &ab8500_bm_data,
		.pdata_size = sizeof(ab8500_bm_data),
	},
	{
		.name = "ab8500-fg",
		.of_compatible = "stericsson,ab8500-fg",
		.num_resources = ARRAY_SIZE(ab8500_fg_resources),
		.resources = ab8500_fg_resources,
		.platform_data = &ab8500_bm_data,
		.pdata_size = sizeof(ab8500_bm_data),
	},
	{
		.name = "ab8500-chargalg",
		.of_compatible = "stericsson,ab8500-chargalg",
		.num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
		.resources = ab8500_chargalg_resources,
		.platform_data = &ab8500_bm_data,
		.pdata_size = sizeof(ab8500_bm_data),
	},
};

static struct mfd_cell ab8500_devs[] = {
M
Mattias Wallin 已提交
1056 1057 1058
#ifdef CONFIG_DEBUG_FS
	{
		.name = "ab8500-debug",
1059
		.of_compatible = "stericsson,ab8500-debug",
1060 1061
		.num_resources = ARRAY_SIZE(ab8500_debug_resources),
		.resources = ab8500_debug_resources,
M
Mattias Wallin 已提交
1062 1063
	},
#endif
1064 1065
	{
		.name = "ab8500-sysctrl",
1066
		.of_compatible = "stericsson,ab8500-sysctrl",
1067
	},
1068 1069 1070 1071
	{
		.name = "ab8500-ext-regulator",
		.of_compatible = "stericsson,ab8500-ext-regulator",
	},
1072 1073
	{
		.name = "ab8500-regulator",
1074
		.of_compatible = "stericsson,ab8500-regulator",
1075
	},
1076 1077 1078 1079
	{
		.name = "abx500-clk",
		.of_compatible = "stericsson,abx500-clk",
	},
1080 1081
	{
		.name = "ab8500-gpadc",
1082
		.of_compatible = "stericsson,ab8500-gpadc",
1083 1084 1085
		.num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
		.resources = ab8500_gpadc_resources,
	},
R
Rabin Vincent 已提交
1086 1087
	{
		.name = "ab8500-rtc",
1088
		.of_compatible = "stericsson,ab8500-rtc",
R
Rabin Vincent 已提交
1089 1090 1091
		.num_resources = ARRAY_SIZE(ab8500_rtc_resources),
		.resources = ab8500_rtc_resources,
	},
1092 1093
	{
		.name = "ab8500-acc-det",
1094
		.of_compatible = "stericsson,ab8500-acc-det",
1095 1096 1097
		.num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
		.resources = ab8500_av_acc_detect_resources,
	},
1098
	{
1099

1100
		.name = "ab8500-poweron-key",
1101
		.of_compatible = "stericsson,ab8500-poweron-key",
1102 1103 1104
		.num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
		.resources = ab8500_poweronkey_db_resources,
	},
A
Arun Murthy 已提交
1105 1106
	{
		.name = "ab8500-pwm",
1107
		.of_compatible = "stericsson,ab8500-pwm",
A
Arun Murthy 已提交
1108 1109 1110 1111
		.id = 1,
	},
	{
		.name = "ab8500-pwm",
1112
		.of_compatible = "stericsson,ab8500-pwm",
A
Arun Murthy 已提交
1113 1114 1115 1116
		.id = 2,
	},
	{
		.name = "ab8500-pwm",
1117
		.of_compatible = "stericsson,ab8500-pwm",
A
Arun Murthy 已提交
1118 1119
		.id = 3,
	},
1120
	{
1121
		.name = "ab8500-denc",
1122
		.of_compatible = "stericsson,ab8500-denc",
1123
	},
1124
	{
1125
		.name = "pinctrl-ab8500",
1126 1127
		.of_compatible = "stericsson,ab8500-gpio",
	},
1128
	{
1129 1130
		.name = "abx500-temp",
		.of_compatible = "stericsson,abx500-temp",
1131 1132
		.num_resources = ARRAY_SIZE(ab8500_temp_resources),
		.resources = ab8500_temp_resources,
1133
	},
1134
	{
1135
		.name = "ab8500-usb",
1136
		.of_compatible = "stericsson,ab8500-usb",
1137 1138
		.num_resources = ARRAY_SIZE(ab8500_usb_resources),
		.resources = ab8500_usb_resources,
1139 1140
	},
	{
1141
		.name = "ab8500-codec",
1142
		.of_compatible = "stericsson,ab8500-codec",
1143 1144 1145
	},
};

1146 1147
static struct mfd_cell ab9540_devs[] = {
#ifdef CONFIG_DEBUG_FS
1148
	{
1149 1150 1151
		.name = "ab8500-debug",
		.num_resources = ARRAY_SIZE(ab8500_debug_resources),
		.resources = ab8500_debug_resources,
1152
	},
1153
#endif
1154
	{
1155
		.name = "ab8500-sysctrl",
1156
	},
1157 1158 1159
	{
		.name = "ab8500-ext-regulator",
	},
1160
	{
1161
		.name = "ab8500-regulator",
1162
	},
1163 1164 1165 1166
	{
		.name = "abx500-clk",
		.of_compatible = "stericsson,abx500-clk",
	},
1167 1168 1169 1170 1171 1172
	{
		.name = "ab8500-gpadc",
		.of_compatible = "stericsson,ab8500-gpadc",
		.num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
		.resources = ab8500_gpadc_resources,
	},
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
	{
		.name = "ab8500-rtc",
		.num_resources = ARRAY_SIZE(ab8500_rtc_resources),
		.resources = ab8500_rtc_resources,
	},
	{
		.name = "ab8500-acc-det",
		.num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
		.resources = ab8500_av_acc_detect_resources,
	},
	{
		.name = "ab8500-poweron-key",
		.num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
		.resources = ab8500_poweronkey_db_resources,
	},
	{
		.name = "ab8500-pwm",
		.id = 1,
	},
	{
		.name = "abx500-temp",
		.num_resources = ARRAY_SIZE(ab8500_temp_resources),
		.resources = ab8500_temp_resources,
	},
1197
	{
1198 1199
		.name = "pinctrl-ab9540",
		.of_compatible = "stericsson,ab9540-gpio",
1200 1201 1202 1203 1204 1205
	},
	{
		.name = "ab9540-usb",
		.num_resources = ARRAY_SIZE(ab8500_usb_resources),
		.resources = ab8500_usb_resources,
	},
1206 1207 1208
	{
		.name = "ab9540-codec",
	},
1209 1210 1211 1212 1213
	{
		.name = "ab-iddet",
		.num_resources = ARRAY_SIZE(ab8505_iddet_resources),
		.resources = ab8505_iddet_resources,
	},
1214 1215
};

1216 1217
/* Device list for ab8505  */
static struct mfd_cell ab8505_devs[] = {
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
#ifdef CONFIG_DEBUG_FS
	{
		.name = "ab8500-debug",
		.num_resources = ARRAY_SIZE(ab8500_debug_resources),
		.resources = ab8500_debug_resources,
	},
#endif
	{
		.name = "ab8500-sysctrl",
	},
	{
		.name = "ab8500-regulator",
	},
1231 1232 1233 1234
	{
		.name = "abx500-clk",
		.of_compatible = "stericsson,abx500-clk",
	},
1235 1236
	{
		.name = "ab8500-gpadc",
1237
		.of_compatible = "stericsson,ab8500-gpadc",
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
		.num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
		.resources = ab8505_gpadc_resources,
	},
	{
		.name = "ab8500-rtc",
		.num_resources = ARRAY_SIZE(ab8500_rtc_resources),
		.resources = ab8500_rtc_resources,
	},
	{
		.name = "ab8500-acc-det",
		.num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
		.resources = ab8500_av_acc_detect_resources,
	},
	{
		.name = "ab8500-poweron-key",
		.num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
		.resources = ab8500_poweronkey_db_resources,
	},
	{
		.name = "ab8500-pwm",
		.id = 1,
	},
	{
1261
		.name = "pinctrl-ab8505",
1262 1263 1264 1265 1266 1267 1268 1269 1270
	},
	{
		.name = "ab8500-usb",
		.num_resources = ARRAY_SIZE(ab8500_usb_resources),
		.resources = ab8500_usb_resources,
	},
	{
		.name = "ab8500-codec",
	},
1271 1272 1273 1274 1275 1276 1277 1278
	{
		.name = "ab-iddet",
		.num_resources = ARRAY_SIZE(ab8505_iddet_resources),
		.resources = ab8505_iddet_resources,
	},
};

static struct mfd_cell ab8540_devs[] = {
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
#ifdef CONFIG_DEBUG_FS
	{
		.name = "ab8500-debug",
		.num_resources = ARRAY_SIZE(ab8500_debug_resources),
		.resources = ab8500_debug_resources,
	},
#endif
	{
		.name = "ab8500-sysctrl",
	},
1289 1290 1291
	{
		.name = "ab8500-ext-regulator",
	},
1292 1293 1294
	{
		.name = "ab8500-regulator",
	},
1295 1296 1297 1298
	{
		.name = "abx500-clk",
		.of_compatible = "stericsson,abx500-clk",
	},
1299 1300
	{
		.name = "ab8500-gpadc",
1301
		.of_compatible = "stericsson,ab8500-gpadc",
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
		.num_resources = ARRAY_SIZE(ab8505_gpadc_resources),
		.resources = ab8505_gpadc_resources,
	},
	{
		.name = "ab8500-acc-det",
		.num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
		.resources = ab8500_av_acc_detect_resources,
	},
	{
		.name = "ab8500-poweron-key",
		.num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
		.resources = ab8500_poweronkey_db_resources,
	},
	{
		.name = "ab8500-pwm",
		.id = 1,
	},
	{
		.name = "abx500-temp",
		.num_resources = ARRAY_SIZE(ab8500_temp_resources),
		.resources = ab8500_temp_resources,
	},
1324
	{
1325
		.name = "pinctrl-ab8540",
1326 1327 1328 1329 1330 1331 1332 1333 1334
	},
	{
		.name = "ab8540-usb",
		.num_resources = ARRAY_SIZE(ab8500_usb_resources),
		.resources = ab8500_usb_resources,
	},
	{
		.name = "ab8540-codec",
	},
1335 1336 1337 1338 1339
	{
		.name = "ab-iddet",
		.num_resources = ARRAY_SIZE(ab8505_iddet_resources),
		.resources = ab8505_iddet_resources,
	},
1340 1341
};

1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
static struct mfd_cell ab8540_cut1_devs[] = {
	{
		.name = "ab8500-rtc",
		.of_compatible = "stericsson,ab8500-rtc",
		.num_resources = ARRAY_SIZE(ab8500_rtc_resources),
		.resources = ab8500_rtc_resources,
	},
};

static struct mfd_cell ab8540_cut2_devs[] = {
	{
		.name = "ab8540-rtc",
		.of_compatible = "stericsson,ab8540-rtc",
		.num_resources = ARRAY_SIZE(ab8540_rtc_resources),
		.resources = ab8540_rtc_resources,
	},
};

1360 1361 1362 1363 1364 1365
static ssize_t show_chip_id(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct ab8500 *ab8500;

	ab8500 = dev_get_drvdata(dev);
1366

1367 1368 1369
	return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
}

1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
/*
 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
 * 0x01 Swoff bit programming
 * 0x02 Thermal protection activation
 * 0x04 Vbat lower then BattOk falling threshold
 * 0x08 Watchdog expired
 * 0x10 Non presence of 32kHz clock
 * 0x20 Battery level lower than power on reset threshold
 * 0x40 Power on key 1 pressed longer than 10 seconds
 * 0x80 DB8500 thermal shutdown
 */
static ssize_t show_switch_off_status(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	u8 value;
	struct ab8500 *ab8500;

	ab8500 = dev_get_drvdata(dev);
	ret = get_register_interruptible(ab8500, AB8500_RTC,
		AB8500_SWITCH_OFF_STATUS, &value);
	if (ret < 0)
		return ret;
	return sprintf(buf, "%#x\n", value);
}

1396 1397 1398 1399 1400 1401 1402 1403 1404
/* use mask and set to override the register turn_on_stat value */
void ab8500_override_turn_on_stat(u8 mask, u8 set)
{
	spin_lock(&on_stat_lock);
	turn_on_stat_mask = mask;
	turn_on_stat_set = set;
	spin_unlock(&on_stat_lock);
}

1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
/*
 * ab8500 has turned on due to (TURN_ON_STATUS):
 * 0x01 PORnVbat
 * 0x02 PonKey1dbF
 * 0x04 PonKey2dbF
 * 0x08 RTCAlarm
 * 0x10 MainChDet
 * 0x20 VbusDet
 * 0x40 UsbIDDetect
 * 0x80 Reserved
 */
static ssize_t show_turn_on_status(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	u8 value;
	struct ab8500 *ab8500;

	ab8500 = dev_get_drvdata(dev);
	ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
		AB8500_TURN_ON_STATUS, &value);
	if (ret < 0)
		return ret;
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441

	/*
	 * In L9540, turn_on_status register is not updated correctly if
	 * the device is rebooted with AC/USB charger connected. Due to
	 * this, the device boots android instead of entering into charge
	 * only mode. Read the AC/USB status register to detect the charger
	 * presence and update the turn on status manually.
	 */
	if (is_ab9540(ab8500)) {
		spin_lock(&on_stat_lock);
		value = (value & turn_on_stat_mask) | turn_on_stat_set;
		spin_unlock(&on_stat_lock);
	}

1442 1443 1444
	return sprintf(buf, "%#x\n", value);
}

1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
static ssize_t show_turn_on_status_2(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	int ret;
	u8 value;
	struct ab8500 *ab8500;

	ab8500 = dev_get_drvdata(dev);
	ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
		AB8505_TURN_ON_STATUS_2, &value);
	if (ret < 0)
		return ret;
	return sprintf(buf, "%#x\n", (value & 0x1));
}

1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
static ssize_t show_ab9540_dbbrstn(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct ab8500 *ab8500;
	int ret;
	u8 value;

	ab8500 = dev_get_drvdata(dev);

	ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2,
		AB9540_MODEM_CTRL2_REG, &value);
	if (ret < 0)
		return ret;

	return sprintf(buf, "%d\n",
			(value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0);
}

static ssize_t store_ab9540_dbbrstn(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t count)
{
	struct ab8500 *ab8500;
	int ret = count;
	int err;
	u8 bitvalues;

	ab8500 = dev_get_drvdata(dev);

	if (count > 0) {
		switch (buf[0]) {
		case '0':
			bitvalues = 0;
			break;
		case '1':
			bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT;
			break;
		default:
			goto exit;
		}

		err = mask_and_set_register_interruptible(ab8500,
			AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG,
			AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues);
		if (err)
			dev_info(ab8500->dev,
				"Failed to set DBBRSTN %c, err %#x\n",
				buf[0], err);
	}

exit:
	return ret;
}

1513
static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
1514
static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
1515
static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
1516
static DEVICE_ATTR(turn_on_status_2, S_IRUGO, show_turn_on_status_2, NULL);
1517 1518
static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
			show_ab9540_dbbrstn, store_ab9540_dbbrstn);
1519 1520 1521

static struct attribute *ab8500_sysfs_entries[] = {
	&dev_attr_chip_id.attr,
1522
	&dev_attr_switch_off_status.attr,
1523
	&dev_attr_turn_on_status.attr,
1524 1525 1526
	NULL,
};

1527 1528 1529 1530 1531
static struct attribute *ab8505_sysfs_entries[] = {
	&dev_attr_turn_on_status_2.attr,
	NULL,
};

1532 1533 1534 1535 1536 1537 1538 1539
static struct attribute *ab9540_sysfs_entries[] = {
	&dev_attr_chip_id.attr,
	&dev_attr_switch_off_status.attr,
	&dev_attr_turn_on_status.attr,
	&dev_attr_dbbrstn.attr,
	NULL,
};

1540 1541 1542 1543
static struct attribute_group ab8500_attr_group = {
	.attrs	= ab8500_sysfs_entries,
};

1544 1545 1546 1547
static struct attribute_group ab8505_attr_group = {
	.attrs	= ab8505_sysfs_entries,
};

1548 1549 1550 1551
static struct attribute_group ab9540_attr_group = {
	.attrs	= ab9540_sysfs_entries,
};

B
Bill Pemberton 已提交
1552
static int ab8500_probe(struct platform_device *pdev)
R
Rabin Vincent 已提交
1553
{
1554 1555 1556 1557 1558 1559 1560 1561 1562
	static char *switch_off_status[] = {
		"Swoff bit programming",
		"Thermal protection activation",
		"Vbat lower then BattOk falling threshold",
		"Watchdog expired",
		"Non presence of 32kHz clock",
		"Battery level lower than power on reset threshold",
		"Power on key 1 pressed longer than 10 seconds",
		"DB8500 thermal shutdown"};
1563 1564 1565 1566 1567 1568 1569 1570 1571
	static char *turn_on_status[] = {
		"Battery rising (Vbat)",
		"Power On Key 1 dbF",
		"Power On Key 2 dbF",
		"RTC Alarm",
		"Main Charger Detect",
		"Vbus Detect (USB)",
		"USB ID Detect",
		"UART Factory Mode Detect"};
1572 1573
	struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev);
	const struct platform_device_id *platid = platform_get_device_id(pdev);
1574 1575
	enum ab8500_version version = AB8500_VERSION_UNDEFINED;
	struct device_node *np = pdev->dev.of_node;
1576 1577
	struct ab8500 *ab8500;
	struct resource *resource;
R
Rabin Vincent 已提交
1578 1579
	int ret;
	int i;
1580
	u8 value;
R
Rabin Vincent 已提交
1581

1582
	ab8500 = devm_kzalloc(&pdev->dev, sizeof *ab8500, GFP_KERNEL);
1583 1584 1585
	if (!ab8500)
		return -ENOMEM;

R
Rabin Vincent 已提交
1586 1587 1588
	if (plat)
		ab8500->irq_base = plat->irq_base;

1589 1590 1591
	ab8500->dev = &pdev->dev;

	resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1592 1593
	if (!resource)
		return -ENODEV;
1594 1595 1596

	ab8500->irq = resource->start;

1597 1598 1599
	ab8500->read = ab8500_prcmu_read;
	ab8500->write = ab8500_prcmu_write;
	ab8500->write_masked = ab8500_prcmu_write_masked;
1600

R
Rabin Vincent 已提交
1601 1602
	mutex_init(&ab8500->lock);
	mutex_init(&ab8500->irq_lock);
1603
	atomic_set(&ab8500->transfer_ongoing, 0);
R
Rabin Vincent 已提交
1604

1605 1606
	platform_set_drvdata(pdev, ab8500);

1607 1608 1609
	if (platid)
		version = platid->driver_data;

1610 1611 1612 1613 1614 1615
	if (version != AB8500_VERSION_UNDEFINED)
		ab8500->version = version;
	else {
		ret = get_register_interruptible(ab8500, AB8500_MISC,
			AB8500_IC_NAME_REG, &value);
		if (ret < 0)
1616
			return ret;
1617 1618 1619 1620

		ab8500->version = value;
	}

1621 1622
	ret = get_register_interruptible(ab8500, AB8500_MISC,
		AB8500_REV_REG, &value);
R
Rabin Vincent 已提交
1623
	if (ret < 0)
1624
		return ret;
R
Rabin Vincent 已提交
1625

1626
	ab8500->chip_id = value;
R
Rabin Vincent 已提交
1627

1628 1629 1630 1631 1632
	dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
			ab8500_version_str[ab8500->version],
			ab8500->chip_id >> 4,
			ab8500->chip_id & 0x0F);

1633 1634 1635 1636 1637 1638 1639
	/* Configure AB8540 */
	if (is_ab8540(ab8500)) {
		ab8500->mask_size = AB8540_NUM_IRQ_REGS;
		ab8500->irq_reg_offset = ab8540_irq_regoffset;
		ab8500->it_latchhier_num = AB8540_IT_LATCHHIER_NUM;
	}/* Configure AB8500 or AB9540 IRQ */
	else if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
1640 1641
		ab8500->mask_size = AB9540_NUM_IRQ_REGS;
		ab8500->irq_reg_offset = ab9540_irq_regoffset;
1642
		ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
1643 1644 1645
	} else {
		ab8500->mask_size = AB8500_NUM_IRQ_REGS;
		ab8500->irq_reg_offset = ab8500_irq_regoffset;
1646
		ab8500->it_latchhier_num = AB8500_IT_LATCHHIER_NUM;
1647
	}
1648
	ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL);
1649 1650
	if (!ab8500->mask)
		return -ENOMEM;
1651 1652 1653 1654
	ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL);
	if (!ab8500->oldmask)
		return -ENOMEM;

1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
	/*
	 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
	 * 0x01 Swoff bit programming
	 * 0x02 Thermal protection activation
	 * 0x04 Vbat lower then BattOk falling threshold
	 * 0x08 Watchdog expired
	 * 0x10 Non presence of 32kHz clock
	 * 0x20 Battery level lower than power on reset threshold
	 * 0x40 Power on key 1 pressed longer than 10 seconds
	 * 0x80 DB8500 thermal shutdown
	 */

	ret = get_register_interruptible(ab8500, AB8500_RTC,
		AB8500_SWITCH_OFF_STATUS, &value);
	if (ret < 0)
		return ret;
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684
	dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value);

	if (value) {
		for (i = 0; i < ARRAY_SIZE(switch_off_status); i++) {
			if (value & 1)
				printk(KERN_CONT " \"%s\"",
				       switch_off_status[i]);
			value = value >> 1;

		}
		printk(KERN_CONT "\n");
	} else {
		printk(KERN_CONT " None\n");
	}
1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
	ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
		AB8500_TURN_ON_STATUS, &value);
	if (ret < 0)
		return ret;
	dev_info(ab8500->dev, "turn on reason(s) (%#x): ", value);

	if (value) {
		for (i = 0; i < ARRAY_SIZE(turn_on_status); i++) {
			if (value & 1)
				printk("\"%s\" ", turn_on_status[i]);
			value = value >> 1;
		}
		printk("\n");
	} else {
		printk("None\n");
	}
1701

R
Rabin Vincent 已提交
1702 1703
	if (plat && plat->init)
		plat->init(ab8500);
1704

1705 1706 1707 1708 1709 1710 1711 1712 1713
	if (is_ab9540(ab8500)) {
		ret = get_register_interruptible(ab8500, AB8500_CHARGER,
			AB8500_CH_USBCH_STAT1_REG, &value);
		if (ret < 0)
			return ret;
		if ((value & VBUS_DET_DBNC1) && (value & VBUS_DET_DBNC100))
			ab8500_override_turn_on_stat(~AB8500_POW_KEY_1_ON,
						     AB8500_VBUS_DET);
	}
R
Rabin Vincent 已提交
1714 1715

	/* Clear and mask all interrupts */
1716
	for (i = 0; i < ab8500->mask_size; i++) {
1717 1718 1719 1720 1721 1722
		/*
		 * Interrupt register 12 doesn't exist prior to AB8500 version
		 * 2.0
		 */
		if (ab8500->irq_reg_offset[i] == 11 &&
				is_ab8500_1p1_or_earlier(ab8500))
1723
			continue;
R
Rabin Vincent 已提交
1724

1725 1726 1727
		if (ab8500->irq_reg_offset[i] < 0)
			continue;

1728
		get_register_interruptible(ab8500, AB8500_INTERRUPT,
1729
			AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
1730
			&value);
1731
		set_register_interruptible(ab8500, AB8500_INTERRUPT,
1732
			AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
R
Rabin Vincent 已提交
1733 1734
	}

1735 1736
	ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
	if (ret)
1737
		return ret;
1738

1739
	for (i = 0; i < ab8500->mask_size; i++)
R
Rabin Vincent 已提交
1740 1741
		ab8500->mask[i] = ab8500->oldmask[i] = 0xff;

1742 1743
	ret = ab8500_irq_init(ab8500, np);
	if (ret)
1744
		return ret;
R
Rabin Vincent 已提交
1745

1746 1747 1748 1749 1750 1751
	ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL,
			ab8500_hierarchical_irq,
			IRQF_ONESHOT | IRQF_NO_SUSPEND,
			"ab8500", ab8500);
	if (ret)
		return ret;
R
Rabin Vincent 已提交
1752

1753 1754 1755 1756 1757 1758
#if CONFIG_DEBUG_FS
	/* Pass to debugfs */
	ab8500_debug_resources[0].start = ab8500->irq;
	ab8500_debug_resources[0].end = ab8500->irq;
#endif

1759 1760 1761
	if (is_ab9540(ab8500))
		ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
				ARRAY_SIZE(ab9540_devs), NULL,
1762
				ab8500->irq_base, ab8500->domain);
1763
	else if (is_ab8540(ab8500)) {
1764 1765
		ret = mfd_add_devices(ab8500->dev, 0, ab8540_devs,
			      ARRAY_SIZE(ab8540_devs), NULL,
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
			      ab8500->irq_base, NULL);
		if (ret)
			return ret;

		if (is_ab8540_1p2_or_earlier(ab8500))
			ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut1_devs,
			      ARRAY_SIZE(ab8540_cut1_devs), NULL,
			      ab8500->irq_base, NULL);
		else /* ab8540 >= cut2 */
			ret = mfd_add_devices(ab8500->dev, 0, ab8540_cut2_devs,
			      ARRAY_SIZE(ab8540_cut2_devs), NULL,
			      ab8500->irq_base, NULL);
	} else if (is_ab8505(ab8500))
1779 1780 1781
		ret = mfd_add_devices(ab8500->dev, 0, ab8505_devs,
			      ARRAY_SIZE(ab8505_devs), NULL,
			      ab8500->irq_base, ab8500->domain);
1782 1783 1784
	else
		ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
				ARRAY_SIZE(ab8500_devs), NULL,
1785
				ab8500->irq_base, ab8500->domain);
1786
	if (ret)
1787
		return ret;
1788

1789 1790 1791 1792
	if (!no_bm) {
		/* Add battery management devices */
		ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
				      ARRAY_SIZE(ab8500_bm_devs), NULL,
1793
				      ab8500->irq_base, ab8500->domain);
1794 1795 1796 1797
		if (ret)
			dev_err(ab8500->dev, "error adding bm devices\n");
	}

1798 1799
	if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
			ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
1800 1801 1802 1803 1804
		ret = sysfs_create_group(&ab8500->dev->kobj,
					&ab9540_attr_group);
	else
		ret = sysfs_create_group(&ab8500->dev->kobj,
					&ab8500_attr_group);
1805 1806 1807 1808 1809 1810

	if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
			ab8500->chip_id >= AB8500_CUT2P0)
		ret = sysfs_create_group(&ab8500->dev->kobj,
					 &ab8505_attr_group);

1811 1812
	if (ret)
		dev_err(ab8500->dev, "error creating sysfs entries\n");
1813 1814

	return ret;
R
Rabin Vincent 已提交
1815 1816
}

B
Bill Pemberton 已提交
1817
static int ab8500_remove(struct platform_device *pdev)
R
Rabin Vincent 已提交
1818
{
1819 1820
	struct ab8500 *ab8500 = platform_get_drvdata(pdev);

1821 1822
	if (((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
			ab8500->chip_id >= AB8500_CUT2P0) || is_ab8540(ab8500))
1823 1824 1825
		sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
	else
		sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
1826

1827 1828 1829 1830
	if ((is_ab8505(ab8500) || is_ab9540(ab8500)) &&
			ab8500->chip_id >= AB8500_CUT2P0)
		sysfs_remove_group(&ab8500->dev->kobj, &ab8505_attr_group);

R
Rabin Vincent 已提交
1831 1832 1833 1834 1835
	mfd_remove_devices(ab8500->dev);

	return 0;
}

1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
static const struct platform_device_id ab8500_id[] = {
	{ "ab8500-core", AB8500_VERSION_AB8500 },
	{ "ab8505-i2c", AB8500_VERSION_AB8505 },
	{ "ab9540-i2c", AB8500_VERSION_AB9540 },
	{ "ab8540-i2c", AB8500_VERSION_AB8540 },
	{ }
};

static struct platform_driver ab8500_core_driver = {
	.driver = {
		.name = "ab8500-core",
		.owner = THIS_MODULE,
	},
	.probe	= ab8500_probe,
B
Bill Pemberton 已提交
1850
	.remove	= ab8500_remove,
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
	.id_table = ab8500_id,
};

static int __init ab8500_core_init(void)
{
	return platform_driver_register(&ab8500_core_driver);
}

static void __exit ab8500_core_exit(void)
{
	platform_driver_unregister(&ab8500_core_driver);
}
1863
core_initcall(ab8500_core_init);
1864 1865
module_exit(ab8500_core_exit);

1866
MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
R
Rabin Vincent 已提交
1867 1868
MODULE_DESCRIPTION("AB8500 MFD core");
MODULE_LICENSE("GPL v2");