Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Core functions for:
0004  *  Philips UCB1400 multifunction chip
0005  *
0006  * Based on ucb1400_ts.c:
0007  *  Author: Nicolas Pitre
0008  *  Created:    September 25, 2006
0009  *  Copyright:  MontaVista Software, Inc.
0010  *
0011  * Spliting done by: Marek Vasut <marek.vasut@gmail.com>
0012  * If something doesn't work and it worked before spliting, e-mail me,
0013  * dont bother Nicolas please ;-)
0014  *
0015  * This code is heavily based on ucb1x00-*.c copyrighted by Russell King
0016  * covering the UCB1100, UCB1200 and UCB1300..  Support for the UCB1400 has
0017  * been made separate from ucb1x00-core/ucb1x00-ts on Russell's request.
0018  */
0019 
0020 #include <linux/module.h>
0021 #include <linux/sched.h>
0022 #include <linux/slab.h>
0023 #include <linux/ucb1400.h>
0024 
0025 unsigned int ucb1400_adc_read(struct snd_ac97 *ac97, u16 adc_channel,
0026         int adcsync)
0027 {
0028     unsigned int val;
0029 
0030     if (adcsync)
0031         adc_channel |= UCB_ADC_SYNC_ENA;
0032 
0033     ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel);
0034     ucb1400_reg_write(ac97, UCB_ADC_CR, UCB_ADC_ENA | adc_channel |
0035             UCB_ADC_START);
0036 
0037     while (!((val = ucb1400_reg_read(ac97, UCB_ADC_DATA))
0038                 & UCB_ADC_DAT_VALID))
0039         schedule_timeout_uninterruptible(1);
0040 
0041     return val & UCB_ADC_DAT_MASK;
0042 }
0043 EXPORT_SYMBOL_GPL(ucb1400_adc_read);
0044 
0045 static int ucb1400_core_probe(struct device *dev)
0046 {
0047     int err;
0048     struct ucb1400 *ucb;
0049     struct ucb1400_ts ucb_ts;
0050     struct ucb1400_gpio ucb_gpio;
0051     struct snd_ac97 *ac97;
0052     struct ucb1400_pdata *pdata = dev_get_platdata(dev);
0053 
0054     memset(&ucb_ts, 0, sizeof(ucb_ts));
0055     memset(&ucb_gpio, 0, sizeof(ucb_gpio));
0056 
0057     ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL);
0058     if (!ucb) {
0059         err = -ENOMEM;
0060         goto err;
0061     }
0062 
0063     dev_set_drvdata(dev, ucb);
0064 
0065     ac97 = to_ac97_t(dev);
0066 
0067     ucb_ts.id = ucb1400_reg_read(ac97, UCB_ID);
0068     if (ucb_ts.id != UCB_ID_1400) {
0069         err = -ENODEV;
0070         goto err0;
0071     }
0072 
0073     /* GPIO */
0074     ucb_gpio.ac97 = ac97;
0075     if (pdata)
0076         ucb_gpio.gpio_offset = pdata->gpio_offset;
0077 
0078     ucb->ucb1400_gpio = platform_device_alloc("ucb1400_gpio", -1);
0079     if (!ucb->ucb1400_gpio) {
0080         err = -ENOMEM;
0081         goto err0;
0082     }
0083     err = platform_device_add_data(ucb->ucb1400_gpio, &ucb_gpio,
0084                     sizeof(ucb_gpio));
0085     if (err)
0086         goto err1;
0087     err = platform_device_add(ucb->ucb1400_gpio);
0088     if (err)
0089         goto err1;
0090 
0091     /* TOUCHSCREEN */
0092     ucb_ts.ac97 = ac97;
0093 
0094     if (pdata != NULL && pdata->irq >= 0)
0095         ucb_ts.irq = pdata->irq;
0096     else
0097         ucb_ts.irq = -1;
0098 
0099     ucb->ucb1400_ts = platform_device_alloc("ucb1400_ts", -1);
0100     if (!ucb->ucb1400_ts) {
0101         err = -ENOMEM;
0102         goto err2;
0103     }
0104     err = platform_device_add_data(ucb->ucb1400_ts, &ucb_ts,
0105                     sizeof(ucb_ts));
0106     if (err)
0107         goto err3;
0108     err = platform_device_add(ucb->ucb1400_ts);
0109     if (err)
0110         goto err3;
0111 
0112     return 0;
0113 
0114 err3:
0115     platform_device_put(ucb->ucb1400_ts);
0116 err2:
0117     platform_device_del(ucb->ucb1400_gpio);
0118 err1:
0119     platform_device_put(ucb->ucb1400_gpio);
0120 err0:
0121     kfree(ucb);
0122 err:
0123     return err;
0124 }
0125 
0126 static int ucb1400_core_remove(struct device *dev)
0127 {
0128     struct ucb1400 *ucb = dev_get_drvdata(dev);
0129 
0130     platform_device_unregister(ucb->ucb1400_ts);
0131     platform_device_unregister(ucb->ucb1400_gpio);
0132 
0133     kfree(ucb);
0134     return 0;
0135 }
0136 
0137 static struct device_driver ucb1400_core_driver = {
0138     .name   = "ucb1400_core",
0139     .bus    = &ac97_bus_type,
0140     .probe  = ucb1400_core_probe,
0141     .remove = ucb1400_core_remove,
0142 };
0143 
0144 static int __init ucb1400_core_init(void)
0145 {
0146     return driver_register(&ucb1400_core_driver);
0147 }
0148 
0149 static void __exit ucb1400_core_exit(void)
0150 {
0151     driver_unregister(&ucb1400_core_driver);
0152 }
0153 
0154 module_init(ucb1400_core_init);
0155 module_exit(ucb1400_core_exit);
0156 
0157 MODULE_DESCRIPTION("Philips UCB1400 driver");
0158 MODULE_LICENSE("GPL");