Release 4.7 drivers/extcon/extcon-adc-jack.c
/*
* drivers/extcon/extcon-adc-jack.c
*
* Analog Jack extcon driver with ADC-based detection capability.
*
* Copyright (C) 2012 Samsung Electronics
* MyungJoo Ham <myungjoo.ham@samsung.com>
*
* Modified for calling to IIO to get adc by <anish.singh@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
#include <linux/iio/consumer.h>
#include <linux/extcon/extcon-adc-jack.h>
#include <linux/extcon.h>
/**
* struct adc_jack_data - internal data for adc_jack device driver
* @edev: extcon device.
* @cable_names: list of supported cables.
* @adc_conditions: list of adc value conditions.
* @num_conditions: size of adc_conditions.
* @irq: irq number of attach/detach event (0 if not exist).
* @handling_delay: interrupt handler will schedule extcon event
* handling at handling_delay jiffies.
* @handler: extcon event handler called by interrupt handler.
* @chan: iio channel being queried.
*/
struct adc_jack_data {
struct extcon_dev *edev;
const unsigned int **cable_names;
struct adc_jack_cond *adc_conditions;
int num_conditions;
int irq;
unsigned long handling_delay; /* in jiffies */
struct delayed_work handler;
struct iio_channel *chan;
};
static void adc_jack_handler(struct work_struct *work)
{
struct adc_jack_data *data = container_of(to_delayed_work(work),
struct adc_jack_data,
handler);
u32 state = 0;
int ret, adc_val;
int i;
ret = iio_read_channel_raw(data->chan, &adc_val);
if (ret < 0) {
dev_err(&data->edev->dev, "read channel() error: %d\n", ret);
return;
}
/* Get state from adc value with adc_conditions */
for (i = 0; i < data->num_conditions; i++) {
struct adc_jack_cond *def = &data->adc_conditions[i];
if (!def->state)
break;
if (def->min_adc <= adc_val && def->max_adc >= adc_val) {
state = def->state;
break;
}
}
/* if no def has met, it means state = 0 (no cables attached) */
extcon_set_state(data->edev, state);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anish kumar | anish kumar | 147 | 98.66% | 1 | 33.33% |
chanwoo choi | chanwoo choi | 2 | 1.34% | 2 | 66.67% |
| Total | 149 | 100.00% | 3 | 100.00% |
static irqreturn_t adc_jack_irq_thread(int irq, void *_data)
{
struct adc_jack_data *data = _data;
queue_delayed_work(system_power_efficient_wq,
&data->handler, data->handling_delay);
return IRQ_HANDLED;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anish kumar | anish kumar | 34 | 91.89% | 1 | 50.00% |
mark brown | mark brown | 3 | 8.11% | 1 | 50.00% |
| Total | 37 | 100.00% | 2 | 100.00% |
static int adc_jack_probe(struct platform_device *pdev)
{
struct adc_jack_data *data;
struct adc_jack_pdata *pdata = dev_get_platdata(&pdev->dev);
int i, err = 0;
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
if (!pdata->cable_names) {
dev_err(&pdev->dev, "error: cable_names not defined.\n");
return -EINVAL;
}
data->edev = devm_extcon_dev_allocate(&pdev->dev, pdata->cable_names);
if (IS_ERR(data->edev)) {
dev_err(&pdev->dev, "failed to allocate extcon device\n");
return -ENOMEM;
}
if (!pdata->adc_conditions ||
!pdata->adc_conditions[0].state) {
dev_err(&pdev->dev, "error: adc_conditions not defined.\n");
return -EINVAL;
}
data->adc_conditions = pdata->adc_conditions;
/* Check the length of array and set num_conditions */
for (i = 0; data->adc_conditions[i].state; i++)
;
data->num_conditions = i;
data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel);
if (IS_ERR(data->chan))
return PTR_ERR(data->chan);
data->handling_delay = msecs_to_jiffies(pdata->handling_delay_ms);
INIT_DEFERRABLE_WORK(&data->handler, adc_jack_handler);
platform_set_drvdata(pdev, data);
err = devm_extcon_dev_register(&pdev->dev, data->edev);
if (err)
return err;
data->irq = platform_get_irq(pdev, 0);
if (!data->irq) {
dev_err(&pdev->dev, "platform_get_irq failed\n");
return -ENODEV;
}
err = request_any_context_irq(data->irq, adc_jack_irq_thread,
pdata->irq_flags, pdata->name, data);
if (err < 0) {
dev_err(&pdev->dev, "error: irq %d\n", data->irq);
return err;
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anish kumar | anish kumar | 289 | 80.50% | 1 | 16.67% |
chanwoo choi | chanwoo choi | 39 | 10.86% | 1 | 16.67% |
sangjung woo | sangjung woo | 22 | 6.13% | 1 | 16.67% |
jingoo han | jingoo han | 4 | 1.11% | 1 | 16.67% |
axel lin | axel lin | 4 | 1.11% | 1 | 16.67% |
linus torvalds | linus torvalds | 1 | 0.28% | 1 | 16.67% |
| Total | 359 | 100.00% | 6 | 100.00% |
static int adc_jack_remove(struct platform_device *pdev)
{
struct adc_jack_data *data = platform_get_drvdata(pdev);
free_irq(data->irq, data);
cancel_work_sync(&data->handler.work);
iio_channel_release(data->chan);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anish kumar | anish kumar | 43 | 86.00% | 1 | 50.00% |
ivan t. ivanov | ivan t. ivanov | 7 | 14.00% | 1 | 50.00% |
| Total | 50 | 100.00% | 2 | 100.00% |
static struct platform_driver adc_jack_driver = {
.probe = adc_jack_probe,
.remove = adc_jack_remove,
.driver = {
.name = "adc-jack",
},
};
module_platform_driver(adc_jack_driver);
MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
MODULE_DESCRIPTION("ADC Jack extcon driver");
MODULE_LICENSE("GPL v2");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
anish kumar | anish kumar | 612 | 85.47% | 1 | 8.33% |
chanwoo choi | chanwoo choi | 45 | 6.28% | 4 | 33.33% |
sangjung woo | sangjung woo | 22 | 3.07% | 1 | 8.33% |
axel lin | axel lin | 22 | 3.07% | 2 | 16.67% |
ivan t. ivanov | ivan t. ivanov | 7 | 0.98% | 1 | 8.33% |
jingoo han | jingoo han | 4 | 0.56% | 1 | 8.33% |
mark brown | mark brown | 3 | 0.42% | 1 | 8.33% |
linus torvalds | linus torvalds | 1 | 0.14% | 1 | 8.33% |
| Total | 716 | 100.00% | 12 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.