blob: b7be613cb503a643ca448141e167a30f84c60fd9 [file] [log] [blame]
Russell King48c92022005-09-11 10:27:23 +01001/*
2 * linux/drivers/mfd/ucb1x00-assabet.c
3 *
4 * Copyright (C) 2001-2003 Russell King, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
9 *
10 * We handle the machine-specific bits of the UCB1x00 driver here.
11 */
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/fs.h>
15#include <linux/proc_fs.h>
16#include <linux/device.h>
Thomas Kunzec8602ed2009-02-10 14:54:57 +010017#include <linux/mfd/ucb1x00.h>
Russell King48c92022005-09-11 10:27:23 +010018
Russell King48c92022005-09-11 10:27:23 +010019#define UCB1X00_ATTR(name,input)\
Russell Kingcd4c1eb2008-01-28 10:59:09 +000020static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
Tony Jones0c554452007-09-25 02:03:03 +020021 char *buf) \
Russell King48c92022005-09-11 10:27:23 +010022{ \
23 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
24 int val; \
25 ucb1x00_adc_enable(ucb); \
26 val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC); \
27 ucb1x00_adc_disable(ucb); \
28 return sprintf(buf, "%d\n", val); \
29} \
Tony Jones0c554452007-09-25 02:03:03 +020030static DEVICE_ATTR(name,0444,name##_show,NULL)
Russell King48c92022005-09-11 10:27:23 +010031
32UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
33UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
34UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
35
36static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
37{
Russell Kingcd4c1eb2008-01-28 10:59:09 +000038 device_create_file(&dev->ucb->dev, &dev_attr_vbatt);
39 device_create_file(&dev->ucb->dev, &dev_attr_vcharger);
40 device_create_file(&dev->ucb->dev, &dev_attr_batt_temp);
Russell King48c92022005-09-11 10:27:23 +010041 return 0;
42}
43
44static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
45{
Russell Kingcd4c1eb2008-01-28 10:59:09 +000046 device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp);
47 device_remove_file(&dev->ucb->dev, &dev_attr_vcharger);
48 device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
Russell King48c92022005-09-11 10:27:23 +010049}
50
51static struct ucb1x00_driver ucb1x00_assabet_driver = {
52 .add = ucb1x00_assabet_add,
53 .remove = ucb1x00_assabet_remove,
54};
55
56static int __init ucb1x00_assabet_init(void)
57{
58 return ucb1x00_register_driver(&ucb1x00_assabet_driver);
59}
60
61static void __exit ucb1x00_assabet_exit(void)
62{
63 ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
64}
65
66module_init(ucb1x00_assabet_init);
67module_exit(ucb1x00_assabet_exit);
68
69MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
70MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
71MODULE_LICENSE("GPL");