summaryrefslogtreecommitdiffstats
path: root/src/mainboard/google/poppy/variants/baseboard/include/baseboard/acpi/camera_pmic.asl
blob: 377f5615f0225a8156a9e9a8e594599a6f4398f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
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
500
501
502
503
504
505
506
507
508
509
510
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */

Scope (\_SB.PCI0.I2C2)
{
	Device (PMIC)
	{
		Name (_HID, "INT3472") /* _HID: Hardware ID */
		Name (_UID, Zero)  /* _UID: Unique ID */
		Name (_DDN, "TPS68470 PMIC")  /* _DDN: DOS Device Name */
		Name (CAMD, 0x64)

		Method (_STA, 0, NotSerialized)  /* _STA: Status */
		{
			Return (0x0F)
		}

		Method (PMON, 0, Serialized) {
			/*
			 * Turn on 3V3_VDD. It takes around 1 ms for voltage to
			 * settle to 3.3 Volt. Provide additional 2 ms delay.
			 */
			STXS(EN_PP3300_DX_CAM)
			Sleep (3)
		}

		Method (PMOF, 0, Serialized) {
			/* Make Sure all PMIC outputs are off. */
			If (LEqual (VSIC, Zero)) {
				CTXS(EN_PP3300_DX_CAM)
			}
		}

		Name (_PR0, Package (0x01) { CPMC })
		Name (_PR3, Package (0x01) { CPMC })

		/* Power resource methods for PMIC */
		PowerResource (CPMC, 0, 0) {
			Name (RSTO, 1)
			Method (_ON, 0, Serialized) {
				PMON()
				/* Do not reset PMIC across S3 and S0ix cycle */
				if (Lequal (RSTO, 1)) {
					CTXS(EN_CAM_PMIC_RST_L)
					Sleep(1)
					STXS(EN_CAM_PMIC_RST_L)
					Sleep (3)
					RSTO = 0
				}
			}
			Method (_OFF, 0, Serialized) {
				PMOF()
			}
			Method (_STA, 0, Serialized) {
				Return (GTXS(EN_PP3300_DX_CAM))
			}
		}

		/* Marks the availability of all the operation regions */
		Name (AVBL, Zero)
		Name (AVGP, Zero)
		Name (AVB0, Zero)
		Name (AVB1, Zero)
		Name (AVB2, Zero)
		Name (AVB3, Zero)
		Method (_REG, 2, NotSerialized)
		{
			If (LEqual (Arg0, 0x08))
			{
				/* Marks the availability of GeneralPurposeIO
				 * 0x08: opregion space for GeneralPurposeIO
				 */
				Store (Arg1, AVGP)
			}
			If (LEqual (Arg0, 0xB0))
			{
				/* Marks the availability of
				 * TI_PMIC_POWER_OPREGION_ID */
				Store (Arg1, AVB0)
			}
			If (LEqual (Arg0, 0xB1))
			{
				/* Marks the availability of
				 * TI_PMIC_VR_VAL_OPREGION_ID */
				Store (Arg1, AVB1)
			}
			If (LEqual (Arg0, 0xB2))
			{
				/* Marks the availability of
				 * TI_PMIC_CLK_OPREGION_ID */
				Store (Arg1, AVB2)
			}
			If (LEqual (Arg0, 0xB3))
			{
				/* Marks the availability of
				 * TI_PMIC_CLK_FREQ_OPREGION_ID */
				Store (Arg1, AVB3)
			}
			If (LAnd (AVGP, LAnd (LAnd (AVB0, AVB1),
							 LAnd(AVB2, AVB3))))
			{
				/* Marks the availability of all opregions */
				Store (1, AVBL)
			}
			Else
			{
				Store (0, AVBL)
			}
		}

		OperationRegion (GPOP, GeneralPurposeIo, 0, 0x2)
		Name (_CRS, ResourceTemplate ()
		{
			I2cSerialBus (0x004D, ControllerInitiated, 0x00061A80,
				AddressingMode7Bit, "\\_SB.PCI0.I2C2",
				0x00, ResourceConsumer, ,
			)
			/* GPIO.1 is sensor SDA in daisy chain mode */
			GpioIo (Exclusive, PullDefault, 0x0000, 0x0000,
				IoRestrictionInputOnly, "\\_SB.PCI0.I2C2.PMIC",
				0x00, ResourceConsumer,,)
			{
				1
			}
			/* GPIO.2 is sensor SCL in daisy chain mode */
			GpioIo (Exclusive, PullDefault, 0x0000, 0x0000,
				IoRestrictionInputOnly, "\\_SB.PCI0.I2C2.PMIC",
				0x00, ResourceConsumer,,)
			{
				2
			}
			/* GPIO.4 is AVDD pin for user facing camera */
			GpioIo (Exclusive, PullDown, 0x0000, 0x0000,
				IoRestrictionOutputOnly, "\\_SB.PCI0.I2C2.PMIC",
				0x00, ResourceConsumer,,)
			{
				4
			}
			/* GPIO.5 is XSHUTDOWN pin for user facing camera */
			GpioIo (Exclusive, PullDown, 0x0000, 0x0000,
				IoRestrictionOutputOnly, "\\_SB.PCI0.I2C2.PMIC",
				0x00, ResourceConsumer,,)
			{
				5
			}
			/* GPIO.9 is XSHUTDOWN pin for world facing camera */
			GpioIo (Exclusive, PullDown, 0x0000, 0x0000,
				IoRestrictionOutputOnly, "\\_SB.PCI0.I2C2.PMIC",
				0x00, ResourceConsumer,,)
			{
				9
			}
		})

		Field (\_SB.PCI0.I2C2.PMIC.GPOP, ByteAcc, NoLock, Preserve)
		{
			Connection
			(
				GpioIo (Exclusive, PullDefault, 0x0000, 0x0000,
					IoRestrictionInputOnly, "\\_SB.PCI0.I2C2.PMIC",
					0x00, ResourceConsumer,,)
				{
					1
				}
			),
			GPO1, 1,
			Connection
			(
				GpioIo (Exclusive, PullDefault, 0x0000, 0x0000,
					IoRestrictionInputOnly, "\\_SB.PCI0.I2C2.PMIC",
					0x00, ResourceConsumer,,)
				{
					2
				}
			),
			GPO2, 1,
			Connection
			(
				GpioIo (Exclusive, PullDown, 0x0000, 0x0000,
					IoRestrictionOutputOnly,
					"\\_SB.PCI0.I2C2.PMIC", 0x00,
					ResourceConsumer,,)
				{
					9
				}
			),
			GRST, 1,
			Connection
			(
				GpioIo (Exclusive, PullDown, 0x0000, 0x0000,
					IoRestrictionOutputOnly,
					"\\_SB.PCI0.I2C2.PMIC", 0x00,
					ResourceConsumer,,)
				{
					4
				}
			),
			GPO4, 1,
			Connection
			(
				GpioIo (Exclusive, PullDown, 0x0000, 0x0000,
					IoRestrictionOutputOnly,
					"\\_SB.PCI0.I2C2.PMIC", 0x00,
					ResourceConsumer,,)
				{
					5
				}
			),
			GPO5, 1,
		}

		/* Set or clear GRST GPIO */
		Method (CRST, 1, Serialized)
		{
			GRST = Arg0
		}

		/* Read GPO1 GPIO, to configure as input */
		Method (CGP1, 0, Serialized)
		{
			Return (GPO1)
		}

		/* Read GPO2 GPIO, to configure as input */
		Method (CGP2, 0, Serialized)
		{
			Return (GPO2)
		}
		/* Set or clear GPO4 GPIO */
		Method (CGP4, 1, Serialized)
		{
			GPO4 = Arg0
		}

		/* Set or clear GPO5 GPIO */
		Method (CGP5, 1, Serialized)
		{
			GPO5 = Arg0
		}
		/* PMIC operation regions */
		/* 0xB0: TI_PMIC_POWER_OPREGION_ID
		 * VSIO: Sensor IO LDO output
		 * VCMC: VCM LDO output
		 * VAX1: Auxiliary LDO1 output
		 * VAX2: Auxiliary LDO2 output
		 * VACT: Analog LDO output
		 * VDCT: Core buck output
		 */
		OperationRegion (PWR1, 0xB0, Zero, 0x0100)
		Field (PWR1, DWordAcc, NoLock, Preserve)
		{
			VSIO, 32,
			VCMC, 32,
			VAX1, 32,
			VAX2, 32,
			VACT, 32,
			VDCT, 32,
		}

		/* 0xB1: TI_PMIC_VR_VAL_OPREGION_ID
		 * SIOV: VSIO VR voltage value
		 * IOVA: VIO VR voltage value
		 * VCMV: VCM VR voltage value
		 * AX1V: Auxiliary LDO1 VR voltage value
		 * AX2V: Auxiliary LDO2 VR voltage value
		 * ACVA: Analog LDO VR voltage
		 * DCVA: Core buck VR volatage
		 */
		OperationRegion (PWR2, 0xB1, Zero, 0x0100)
		Field (PWR2, DWordAcc, NoLock, Preserve)
		{
			SIOV, 32,
			IOVA, 32,
			VCMV, 32,
			AX1V, 32,
			AX2V, 32,
			ACVA, 32,
			DCVA, 32,
		}

		/* 0xB2: TI_PMIC_CLK_OPREGION_ID
		 * PCTL: PLL control register
		 * PCT2: PLL control 2 register
		 * CFG1: Clock configuration 1 register
		 * CFG2: Clock configuration 2 register
		 */
		OperationRegion (CLKC, 0xB2, Zero, 0x0100)
		Field (CLKC, DWordAcc, NoLock, Preserve)
		{
			PCTL, 32,
			PCT2, 32,
			CFG1, 32,
			CFG2, 32,
		}

		/* 0xB3: TI_PMIC_CLK_FREQ_OPREGION_ID
		 * PDV2: PLL output divider for HCLK_B
		 * BODI: PLL output divider for boost clock
		 * BUDI: PLL output divider for buck clock
		 * PSWR: PLL reference clock setting
		 * XTDV: Reference crystal divider
		 * PLDV: PLL feedback divider
		 * PODV: PLL output divider for HCLK_A
		 */
		OperationRegion (CLKF, 0xB3, Zero, 0x0100)
		Field (CLKF, DWordAcc, NoLock, Preserve)
		{
			PDV2, 32,
			BODI, 32,
			BUDI, 32,
			PSWR, 32,
			XTDV, 32,
			PLDV, 32,
			PODV, 32,
		}

		/* CLE0 and CLE1 are used to determine if both the clocks
		are enabled or disabled. */
		Mutex (MUTC, 0)
		Name (CLE0, 0)
		Name (CLE1, 0)
		Method (CLKE, 0, Serialized) {
			/* save Acquire result so we can check for
			Mutex acquired */
			Store (Acquire (MUTC, 1000), Local0)
			/* check for Mutex acquired */
			If (LEqual (Local0, Zero)) {
			/* Enable clocks only when a sensor is turned on and
			both the clocks are disabled */
				If (LNot (LOr (CLE0, CLE1))) {
					/* Set boost clock divider */
					BODI = 3
					/* Set buck clock divider */
					BUDI = 2
					/* Set the PLL_REF_CLK cyles */
					PSWR = 19
					/* Set the reference crystal divider */
					XTDV = 170
					/* Set PLL feedback divider */
					PLDV = 32
					/* Set PLL output divider for HCLK_A */
					PODV = 1
					/* Set PLL output divider for HCLK_B */
					PDV2 = 1
					/* Enable clocks for both the sensors
					 * CFG1: output selection for HCLK_A and
					 * HCLK_B.
					 * CFG2: set drive strength for HCLK_A
					 * and HCLK_B.
					 */
					CFG2 = 5
					CFG1 = 10
					/* Enable PLL output, crystal oscillator
					 * input capacitance control and set
					 * Xtal oscillator as clock source.
					 */
					PCTL = 209
					Sleep(1)
				}
				Release (MUTC)
			}
		}

		/* Clocks need to be disabled only if both the sensors are
		turned off */
		Method (CLKD, 0, Serialized) {
			/* save Acquire result so we can check for
			Mutex acquired */
			Store (Acquire (MUTC, 1000), Local0)
			/* check for Mutex acquired */
			If (LEqual (Local0, Zero)) {
				If (LNot (LOr (CLE0, CLE1))) {
					BODI = 0
					BUDI = 0
					PSWR = 0
					XTDV = 0
					PLDV = 0
					PODV = 0
					PDV2 = 0
					/* Disable clocks for both the
					sensors */
					CFG2 = 0
					CFG1 = 0
					PCTL = 0
				}
				Release (MUTC)
			}
		}

		/* Reference count for VSIO */
		Name (VSIC, 0)
		Method (DOVD, 1, Serialized) {
			/* Turn off VSIO */
			If (LEqual (Arg0, Zero)) {
				/* Decrement only if VSIC > 0 */
				if (LGreater (VSIC, 0)) {
					Decrement (VSIC)
					If (LEqual (VSIC, Zero)) {
						VSIO = 0
						Sleep(1)
						PMOF()
					}
				}
			} ElseIf (LEqual (Arg0, 1)) {
				/* Increment only if VSIC < 4 */
				If (LLess (VSIC, 4)) {
					/* Turn on VSIO */
					If (LEqual (VSIC, Zero)) {
						PMON()
						VSIO = 3

						if (LNotEqual (IOVA, 52)) {
							/* Set VSIO value as
							1.8006 V */
							IOVA = 52
						}
						if (LNotEqual (SIOV, 52)) {
							/* Set VSIO value as
							1.8006 V */
							SIOV = 52
						}
						Sleep(3)
					}
					Increment (VSIC)
				}
			}
		}

		/* Power resource methods for CAM0 */
		PowerResource (OVTH, 0, 0) {
			Name (STA, 0)
			Method (_ON, 0, Serialized) {
				/* TODO: Read Voltage and Sleep values from Sensor Obj */
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 0)) {
						/* Enable VSIO regulator +
						daisy chain */
						DOVD(1)

						\_SB.PCI0.I2C2.PMIC.CGP1()
						\_SB.PCI0.I2C2.PMIC.CGP2()

						/* Set ANA at 2.8152V */
						ACVA = 109
						VACT = 1

						/* Set CORE at 1.2V */
						DCVA = 12
						VDCT = 1

						\_SB.PCI0.I2C2.PMIC.CLKE()
						CLE0 = 1

						/*
						 * Wait for all regulator
						 * outputs to settle.
						 */
						Sleep(1)

						\_SB.PCI0.I2C2.PMIC.CRST(1)

						/*
						 * 5 ms needed before
						 * streaming on.
						 */
						Sleep(5)

						STA = 1
					}
				}
			}

			Method (_OFF, 0, Serialized) {
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 1)) {
						Sleep(2)
						CLE0 = 0
						\_SB.PCI0.I2C2.PMIC.CLKD()
						Sleep(2)
						\_SB.PCI0.I2C2.PMIC.CRST(0)
						Sleep(3)
						VDCT = 0
						Sleep(3)
						VACT = 0
						Sleep(1)
						DOVD(0)
					}
				}
				STA = 0
			}
			Method (_STA, 0, NotSerialized) {
				Return (STA)
			}
		}

		/* Power resource methods for CAM1 */
		PowerResource (OVFI, 0, 0) {
			Name (STA, 0)
			Method (_ON, 0, Serialized) {
				/* TODO: Read Voltage and Sleep values from Sensor Obj */
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 0)) {
						/* Enable VSIO regulator +
						daisy chain */
						DOVD(1)

						/* Set VAUX2 as 1.8006 V */
						AX2V = 52
						VAX2 = 1 /* Enable VAUX2 */

						\_SB.PCI0.I2C2.PMIC.CGP4(1)

						/*
						 * Wait for DOVDD and AVDD
						 * to settle.
						 */
						Sleep(1)

						/* Set VAUX1 as 1.2132V */
						AX1V = 19
						VAX1 = 1 /* Enable VAUX1 */

						/* Wait for VDD to settle. */
						Sleep(1)

						\_SB.PCI0.I2C2.PMIC.CLKE()
						CLE1 = 1

						\_SB.PCI0.I2C2.PMIC.CGP5(1)
						/*
						 * Ensure 10 ms between
						 * power-up and streamon.
						 */
						Sleep(10)
						STA = 1
					}
				}
			}

			Method (_OFF, 0, Serialized) {
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 1)) {
						Sleep(2)
						CLE1 = 0
						\_SB.PCI0.I2C2.PMIC.CLKD()
						Sleep(2)
						\_SB.PCI0.I2C2.PMIC.CGP5(0)
						Sleep(3)
						VAX1 = 0
						Sleep(1)
						\_SB.PCI0.I2C2.PMIC.CGP4(0)
						Sleep(1)
						VAX2 = 0
						Sleep(1)
						DOVD(0)
					}
					STA = 0
				}
			}

			Method (_STA, 0, NotSerialized) {
				Return (STA)
			}
		}

		/* Power resource methods for VCM */
		PowerResource (VCMP, 0, 0) {
			Name (STA, 0)
			Method (_ON, 0, Serialized) {
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 0)) {
						/* Enable VSIO regulator +
						daisy chain */
						DOVD(1)

						/* Enable VCM regulator */
						VCMC = 1
						/* Set VCM value at 2.8152 V */
						VCMV = 109
						Sleep(3)

						STA = 1
					}
				}
			}

			Method (_OFF, 0, Serialized) {
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 1)) {
						VCMC = 0 /* Disable regulator */
						Sleep(1)
						DOVD(0) /* Disable regulator */
						STA = 0
					}
				}
			}

			Method (_STA, 0, NotSerialized) {
				Return (STA)
			}
		}

		/* Power resource methods for NVM */
		PowerResource (NVMP, 0, 0) {
			Name (STA, 0)
			Method (_ON, 0, Serialized) {
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 0)) {
						/* Enable VSIO regulator +
						daisy chain */
						DOVD(1)
						STA = 1
					}
				}
			}

			Method (_OFF, 0, Serialized) {
				If (LEqual (AVBL, 1)) {
					If (LEqual (STA, 1)) {
						DOVD(0) /* Disable regulator */
						STA = 0
					}
				}
			}

			Method (_STA, 0, NotSerialized) {
				Return (STA)
			}
		}
	}

}