xref: /linux/drivers/mfd/ucb1x00-assabet.c (revision 54292a4649a5dd93562d10f188a8e201afebfe2f)
148c92022SRussell King /*
248c92022SRussell King  *  linux/drivers/mfd/ucb1x00-assabet.c
348c92022SRussell King  *
448c92022SRussell King  *  Copyright (C) 2001-2003 Russell King, All Rights Reserved.
548c92022SRussell King  *
648c92022SRussell King  * This program is free software; you can redistribute it and/or modify
748c92022SRussell King  * it under the terms of the GNU General Public License as published by
848c92022SRussell King  * the Free Software Foundation; either version 2 of the License.
948c92022SRussell King  *
1048c92022SRussell King  *  We handle the machine-specific bits of the UCB1x00 driver here.
1148c92022SRussell King  */
1248c92022SRussell King #include <linux/module.h>
1348c92022SRussell King #include <linux/init.h>
1448c92022SRussell King #include <linux/device.h>
15*54292a46SRussell King #include <linux/err.h>
16*54292a46SRussell King #include <linux/fs.h>
17*54292a46SRussell King #include <linux/gpio_keys.h>
18*54292a46SRussell King #include <linux/input.h>
19*54292a46SRussell King #include <linux/platform_device.h>
20*54292a46SRussell King #include <linux/proc_fs.h>
21c8602edfSThomas Kunze #include <linux/mfd/ucb1x00.h>
2248c92022SRussell King 
2348c92022SRussell King #define UCB1X00_ATTR(name,input)\
24cd4c1eb5SRussell King static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
250c55445fSTony Jones 			   char *buf)	\
2648c92022SRussell King {								\
2748c92022SRussell King 	struct ucb1x00 *ucb = classdev_to_ucb1x00(dev);		\
2848c92022SRussell King 	int val;						\
2948c92022SRussell King 	ucb1x00_adc_enable(ucb);				\
3048c92022SRussell King 	val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC);		\
3148c92022SRussell King 	ucb1x00_adc_disable(ucb);				\
3248c92022SRussell King 	return sprintf(buf, "%d\n", val);			\
3348c92022SRussell King }								\
340c55445fSTony Jones static DEVICE_ATTR(name,0444,name##_show,NULL)
3548c92022SRussell King 
3648c92022SRussell King UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
3748c92022SRussell King UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
3848c92022SRussell King UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
3948c92022SRussell King 
4048c92022SRussell King static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
4148c92022SRussell King {
42*54292a46SRussell King 	struct ucb1x00 *ucb = dev->ucb;
43*54292a46SRussell King 	struct platform_device *pdev;
44*54292a46SRussell King 	struct gpio_keys_platform_data keys;
45*54292a46SRussell King 	static struct gpio_keys_button buttons[6];
46*54292a46SRussell King 	unsigned i;
47*54292a46SRussell King 
48*54292a46SRussell King 	memset(buttons, 0, sizeof(buttons));
49*54292a46SRussell King 	memset(&keys, 0, sizeof(keys));
50*54292a46SRussell King 
51*54292a46SRussell King 	for (i = 0; i < ARRAY_SIZE(buttons); i++) {
52*54292a46SRussell King 		buttons[i].code = BTN_0 + i;
53*54292a46SRussell King 		buttons[i].gpio = ucb->gpio.base + i;
54*54292a46SRussell King 		buttons[i].type = EV_KEY;
55*54292a46SRussell King 		buttons[i].can_disable = true;
56*54292a46SRussell King 	}
57*54292a46SRussell King 
58*54292a46SRussell King 	keys.buttons = buttons;
59*54292a46SRussell King 	keys.nbuttons = ARRAY_SIZE(buttons);
60*54292a46SRussell King 	keys.poll_interval = 50;
61*54292a46SRussell King 	keys.name = "ucb1x00";
62*54292a46SRussell King 
63*54292a46SRussell King 	pdev = platform_device_register_data(&ucb->dev, "gpio-keys", -1,
64*54292a46SRussell King 		&keys, sizeof(keys));
65*54292a46SRussell King 
66*54292a46SRussell King 	device_create_file(&ucb->dev, &dev_attr_vbatt);
67*54292a46SRussell King 	device_create_file(&ucb->dev, &dev_attr_vcharger);
68*54292a46SRussell King 	device_create_file(&ucb->dev, &dev_attr_batt_temp);
69*54292a46SRussell King 
70*54292a46SRussell King 	dev->priv = pdev;
7148c92022SRussell King 	return 0;
7248c92022SRussell King }
7348c92022SRussell King 
7448c92022SRussell King static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
7548c92022SRussell King {
76*54292a46SRussell King 	struct platform_device *pdev = dev->priv;
77*54292a46SRussell King 
78*54292a46SRussell King 	if (!IS_ERR(pdev))
79*54292a46SRussell King 		platform_device_unregister(pdev);
80*54292a46SRussell King 
81cd4c1eb5SRussell King 	device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp);
82cd4c1eb5SRussell King 	device_remove_file(&dev->ucb->dev, &dev_attr_vcharger);
83cd4c1eb5SRussell King 	device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
8448c92022SRussell King }
8548c92022SRussell King 
8648c92022SRussell King static struct ucb1x00_driver ucb1x00_assabet_driver = {
8748c92022SRussell King 	.add	= ucb1x00_assabet_add,
8848c92022SRussell King 	.remove	= ucb1x00_assabet_remove,
8948c92022SRussell King };
9048c92022SRussell King 
9148c92022SRussell King static int __init ucb1x00_assabet_init(void)
9248c92022SRussell King {
9348c92022SRussell King 	return ucb1x00_register_driver(&ucb1x00_assabet_driver);
9448c92022SRussell King }
9548c92022SRussell King 
9648c92022SRussell King static void __exit ucb1x00_assabet_exit(void)
9748c92022SRussell King {
9848c92022SRussell King 	ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
9948c92022SRussell King }
10048c92022SRussell King 
10148c92022SRussell King module_init(ucb1x00_assabet_init);
10248c92022SRussell King module_exit(ucb1x00_assabet_exit);
10348c92022SRussell King 
10448c92022SRussell King MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
10548c92022SRussell King MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
10648c92022SRussell King MODULE_LICENSE("GPL");
107