2 * intel_pmic_bxtwc.c - Intel BXT WhiskeyCove PMIC operation region driver
4 * Copyright (C) 2015 Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/init.h>
17 #include <linux/acpi.h>
18 #include <linux/mfd/intel_soc_pmic.h>
19 #include <linux/regmap.h>
20 #include <linux/platform_device.h>
21 #include "intel_pmic.h"
23 #define WHISKEY_COVE_ALRT_HIGH_BIT_MASK 0x0F
24 #define WHISKEY_COVE_ADC_HIGH_BIT(x) (((x & 0x0F) << 8))
25 #define WHISKEY_COVE_ADC_CURSRC(x) (((x & 0xF0) >> 4))
26 #define VR_MODE_DISABLED 0
27 #define VR_MODE_AUTO BIT(0)
28 #define VR_MODE_NORMAL BIT(1)
29 #define VR_MODE_SWITCH BIT(2)
30 #define VR_MODE_ECO (BIT(0)|BIT(1))
31 #define VSWITCH2_OUTPUT BIT(5)
32 #define VSWITCH1_OUTPUT BIT(4)
33 #define VUSBPHY_CHARGE BIT(1)
35 static struct pmic_table power_table
[] = {
40 }, /* VDD1 -> VDD1CNT */
45 }, /* VDD2 -> VDD2CNT */
50 }, /* VDD3 -> VDD3CNT */
55 }, /* VLFX -> VFLEXCNT */
59 .bit
= VR_MODE_NORMAL
,
60 }, /* VP1A -> VPROG1ACNT */
64 .bit
= VR_MODE_NORMAL
,
65 }, /* VP1B -> VPROG1BCNT */
69 .bit
= VR_MODE_NORMAL
,
70 }, /* VP1C -> VPROG1CCNT */
74 .bit
= VR_MODE_NORMAL
,
75 }, /* VP1D -> VPROG1DCNT */
79 .bit
= VR_MODE_NORMAL
,
80 }, /* VP2A -> VPROG2ACNT */
84 .bit
= VR_MODE_NORMAL
,
85 }, /* VP2B -> VPROG2BCNT */
89 .bit
= VR_MODE_NORMAL
,
90 }, /* VP2C -> VPROG2CCNT */
94 .bit
= VR_MODE_NORMAL
,
95 }, /* VP3A -> VPROG3ACNT */
99 .bit
= VR_MODE_NORMAL
,
100 }, /* VP3B -> VPROG3BCNT */
104 .bit
= VSWITCH2_OUTPUT
,
105 }, /* VSW2 -> VLD0CNT Bit 5*/
109 .bit
= VSWITCH1_OUTPUT
,
110 }, /* VSW1 -> VLD0CNT Bit 4 */
114 .bit
= VUSBPHY_CHARGE
,
115 }, /* VUPY -> VLDOCNT Bit 1 */
119 .bit
= VR_MODE_NORMAL
,
120 }, /* VRSO -> VREFSOCCNT*/
124 .bit
= VR_MODE_NORMAL
,
125 }, /* VP1E -> VPROG1ECNT */
129 .bit
= VR_MODE_NORMAL
,
130 }, /* VP1F -> VPROG1FCNT */
134 .bit
= VR_MODE_NORMAL
,
135 }, /* VP2D -> VPROG2DCNT */
139 .bit
= VR_MODE_NORMAL
,
140 }, /* VP4A -> VPROG4ACNT */
144 .bit
= VR_MODE_NORMAL
,
145 }, /* VP4B -> VPROG4BCNT */
149 .bit
= VR_MODE_NORMAL
,
150 }, /* VP4C -> VPROG4CCNT */
154 .bit
= VR_MODE_NORMAL
,
155 }, /* VP4D -> VPROG4DCNT */
159 .bit
= VR_MODE_NORMAL
,
160 }, /* VP5A -> VPROG5ACNT */
164 .bit
= VR_MODE_NORMAL
,
165 }, /* VP5B -> VPROG5BCNT */
169 .bit
= VR_MODE_NORMAL
,
170 }, /* VP6A -> VPROG6ACNT */
174 .bit
= VR_MODE_NORMAL
,
175 }, /* VP6B -> VPROG6BCNT */
180 }, /* SDWN_N -> MODEMCTRL Bit 2 */
185 } /* MOFF -> MODEMCTRL Bit 0 */
188 static struct pmic_table thermal_table
[] = {
281 static int intel_bxtwc_pmic_get_power(struct regmap
*regmap
, int reg
,
286 if (regmap_read(regmap
, reg
, &data
))
289 *value
= (data
& bit
) ? 1 : 0;
293 static int intel_bxtwc_pmic_update_power(struct regmap
*regmap
, int reg
,
303 return regmap_update_bits(regmap
, reg
, mask
, val
);
306 static int intel_bxtwc_pmic_get_raw_temp(struct regmap
*regmap
, int reg
)
308 unsigned int val
, adc_val
, reg_val
;
309 u8 temp_l
, temp_h
, cursrc
;
311 static const unsigned long rlsb_array
[] = {
312 0, 260420, 130210, 65100, 32550, 16280,
313 8140, 4070, 2030, 0, 260420, 130210 };
315 if (regmap_read(regmap
, reg
, &val
))
319 if (regmap_read(regmap
, (reg
- 1), &val
))
323 reg_val
= temp_l
| WHISKEY_COVE_ADC_HIGH_BIT(temp_h
);
324 cursrc
= WHISKEY_COVE_ADC_CURSRC(temp_h
);
325 rlsb
= rlsb_array
[cursrc
];
326 adc_val
= reg_val
* rlsb
/ 1000;
332 intel_bxtwc_pmic_update_aux(struct regmap
*regmap
, int reg
, int raw
)
335 u16 resi_val
, count
= 0, thrsh
= 0;
336 u8 alrt_h
, alrt_l
, cursel
= 0;
341 count
= fls(bsr_num
) - 1;
343 cursel
= clamp_t(s8
, (count
- 7), 0, 7);
344 thrsh
= raw
/ (1 << (4 + cursel
));
346 resi_val
= (cursel
<< 9) | thrsh
;
347 alrt_h
= (resi_val
>> 8) & WHISKEY_COVE_ALRT_HIGH_BIT_MASK
;
348 if (regmap_update_bits(regmap
,
350 WHISKEY_COVE_ALRT_HIGH_BIT_MASK
,
354 alrt_l
= (u8
)resi_val
;
355 return regmap_write(regmap
, reg
, alrt_l
);
359 intel_bxtwc_pmic_get_policy(struct regmap
*regmap
, int reg
, int bit
, u64
*value
)
364 if (regmap_read(regmap
, reg
, &val
))
367 *value
= (val
& mask
) >> bit
;
372 intel_bxtwc_pmic_update_policy(struct regmap
*regmap
,
373 int reg
, int bit
, int enable
)
375 u8 mask
= BIT(bit
), val
= enable
<< bit
;
377 return regmap_update_bits(regmap
, reg
, mask
, val
);
380 static struct intel_pmic_opregion_data intel_bxtwc_pmic_opregion_data
= {
381 .get_power
= intel_bxtwc_pmic_get_power
,
382 .update_power
= intel_bxtwc_pmic_update_power
,
383 .get_raw_temp
= intel_bxtwc_pmic_get_raw_temp
,
384 .update_aux
= intel_bxtwc_pmic_update_aux
,
385 .get_policy
= intel_bxtwc_pmic_get_policy
,
386 .update_policy
= intel_bxtwc_pmic_update_policy
,
387 .power_table
= power_table
,
388 .power_table_count
= ARRAY_SIZE(power_table
),
389 .thermal_table
= thermal_table
,
390 .thermal_table_count
= ARRAY_SIZE(thermal_table
),
393 static int intel_bxtwc_pmic_opregion_probe(struct platform_device
*pdev
)
395 struct intel_soc_pmic
*pmic
= dev_get_drvdata(pdev
->dev
.parent
);
397 return intel_pmic_install_opregion_handler(&pdev
->dev
,
398 ACPI_HANDLE(pdev
->dev
.parent
),
400 &intel_bxtwc_pmic_opregion_data
);
403 static struct platform_device_id bxt_wc_opregion_id_table
[] = {
404 { .name
= "bxt_wcove_region" },
408 static struct platform_driver intel_bxtwc_pmic_opregion_driver
= {
409 .probe
= intel_bxtwc_pmic_opregion_probe
,
411 .name
= "bxt_whiskey_cove_pmic",
413 .id_table
= bxt_wc_opregion_id_table
,
416 static int __init
intel_bxtwc_pmic_opregion_driver_init(void)
418 return platform_driver_register(&intel_bxtwc_pmic_opregion_driver
);
420 device_initcall(intel_bxtwc_pmic_opregion_driver_init
);