2 * AB8500 system control driver
4 * Copyright (C) ST-Ericsson SA 2010
5 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com> for ST Ericsson.
6 * License terms: GNU General Public License (GPL) version 2
10 #include <linux/init.h>
11 #include <linux/export.h>
12 #include <linux/platform_device.h>
14 #include <linux/reboot.h>
15 #include <linux/signal.h>
16 #include <linux/power_supply.h>
17 #include <linux/mfd/abx500.h>
18 #include <linux/mfd/abx500/ab8500.h>
19 #include <linux/mfd/abx500/ab8500-sysctrl.h>
22 #define AB8500_ALARM_MIN_LOW 0x08
23 #define AB8500_ALARM_MIN_MID 0x09
25 #define RTC_ALARM_ENABLE 0x4
27 static struct device
*sysctrl_dev
;
29 static void ab8500_power_off(void)
33 static const char * const pss
[] = {"ab8500_ac", "pm2301", "ab8500_usb"};
35 bool charger_present
= false;
36 union power_supply_propval val
;
37 struct power_supply
*psy
;
40 if (sysctrl_dev
== NULL
) {
41 pr_err("%s: sysctrl not initialized\n", __func__
);
46 * If we have a charger connected and we're powering off,
47 * reboot into charge-only mode.
50 for (i
= 0; i
< ARRAY_SIZE(pss
); i
++) {
51 psy
= power_supply_get_by_name(pss
[i
]);
55 ret
= power_supply_get_property(psy
, POWER_SUPPLY_PROP_ONLINE
,
57 power_supply_put(psy
);
59 if (!ret
&& val
.intval
) {
60 charger_present
= true;
68 /* Check if battery is known */
69 psy
= power_supply_get_by_name("ab8500_btemp");
71 ret
= power_supply_get_property(psy
,
72 POWER_SUPPLY_PROP_TECHNOLOGY
, &val
);
73 if (!ret
&& val
.intval
!= POWER_SUPPLY_TECHNOLOGY_UNKNOWN
) {
74 pr_info("Charger '%s' is connected with known battery",
76 pr_info(" - Rebooting.\n");
77 machine_restart("charging");
79 power_supply_put(psy
);
85 if (!sigprocmask(SIG_BLOCK
, &all
, &old
)) {
86 (void)ab8500_sysctrl_set(AB8500_STW4500CTRL1
,
87 AB8500_STW4500CTRL1_SWOFF
|
88 AB8500_STW4500CTRL1_SWRESET4500N
);
89 (void)sigprocmask(SIG_SETMASK
, &old
, NULL
);
93 static inline bool valid_bank(u8 bank
)
95 return ((bank
== AB8500_SYS_CTRL1_BLOCK
) ||
96 (bank
== AB8500_SYS_CTRL2_BLOCK
));
99 int ab8500_sysctrl_read(u16 reg
, u8
*value
)
103 if (sysctrl_dev
== NULL
)
107 if (!valid_bank(bank
))
110 return abx500_get_register_interruptible(sysctrl_dev
, bank
,
111 (u8
)(reg
& 0xFF), value
);
113 EXPORT_SYMBOL(ab8500_sysctrl_read
);
115 int ab8500_sysctrl_write(u16 reg
, u8 mask
, u8 value
)
119 if (sysctrl_dev
== NULL
)
123 if (!valid_bank(bank
))
126 return abx500_mask_and_set_register_interruptible(sysctrl_dev
, bank
,
127 (u8
)(reg
& 0xFF), mask
, value
);
129 EXPORT_SYMBOL(ab8500_sysctrl_write
);
131 static int ab8500_sysctrl_probe(struct platform_device
*pdev
)
133 sysctrl_dev
= &pdev
->dev
;
136 pm_power_off
= ab8500_power_off
;
141 static int ab8500_sysctrl_remove(struct platform_device
*pdev
)
145 if (pm_power_off
== ab8500_power_off
)
151 static struct platform_driver ab8500_sysctrl_driver
= {
153 .name
= "ab8500-sysctrl",
155 .probe
= ab8500_sysctrl_probe
,
156 .remove
= ab8500_sysctrl_remove
,
159 static int __init
ab8500_sysctrl_init(void)
161 return platform_driver_register(&ab8500_sysctrl_driver
);
163 arch_initcall(ab8500_sysctrl_init
);