Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 1 | /* |
| 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 |
| 5 | */ |
| 6 | |
| 7 | #include <linux/err.h> |
Paul Gortmaker | 4e36dd3 | 2011-07-03 15:13:27 -0400 | [diff] [blame] | 8 | #include <linux/module.h> |
Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 9 | #include <linux/platform_device.h> |
Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 10 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 11 | #include <linux/mfd/abx500/ab8500.h> |
| 12 | #include <linux/mfd/abx500/ab8500-sysctrl.h> |
Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 13 | |
| 14 | static struct device *sysctrl_dev; |
| 15 | |
| 16 | static inline bool valid_bank(u8 bank) |
| 17 | { |
| 18 | return ((bank == AB8500_SYS_CTRL1_BLOCK) || |
| 19 | (bank == AB8500_SYS_CTRL2_BLOCK)); |
| 20 | } |
| 21 | |
| 22 | int ab8500_sysctrl_read(u16 reg, u8 *value) |
| 23 | { |
| 24 | u8 bank; |
| 25 | |
| 26 | if (sysctrl_dev == NULL) |
| 27 | return -EAGAIN; |
| 28 | |
| 29 | bank = (reg >> 8); |
| 30 | if (!valid_bank(bank)) |
| 31 | return -EINVAL; |
| 32 | |
| 33 | return abx500_get_register_interruptible(sysctrl_dev, bank, |
| 34 | (u8)(reg & 0xFF), value); |
| 35 | } |
| 36 | |
| 37 | int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value) |
| 38 | { |
| 39 | u8 bank; |
| 40 | |
| 41 | if (sysctrl_dev == NULL) |
| 42 | return -EAGAIN; |
| 43 | |
| 44 | bank = (reg >> 8); |
| 45 | if (!valid_bank(bank)) |
| 46 | return -EINVAL; |
| 47 | |
| 48 | return abx500_mask_and_set_register_interruptible(sysctrl_dev, bank, |
| 49 | (u8)(reg & 0xFF), mask, value); |
| 50 | } |
| 51 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 52 | static int ab8500_sysctrl_probe(struct platform_device *pdev) |
Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 53 | { |
| 54 | sysctrl_dev = &pdev->dev; |
| 55 | return 0; |
| 56 | } |
| 57 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 58 | static int ab8500_sysctrl_remove(struct platform_device *pdev) |
Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 59 | { |
| 60 | sysctrl_dev = NULL; |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static struct platform_driver ab8500_sysctrl_driver = { |
| 65 | .driver = { |
| 66 | .name = "ab8500-sysctrl", |
| 67 | .owner = THIS_MODULE, |
Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 68 | }, |
| 69 | .probe = ab8500_sysctrl_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 70 | .remove = ab8500_sysctrl_remove, |
Mattias Nilsson | 90550d1 | 2011-02-14 11:17:12 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | static int __init ab8500_sysctrl_init(void) |
| 74 | { |
| 75 | return platform_driver_register(&ab8500_sysctrl_driver); |
| 76 | } |
| 77 | subsys_initcall(ab8500_sysctrl_init); |
| 78 | |
| 79 | MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com"); |
| 80 | MODULE_DESCRIPTION("AB8500 system control driver"); |
| 81 | MODULE_LICENSE("GPL v2"); |