Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  linux/drivers/mfd/ucb1x00-assabet.c
0004  *
0005  *  Copyright (C) 2001-2003 Russell King, All Rights Reserved.
0006  *
0007  *  We handle the machine-specific bits of the UCB1x00 driver here.
0008  */
0009 #include <linux/module.h>
0010 #include <linux/init.h>
0011 #include <linux/device.h>
0012 #include <linux/err.h>
0013 #include <linux/fs.h>
0014 #include <linux/gpio_keys.h>
0015 #include <linux/input.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/proc_fs.h>
0018 #include <linux/mfd/ucb1x00.h>
0019 
0020 #define UCB1X00_ATTR(name,input)\
0021 static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
0022                char *buf)   \
0023 {                               \
0024     struct ucb1x00 *ucb = classdev_to_ucb1x00(dev);     \
0025     int val;                        \
0026     ucb1x00_adc_enable(ucb);                \
0027     val = ucb1x00_adc_read(ucb, input, UCB_NOSYNC);     \
0028     ucb1x00_adc_disable(ucb);               \
0029     return sprintf(buf, "%d\n", val);           \
0030 }                               \
0031 static DEVICE_ATTR_RO(name)
0032 
0033 UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
0034 UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
0035 UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
0036 
0037 static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
0038 {
0039     struct ucb1x00 *ucb = dev->ucb;
0040     struct platform_device *pdev;
0041     struct gpio_keys_platform_data keys;
0042     static struct gpio_keys_button buttons[6];
0043     unsigned i;
0044 
0045     memset(buttons, 0, sizeof(buttons));
0046     memset(&keys, 0, sizeof(keys));
0047 
0048     for (i = 0; i < ARRAY_SIZE(buttons); i++) {
0049         buttons[i].code = BTN_0 + i;
0050         buttons[i].gpio = ucb->gpio.base + i;
0051         buttons[i].type = EV_KEY;
0052         buttons[i].can_disable = true;
0053     }
0054 
0055     keys.buttons = buttons;
0056     keys.nbuttons = ARRAY_SIZE(buttons);
0057     keys.poll_interval = 50;
0058     keys.name = "ucb1x00";
0059 
0060     pdev = platform_device_register_data(&ucb->dev, "gpio-keys", -1,
0061         &keys, sizeof(keys));
0062 
0063     device_create_file(&ucb->dev, &dev_attr_vbatt);
0064     device_create_file(&ucb->dev, &dev_attr_vcharger);
0065     device_create_file(&ucb->dev, &dev_attr_batt_temp);
0066 
0067     dev->priv = pdev;
0068     return 0;
0069 }
0070 
0071 static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
0072 {
0073     struct platform_device *pdev = dev->priv;
0074 
0075     if (!IS_ERR(pdev))
0076         platform_device_unregister(pdev);
0077 
0078     device_remove_file(&dev->ucb->dev, &dev_attr_batt_temp);
0079     device_remove_file(&dev->ucb->dev, &dev_attr_vcharger);
0080     device_remove_file(&dev->ucb->dev, &dev_attr_vbatt);
0081 }
0082 
0083 static struct ucb1x00_driver ucb1x00_assabet_driver = {
0084     .add    = ucb1x00_assabet_add,
0085     .remove = ucb1x00_assabet_remove,
0086 };
0087 
0088 static int __init ucb1x00_assabet_init(void)
0089 {
0090     return ucb1x00_register_driver(&ucb1x00_assabet_driver);
0091 }
0092 
0093 static void __exit ucb1x00_assabet_exit(void)
0094 {
0095     ucb1x00_unregister_driver(&ucb1x00_assabet_driver);
0096 }
0097 
0098 module_init(ucb1x00_assabet_init);
0099 module_exit(ucb1x00_assabet_exit);
0100 
0101 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
0102 MODULE_DESCRIPTION("Assabet noddy testing only example ADC driver");
0103 MODULE_LICENSE("GPL");