184a14ae8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
248c92022SRussell King /*
348c92022SRussell King * linux/drivers/mfd/ucb1x00-assabet.c
448c92022SRussell King *
548c92022SRussell King * Copyright (C) 2001-2003 Russell King, All Rights Reserved.
648c92022SRussell King *
748c92022SRussell King * We handle the machine-specific bits of the UCB1x00 driver here.
848c92022SRussell King */
948c92022SRussell King #include <linux/module.h>
1048c92022SRussell King #include <linux/init.h>
1148c92022SRussell King #include <linux/device.h>
1254292a46SRussell King #include <linux/err.h>
1354292a46SRussell King #include <linux/fs.h>
1454292a46SRussell King #include <linux/gpio_keys.h>
1554292a46SRussell King #include <linux/input.h>
1654292a46SRussell King #include <linux/platform_device.h>
1754292a46SRussell King #include <linux/proc_fs.h>
18c8602edfSThomas Kunze #include <linux/mfd/ucb1x00.h>
1948c92022SRussell King
2048c92022SRussell King #define UCB1X00_ATTR(name,input)\
21cd4c1eb5SRussell King static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
220c55445fSTony Jones char *buf) \
2348c92022SRussell King { \
2448c92022SRussell King struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
2548c92022SRussell King int val; \
2648c92022SRussell King ucb1x00_adc_enable(ucb); \
2748c92022SRussell King val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC); \
2848c92022SRussell King ucb1x00_adc_disable(ucb); \
2948c92022SRussell King return sprintf(buf, "%d\n", val); \
3048c92022SRussell King } \
31*47ed390bSZhen Lei static DEVICE_ATTR_RO(name)
3248c92022SRussell King
3348c92022SRussell King UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
3448c92022SRussell King UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
3548c92022SRussell King UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
3648c92022SRussell King
ucb1x00_assabet_add(struct ucb1x00_dev * dev)3748c92022SRussell King static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
3848c92022SRussell King {
3954292a46SRussell King struct ucb1x00 *ucb = dev->ucb;
4054292a46SRussell King struct platform_device *pdev;
4154292a46SRussell King struct gpio_keys_platform_data keys;
4254292a46SRussell King static struct gpio_keys_button buttons[6];
4354292a46SRussell King unsigned i;
4454292a46SRussell King
4554292a46SRussell King memset(buttons, 0, sizeof(buttons));
4654292a46SRussell King memset(&keys, 0, sizeof(keys));
4754292a46SRussell King
4854292a46SRussell King for (i = 0; i < ARRAY_SIZE(buttons); i++) {
4954292a46SRussell King buttons[i].code = BTN_0 + i;
5054292a46SRussell King buttons[i].gpio = ucb->gpio.base + i;
5154292a46SRussell King buttons[i].type = EV_KEY;
5254292a46SRussell King buttons[i].can_disable = true;
5354292a46SRussell King }
5454292a46SRussell King
5554292a46SRussell King keys.buttons = buttons;
5654292a46SRussell King keys.nbuttons = ARRAY_SIZE(buttons);
5754292a46SRussell King keys.poll_interval = 50;
5854292a46SRussell King keys.name = "ucb1x00";
5954292a46SRussell King
6054292a46SRussell King pdev = platform_device_register_data(&ucb->dev, "gpio-keys", -1,
6154292a46SRussell King &keys, sizeof(keys));
6254292a46SRussell King
6354292a46SRussell King device_create_file(&ucb->dev, &dev_attr_vbatt);
6454292a46SRussell King device_create_file(&ucb->dev, &dev_attr_vcharger);
6554292a46SRussell King device_create_file(&ucb->dev, &dev_attr_batt_temp);
6654292a46SRussell King
6754292a46SRussell King dev->priv = pdev;
6848c92022SRussell King return 0;
6948c92022SRussell King }
7048c92022SRussell King
ucb1x00_assabet_remove(struct ucb1x00_dev * dev)7148c92022SRussell King static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
7248c92022SRussell King {
7354292a46SRussell King struct platform_device *pdev = dev->priv;
7454292a46SRussell King
7554292a46SRussell King if (!IS_ERR(pdev))
7654292a46SRussell King platform_device_unregister(pdev);
7754292a46SRussell King
78cd4c1eb5SRussell King device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp);
79cd4c1eb5SRussell King device_remove_file(&dev->ucb->dev, &dev_attr_vcharger);
80cd4c1eb5SRussell King device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
8148c92022SRussell King }
8248c92022SRussell King
8348c92022SRussell King static struct ucb1x00_driver ucb1x00_assabet_driver = {
8448c92022SRussell King .add = ucb1x00_assabet_add,
8548c92022SRussell King .remove = ucb1x00_assabet_remove,
8648c92022SRussell King };
8748c92022SRussell King
ucb1x00_assabet_init(void)8848c92022SRussell King static int __init ucb1x00_assabet_init(void)
8948c92022SRussell King {
9048c92022SRussell King return ucb1x00_register_driver(&ucb1x00_assabet_driver);
9148c92022SRussell King }
9248c92022SRussell King
ucb1x00_assabet_exit(void)9348c92022SRussell King static void __exit ucb1x00_assabet_exit(void)
9448c92022SRussell King {
9548c92022SRussell King ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
9648c92022SRussell King }
9748c92022SRussell King
9848c92022SRussell King module_init(ucb1x00_assabet_init);
9948c92022SRussell King module_exit(ucb1x00_assabet_exit);
10048c92022SRussell King
10148c92022SRussell King MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
10248c92022SRussell King MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
10348c92022SRussell King MODULE_LICENSE("GPL");
104