2 * Copyright (C) ST-Ericsson SA 2010
3 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> for ST Ericsson.
4 * License terms: GNU General Public License (GPL) version 2
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
11 #include <linux/reboot.h>
12 #include <linux/signal.h>
13 #include <linux/power_supply.h>
14 #include <linux/mfd/abx500.h>
15 #include <linux/mfd/abx500/ab8500.h>
16 #include <linux/mfd/abx500/ab8500-sysctrl.h>
19 #define AB8500_ALARM_MIN_LOW 0x08
20 #define AB8500_ALARM_MIN_MID 0x09
22 #define RTC_ALARM_ENABLE 0x4
24 static struct device
*sysctrl_dev
;
26 static void ab8500_power_off(void)
30 static char *pss
[] = {"ab8500_ac", "pm2301", "ab8500_usb"};
32 bool charger_present
= false;
33 union power_supply_propval val
;
34 struct power_supply
*psy
;
37 if (sysctrl_dev
== NULL
) {
38 pr_err("%s: sysctrl not initialized\n", __func__
);
43 * If we have a charger connected and we're powering off,
44 * reboot into charge-only mode.
47 for (i
= 0; i
< ARRAY_SIZE(pss
); i
++) {
48 psy
= power_supply_get_by_name(pss
[i
]);
52 ret
= power_supply_get_property(psy
, POWER_SUPPLY_PROP_ONLINE
,
54 power_supply_put(psy
);
56 if (!ret
&& val
.intval
) {
57 charger_present
= true;
65 /* Check if battery is known */
66 psy
= power_supply_get_by_name("ab8500_btemp");
68 ret
= power_supply_get_property(psy
,
69 POWER_SUPPLY_PROP_TECHNOLOGY
, &val
);
70 if (!ret
&& val
.intval
!= POWER_SUPPLY_TECHNOLOGY_UNKNOWN
) {
72 "Charger \"%s\" is connected with known battery."
75 machine_restart("charging");
77 power_supply_put(psy
);
83 if (!sigprocmask(SIG_BLOCK
, &all
, &old
)) {
84 (void)ab8500_sysctrl_set(AB8500_STW4500CTRL1
,
85 AB8500_STW4500CTRL1_SWOFF
|
86 AB8500_STW4500CTRL1_SWRESET4500N
);
87 (void)sigprocmask(SIG_SETMASK
, &old
, NULL
);
91 static inline bool valid_bank(u8 bank
)
93 return ((bank
== AB8500_SYS_CTRL1_BLOCK
) ||
94 (bank
== AB8500_SYS_CTRL2_BLOCK
));
97 int ab8500_sysctrl_read(u16 reg
, u8
*value
)
101 if (sysctrl_dev
== NULL
)
105 if (!valid_bank(bank
))
108 return abx500_get_register_interruptible(sysctrl_dev
, bank
,
109 (u8
)(reg
& 0xFF), value
);
111 EXPORT_SYMBOL(ab8500_sysctrl_read
);
113 int ab8500_sysctrl_write(u16 reg
, u8 mask
, u8 value
)
117 if (sysctrl_dev
== NULL
)
121 if (!valid_bank(bank
))
124 return abx500_mask_and_set_register_interruptible(sysctrl_dev
, bank
,
125 (u8
)(reg
& 0xFF), mask
, value
);
127 EXPORT_SYMBOL(ab8500_sysctrl_write
);
129 static int ab8500_sysctrl_probe(struct platform_device
*pdev
)
131 struct ab8500
*ab8500
= dev_get_drvdata(pdev
->dev
.parent
);
132 struct ab8500_platform_data
*plat
;
133 struct ab8500_sysctrl_platform_data
*pdata
;
135 plat
= dev_get_platdata(pdev
->dev
.parent
);
140 sysctrl_dev
= &pdev
->dev
;
143 pm_power_off
= ab8500_power_off
;
145 pdata
= plat
->sysctrl
;
149 if (is_ab8505(ab8500
))
150 last
= AB8500_SYSCLKREQ4RFCLKBUF
;
152 last
= AB8500_SYSCLKREQ8RFCLKBUF
;
154 for (i
= AB8500_SYSCLKREQ1RFCLKBUF
; i
<= last
; i
++) {
155 j
= i
- AB8500_SYSCLKREQ1RFCLKBUF
;
156 ret
= ab8500_sysctrl_write(i
, 0xff,
157 pdata
->initial_req_buf_config
[j
]);
159 "Setting SysClkReq%dRfClkBuf 0x%X\n",
161 pdata
->initial_req_buf_config
[j
]);
164 "unable to set sysClkReq%dRfClkBuf: "
173 static int ab8500_sysctrl_remove(struct platform_device
*pdev
)
177 if (pm_power_off
== ab8500_power_off
)
183 static struct platform_driver ab8500_sysctrl_driver
= {
185 .name
= "ab8500-sysctrl",
187 .probe
= ab8500_sysctrl_probe
,
188 .remove
= ab8500_sysctrl_remove
,
191 static int __init
ab8500_sysctrl_init(void)
193 return platform_driver_register(&ab8500_sysctrl_driver
);
195 arch_initcall(ab8500_sysctrl_init
);
197 MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com");
198 MODULE_DESCRIPTION("AB8500 system control driver");
199 MODULE_LICENSE("GPL v2");