summaryrefslogtreecommitdiff
path: root/drivers/staging
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-12-16 09:39:16 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-16 09:39:16 -0800
commitbd9999cd6a5eb899504ce14c1f70c5479143bbbc (patch)
treeea8cba08f86c431d49cb3f58254dac8ca60e96d8 /drivers/staging
parent9dfe495c7b4896fb88aa745660254a9704ae5930 (diff)
parent65390ea01ce678379da32b01f39fcfac4903f256 (diff)
Merge tag 'media/v4.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: - new Mediatek drivers: mtk-mdp and mtk-vcodec - some additions at the media documentation - the CEC core and drivers were promoted from staging to mainstream - some cleanups at the DVB core - the LIRC serial driver got promoted from staging to mainstream - added a driver for Renesas R-Car FDP1 driver - add DVBv5 statistics support to mn88473 driver - several fixes related to printk continuation lines - add support for HSV encoding formats - lots of other cleanups, fixups and driver improvements. * tag 'media/v4.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (496 commits) [media] v4l: tvp5150: Add missing break in set control handler [media] v4l: tvp5150: Don't inline the tvp5150_selmux() function [media] v4l: tvp5150: Compile tvp5150_link_setup out if !CONFIG_MEDIA_CONTROLLER [media] em28xx: don't store usb_device at struct em28xx [media] em28xx: use usb_interface for dev_foo() calls [media] em28xx: don't change the device's name [media] mn88472: fix chip id check on probe [media] mn88473: fix chip id check on probe [media] lirc: fix error paths in lirc_cdev_add() [media] s5p-mfc: Add support for MFC v8 available in Exynos 5433 SoCs [media] s5p-mfc: Rework clock handling [media] s5p-mfc: Don't keep clock prepared all the time [media] s5p-mfc: Kill all IS_ERR_OR_NULL in clocks management code [media] s5p-mfc: Remove dead conditional code [media] s5p-mfc: Ensure that clock is disabled before turning power off [media] s5p-mfc: Remove special clock rate management [media] s5p-mfc: Use printk_ratelimited for reporting ioctl errors [media] s5p-mfc: Set DMA_ATTR_ALLOC_SINGLE_PAGES [media] vivid: Set color_enc on HSV formats [media] v4l2-tpg: Init hv_enc field with a valid value ...
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/media/Kconfig4
-rw-r--r--drivers/staging/media/Makefile2
-rw-r--r--drivers/staging/media/bcm2048/radio-bcm2048.c66
-rw-r--r--drivers/staging/media/bcm2048/radio-bcm2048.h5
-rw-r--r--drivers/staging/media/cec/Kconfig12
-rw-r--r--drivers/staging/media/cec/Makefile5
-rw-r--r--drivers/staging/media/cec/TODO32
-rw-r--r--drivers/staging/media/cec/cec-adap.c1660
-rw-r--r--drivers/staging/media/cec/cec-api.c579
-rw-r--r--drivers/staging/media/cec/cec-core.c411
-rw-r--r--drivers/staging/media/cec/cec-priv.h56
-rw-r--r--drivers/staging/media/davinci_vpfe/Makefile4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.c31
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.h2
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_video.c4
-rw-r--r--drivers/staging/media/lirc/Kconfig13
-rw-r--r--drivers/staging/media/lirc/Makefile1
-rw-r--r--drivers/staging/media/lirc/lirc_imon.c11
-rw-r--r--drivers/staging/media/lirc/lirc_sasem.c5
-rw-r--r--drivers/staging/media/lirc/lirc_serial.c1130
-rw-r--r--drivers/staging/media/pulse8-cec/Kconfig10
-rw-r--r--drivers/staging/media/pulse8-cec/Makefile1
-rw-r--r--drivers/staging/media/pulse8-cec/TODO52
-rw-r--r--drivers/staging/media/pulse8-cec/pulse8-cec.c753
-rw-r--r--drivers/staging/media/s5p-cec/Kconfig2
-rw-r--r--drivers/staging/media/s5p-cec/TODO12
-rw-r--r--drivers/staging/media/s5p-cec/s5p_cec.c10
-rw-r--r--drivers/staging/media/st-cec/Kconfig2
-rw-r--r--drivers/staging/media/st-cec/TODO7
-rw-r--r--drivers/staging/media/st-cec/stih-cec.c7
30 files changed, 83 insertions, 4806 deletions
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index 6620d96ee44d..ffb8fa72c3da 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -21,16 +21,12 @@ if STAGING_MEDIA && MEDIA_SUPPORT
# Please keep them in alphabetic order
source "drivers/staging/media/bcm2048/Kconfig"
-source "drivers/staging/media/cec/Kconfig"
-
source "drivers/staging/media/cxd2099/Kconfig"
source "drivers/staging/media/davinci_vpfe/Kconfig"
source "drivers/staging/media/omap4iss/Kconfig"
-source "drivers/staging/media/pulse8-cec/Kconfig"
-
source "drivers/staging/media/s5p-cec/Kconfig"
# Keep LIRC at the end, as it has sub-menus
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index 906257e94dda..a28e82cf6447 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -1,9 +1,7 @@
obj-$(CONFIG_I2C_BCM2048) += bcm2048/
-obj-$(CONFIG_MEDIA_CEC) += cec/
obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC) += s5p-cec/
obj-$(CONFIG_DVB_CXD2099) += cxd2099/
obj-$(CONFIG_LIRC_STAGING) += lirc/
obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/
-obj-$(CONFIG_USB_PULSE8_CEC) += pulse8-cec/
obj-$(CONFIG_VIDEO_STI_HDMI_CEC) += st-cec/
diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c
index c5116c058cea..37bd439ee08b 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.c
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.c
@@ -17,10 +17,6 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
*/
/*
@@ -999,7 +995,7 @@ static int bcm2048_set_fm_search_tune_mode(struct bcm2048_device *bdev,
timeout = BCM2048_AUTO_SEARCH_TIMEOUT;
if (!wait_for_completion_timeout(&bdev->compl,
- msecs_to_jiffies(timeout)))
+ msecs_to_jiffies(timeout)))
dev_err(&bdev->client->dev, "IRQ timeout.\n");
if (value)
@@ -2059,67 +2055,67 @@ property_signed_read(fm_rssi, int, "%d")
DEFINE_SYSFS_PROPERTY(region, unsigned, int, "%u", 0)
static struct device_attribute attrs[] = {
- __ATTR(power_state, S_IRUGO | S_IWUSR, bcm2048_power_state_read,
+ __ATTR(power_state, 0644, bcm2048_power_state_read,
bcm2048_power_state_write),
- __ATTR(mute, S_IRUGO | S_IWUSR, bcm2048_mute_read,
+ __ATTR(mute, 0644, bcm2048_mute_read,
bcm2048_mute_write),
- __ATTR(audio_route, S_IRUGO | S_IWUSR, bcm2048_audio_route_read,
+ __ATTR(audio_route, 0644, bcm2048_audio_route_read,
bcm2048_audio_route_write),
- __ATTR(dac_output, S_IRUGO | S_IWUSR, bcm2048_dac_output_read,
+ __ATTR(dac_output, 0644, bcm2048_dac_output_read,
bcm2048_dac_output_write),
- __ATTR(fm_hi_lo_injection, S_IRUGO | S_IWUSR,
+ __ATTR(fm_hi_lo_injection, 0644,
bcm2048_fm_hi_lo_injection_read,
bcm2048_fm_hi_lo_injection_write),
- __ATTR(fm_frequency, S_IRUGO | S_IWUSR, bcm2048_fm_frequency_read,
+ __ATTR(fm_frequency, 0644, bcm2048_fm_frequency_read,
bcm2048_fm_frequency_write),
- __ATTR(fm_af_frequency, S_IRUGO | S_IWUSR,
+ __ATTR(fm_af_frequency, 0644,
bcm2048_fm_af_frequency_read,
bcm2048_fm_af_frequency_write),
- __ATTR(fm_deemphasis, S_IRUGO | S_IWUSR, bcm2048_fm_deemphasis_read,
+ __ATTR(fm_deemphasis, 0644, bcm2048_fm_deemphasis_read,
bcm2048_fm_deemphasis_write),
- __ATTR(fm_rds_mask, S_IRUGO | S_IWUSR, bcm2048_fm_rds_mask_read,
+ __ATTR(fm_rds_mask, 0644, bcm2048_fm_rds_mask_read,
bcm2048_fm_rds_mask_write),
- __ATTR(fm_best_tune_mode, S_IRUGO | S_IWUSR,
+ __ATTR(fm_best_tune_mode, 0644,
bcm2048_fm_best_tune_mode_read,
bcm2048_fm_best_tune_mode_write),
- __ATTR(fm_search_rssi_threshold, S_IRUGO | S_IWUSR,
+ __ATTR(fm_search_rssi_threshold, 0644,
bcm2048_fm_search_rssi_threshold_read,
bcm2048_fm_search_rssi_threshold_write),
- __ATTR(fm_search_mode_direction, S_IRUGO | S_IWUSR,
+ __ATTR(fm_search_mode_direction, 0644,
bcm2048_fm_search_mode_direction_read,
bcm2048_fm_search_mode_direction_write),
- __ATTR(fm_search_tune_mode, S_IRUGO | S_IWUSR,
+ __ATTR(fm_search_tune_mode, 0644,
bcm2048_fm_search_tune_mode_read,
bcm2048_fm_search_tune_mode_write),
- __ATTR(rds, S_IRUGO | S_IWUSR, bcm2048_rds_read,
+ __ATTR(rds, 0644, bcm2048_rds_read,
bcm2048_rds_write),
- __ATTR(rds_b_block_mask, S_IRUGO | S_IWUSR,
+ __ATTR(rds_b_block_mask, 0644,
bcm2048_rds_b_block_mask_read,
bcm2048_rds_b_block_mask_write),
- __ATTR(rds_b_block_match, S_IRUGO | S_IWUSR,
+ __ATTR(rds_b_block_match, 0644,
bcm2048_rds_b_block_match_read,
bcm2048_rds_b_block_match_write),
- __ATTR(rds_pi_mask, S_IRUGO | S_IWUSR, bcm2048_rds_pi_mask_read,
+ __ATTR(rds_pi_mask, 0644, bcm2048_rds_pi_mask_read,
bcm2048_rds_pi_mask_write),
- __ATTR(rds_pi_match, S_IRUGO | S_IWUSR, bcm2048_rds_pi_match_read,
+ __ATTR(rds_pi_match, 0644, bcm2048_rds_pi_match_read,
bcm2048_rds_pi_match_write),
- __ATTR(rds_wline, S_IRUGO | S_IWUSR, bcm2048_rds_wline_read,
+ __ATTR(rds_wline, 0644, bcm2048_rds_wline_read,
bcm2048_rds_wline_write),
- __ATTR(rds_pi, S_IRUGO, bcm2048_rds_pi_read, NULL),
- __ATTR(rds_rt, S_IRUGO, bcm2048_rds_rt_read, NULL),
- __ATTR(rds_ps, S_IRUGO, bcm2048_rds_ps_read, NULL),
- __ATTR(fm_rds_flags, S_IRUGO, bcm2048_fm_rds_flags_read, NULL),
- __ATTR(region_bottom_frequency, S_IRUGO,
+ __ATTR(rds_pi, 0444, bcm2048_rds_pi_read, NULL),
+ __ATTR(rds_rt, 0444, bcm2048_rds_rt_read, NULL),
+ __ATTR(rds_ps, 0444, bcm2048_rds_ps_read, NULL),
+ __ATTR(fm_rds_flags, 0444, bcm2048_fm_rds_flags_read, NULL),
+ __ATTR(region_bottom_frequency, 0444,
bcm2048_region_bottom_frequency_read, NULL),
- __ATTR(region_top_frequency, S_IRUGO,
+ __ATTR(region_top_frequency, 0444,
bcm2048_region_top_frequency_read, NULL),
- __ATTR(fm_carrier_error, S_IRUGO,
+ __ATTR(fm_carrier_error, 0444,
bcm2048_fm_carrier_error_read, NULL),
- __ATTR(fm_rssi, S_IRUGO,
+ __ATTR(fm_rssi, 0444,
bcm2048_fm_rssi_read, NULL),
- __ATTR(region, S_IRUGO | S_IWUSR, bcm2048_region_read,
+ __ATTR(region, 0644, bcm2048_region_read,
bcm2048_region_write),
- __ATTR(rds_data, S_IRUGO, bcm2048_rds_data_read, NULL),
+ __ATTR(rds_data, 0444, bcm2048_rds_data_read, NULL),
};
static int bcm2048_sysfs_unregister_properties(struct bcm2048_device *bdev,
@@ -2204,7 +2200,7 @@ static ssize_t bcm2048_fops_read(struct file *file, char __user *buf,
}
/* interruptible_sleep_on(&bdev->read_queue); */
if (wait_event_interruptible(bdev->read_queue,
- bdev->rds_data_available) < 0) {
+ bdev->rds_data_available) < 0) {
retval = -EINTR;
goto done;
}
diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.h b/drivers/staging/media/bcm2048/radio-bcm2048.h
index 4c90a32db795..4d950c1e2e8b 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.h
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.h
@@ -14,11 +14,6 @@
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
*/
#ifndef BCM2048_H
diff --git a/drivers/staging/media/cec/Kconfig b/drivers/staging/media/cec/Kconfig
deleted file mode 100644
index 6e12d41b1f86..000000000000
--- a/drivers/staging/media/cec/Kconfig
+++ /dev/null
@@ -1,12 +0,0 @@
-config MEDIA_CEC
- bool "CEC API (EXPERIMENTAL)"
- depends on MEDIA_SUPPORT
- select MEDIA_CEC_EDID
- ---help---
- Enable the CEC API.
-
-config MEDIA_CEC_DEBUG
- bool "CEC debugfs interface (EXPERIMENTAL)"
- depends on MEDIA_CEC && DEBUG_FS
- ---help---
- Turns on the DebugFS interface for CEC devices.
diff --git a/drivers/staging/media/cec/Makefile b/drivers/staging/media/cec/Makefile
deleted file mode 100644
index bd7f3c593468..000000000000
--- a/drivers/staging/media/cec/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-cec-objs := cec-core.o cec-adap.o cec-api.o
-
-ifeq ($(CONFIG_MEDIA_CEC),y)
- obj-$(CONFIG_MEDIA_SUPPORT) += cec.o
-endif
diff --git a/drivers/staging/media/cec/TODO b/drivers/staging/media/cec/TODO
deleted file mode 100644
index 13224694a8ae..000000000000
--- a/drivers/staging/media/cec/TODO
+++ /dev/null
@@ -1,32 +0,0 @@
-The reason why cec.c is still in staging is that I would like
-to have a bit more confidence in the uABI. The kABI is fine,
-no problem there, but I would like to let the public API mature
-a bit.
-
-Once I'm confident that I didn't miss anything then the cec.c source
-can move to drivers/media and the linux/cec.h and linux/cec-funcs.h
-headers can move to uapi/linux and added to uapi/linux/Kbuild to make
-them public.
-
-Hopefully this will happen later in 2016.
-
-Other TODOs:
-
-- There are two possible replies to CEC_MSG_INITIATE_ARC. How to handle that?
-- Add a flag to inhibit passing CEC RC messages to the rc subsystem.
- Applications should be able to choose this when calling S_LOG_ADDRS.
-- If the reply field of cec_msg is set then when the reply arrives it
- is only sent to the filehandle that transmitted the original message
- and not to any followers. Should this behavior change or perhaps
- controlled through a cec_msg flag?
-- Should CEC_LOG_ADDR_TYPE_SPECIFIC be replaced by TYPE_2ND_TV and TYPE_PROCESSOR?
- And also TYPE_SWITCH and TYPE_CDC_ONLY in addition to the TYPE_UNREGISTERED?
- This should give the framework more information about the device type
- since SPECIFIC and UNREGISTERED give no useful information.
-- Once this is out of staging this should no longer be a separate
- config option, instead it should be selected by drivers that want it.
-- Revisit the IS_REACHABLE(RC_CORE): perhaps the RC_CORE support should
- be enabled through a separate config option in drivers/media/Kconfig
- or rc/Kconfig?
-
-Hans Verkuil <hans.verkuil@cisco.com>
diff --git a/drivers/staging/media/cec/cec-adap.c b/drivers/staging/media/cec/cec-adap.c
deleted file mode 100644
index 611e07b78bfe..000000000000
--- a/drivers/staging/media/cec/cec-adap.c
+++ /dev/null
@@ -1,1660 +0,0 @@
-/*
- * cec-adap.c - HDMI Consumer Electronics Control framework - CEC adapter
- *
- * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
- *
- * This program is free software; you may redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/kmod.h>
-#include <linux/ktime.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/string.h>
-#include <linux/types.h>
-
-#include "cec-priv.h"
-
-static int cec_report_features(struct cec_adapter *adap, unsigned int la_idx);
-static int cec_report_phys_addr(struct cec_adapter *adap, unsigned int la_idx);
-
-/*
- * 400 ms is the time it takes for one 16 byte message to be
- * transferred and 5 is the maximum number of retries. Add
- * another 100 ms as a margin. So if the transmit doesn't
- * finish before that time something is really wrong and we
- * have to time out.
- *
- * This is a sign that something it really wrong and a warning
- * will be issued.
- */
-#define CEC_XFER_TIMEOUT_MS (5 * 400 + 100)
-
-#define call_op(adap, op, arg...) \
- (adap->ops->op ? adap->ops->op(adap, ## arg) : 0)
-
-#define call_void_op(adap, op, arg...) \
- do { \
- if (adap->ops->op) \
- adap->ops->op(adap, ## arg); \
- } while (0)
-
-static int cec_log_addr2idx(const struct cec_adapter *adap, u8 log_addr)
-{
- int i;
-
- for (i = 0; i < adap->log_addrs.num_log_addrs; i++)
- if (adap->log_addrs.log_addr[i] == log_addr)
- return i;
- return -1;
-}
-
-static unsigned int cec_log_addr2dev(const struct cec_adapter *adap, u8 log_addr)
-{
- int i = cec_log_addr2idx(adap, log_addr);
-
- return adap->log_addrs.primary_device_type[i < 0 ? 0 : i];
-}
-
-/*
- * Queue a new event for this filehandle. If ts == 0, then set it
- * to the current time.
- *
- * The two events that are currently defined do not need to keep track
- * of intermediate events, so no actual queue of events is needed,
- * instead just store the latest state and the total number of lost
- * messages.
- *
- * Should new events be added in the future that require intermediate
- * results to be queued as well, then a proper queue data structure is
- * required. But until then, just keep it simple.
- */
-void cec_queue_event_fh(struct cec_fh *fh,
- const struct cec_event *new_ev, u64 ts)
-{
- struct cec_event *ev = &fh->events[new_ev->event - 1];
-
- if (ts == 0)
- ts = ktime_get_ns();
-
- mutex_lock(&fh->lock);
- if (new_ev->event == CEC_EVENT_LOST_MSGS &&
- fh->pending_events & (1 << new_ev->event)) {
- /*
- * If there is already a lost_msgs event, then just
- * update the lost_msgs count. This effectively
- * merges the old and new events into one.
- */
- ev->lost_msgs.lost_msgs += new_ev->lost_msgs.lost_msgs;
- goto unlock;
- }
-
- /*
- * Intermediate states are not interesting, so just
- * overwrite any older event.
- */
- *ev = *new_ev;
- ev->ts = ts;
- fh->pending_events |= 1 << new_ev->event;
-
-unlock:
- mutex_unlock(&fh->lock);
- wake_up_interruptible(&fh->wait);
-}
-
-/* Queue a new event for all open filehandles. */
-static void cec_queue_event(struct cec_adapter *adap,
- const struct cec_event *ev)
-{
- u64 ts = ktime_get_ns();
- struct cec_fh *fh;
-
- mutex_lock(&adap->devnode.lock);
- list_for_each_entry(fh, &adap->devnode.fhs, list)
- cec_queue_event_fh(fh, ev, ts);
- mutex_unlock(&adap->devnode.lock);
-}
-
-/*
- * Queue a new message for this filehandle. If there is no more room
- * in the queue, then send the LOST_MSGS event instead.
- */
-static void cec_queue_msg_fh(struct cec_fh *fh, const struct cec_msg *msg)
-{
- static const struct cec_event ev_lost_msg = {
- .ts = 0,
- .event = CEC_EVENT_LOST_MSGS,
- .flags = 0,
- {
- .lost_msgs.lost_msgs = 1,
- },
- };
- struct cec_msg_entry *entry;
-
- mutex_lock(&fh->lock);
- entry = kmalloc(sizeof(*entry), GFP_KERNEL);
- if (!entry)
- goto lost_msgs;
-
- entry->msg = *msg;
- /* Add new msg at the end of the queue */
- list_add_tail(&entry->list, &fh->msgs);
-
- /*
- * if the queue now has more than CEC_MAX_MSG_RX_QUEUE_SZ
- * messages, drop the oldest one and send a lost message event.
- */
- if (fh->queued_msgs == CEC_MAX_MSG_RX_QUEUE_SZ) {
- list_del(&entry->list);
- goto lost_msgs;
- }
- fh->queued_msgs++;
- mutex_unlock(&fh->lock);
- wake_up_interruptible(&fh->wait);
- return;
-
-lost_msgs:
- mutex_unlock(&fh->lock);
- cec_queue_event_fh(fh, &ev_lost_msg, 0);
-}
-
-/*
- * Queue the message for those filehandles that are in monitor mode.
- * If valid_la is true (this message is for us or was sent by us),
- * then pass it on to any monitoring filehandle. If this message
- * isn't for us or from us, then only give it to filehandles that
- * are in MONITOR_ALL mode.
- *
- * This can only happen if the CEC_CAP_MONITOR_ALL capability is
- * set and the CEC adapter was placed in 'monitor all' mode.
- */
-static void cec_queue_msg_monitor(struct cec_adapter *adap,
- const struct cec_msg *msg,
- bool valid_la)
-{
- struct cec_fh *fh;
- u32 monitor_mode = valid_la ? CEC_MODE_MONITOR :
- CEC_MODE_MONITOR_ALL;
-
- mutex_lock(&adap->devnode.lock);
- list_for_each_entry(fh, &adap->devnode.fhs, list) {
- if (fh->mode_follower >= monitor_mode)
- cec_queue_msg_fh(fh, msg);
- }
- mutex_unlock(&adap->devnode.lock);
-}
-
-/*
- * Queue the message for follower filehandles.
- */
-static void cec_queue_msg_followers(struct cec_adapter *adap,
- const struct cec_msg *msg)
-{
- struct cec_fh *fh;
-
- mutex_lock(&adap->devnode.lock);
- list_for_each_entry(fh, &adap->devnode.fhs, list) {
- if (fh->mode_follower == CEC_MODE_FOLLOWER)
- cec_queue_msg_fh(fh, msg);
- }
- mutex_unlock(&adap->devnode.lock);
-}
-
-/* Notify userspace of an adapter state change. */
-static void cec_post_state_event(struct cec_adapter *adap)
-{
- struct cec_event ev = {
- .event = CEC_EVENT_STATE_CHANGE,
- };
-
- ev.state_change.phys_addr = adap->phys_addr;
- ev.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
- cec_queue_event(adap, &ev);
-}
-
-/*
- * A CEC transmit (and a possible wait for reply) completed.
- * If this was in blocking mode, then complete it, otherwise
- * queue the message for userspace to dequeue later.
- *
- * This function is called with adap->lock held.
- */
-static void cec_data_completed(struct cec_data *data)
-{
- /*
- * Delete this transmit from the filehandle's xfer_list since
- * we're done with it.
- *
- * Note that if the filehandle is closed before this transmit
- * finished, then the release() function will set data->fh to NULL.
- * Without that we would be referring to a closed filehandle.
- */
- if (data->fh)
- list_del(&data->xfer_list);
-
- if (data->blocking) {
- /*
- * Someone is blocking so mark the message as completed
- * and call complete.
- */
- data->completed = true;
- complete(&data->c);
- } else {
- /*
- * No blocking, so just queue the message if needed and
- * free the memory.
- */
- if (data->fh)
- cec_queue_msg_fh(data->fh, &data->msg);
- kfree(data);
- }
-}
-
-/*
- * A pending CEC transmit needs to be cancelled, either because the CEC
- * adapter is disabled or the transmit takes an impossibly long time to
- * finish.
- *
- * This function is called with adap->lock held.
- */
-static void cec_data_cancel(struct cec_data *data)
-{
- /*
- * It's either the current transmit, or it is a pending
- * transmit. Take the appropriate action to clear it.
- */
- if (data->adap->transmitting == data) {
- data->adap->transmitting = NULL;
- } else {
- list_del_init(&data->list);
- if (!(data->msg.tx_status & CEC_TX_STATUS_OK))
- data->adap->transmit_queue_sz--;
- }
-
- /* Mark it as an error */
- data->msg.tx_ts = ktime_get_ns();
- data->msg.tx_status = CEC_TX_STATUS_ERROR |
- CEC_TX_STATUS_MAX_RETRIES;
- data->attempts = 0;
- data->msg.tx_error_cnt = 1;
- /* Queue transmitted message for monitoring purposes */
- cec_queue_msg_monitor(data->adap, &data->msg, 1);
-
- cec_data_completed(data);
-}
-
-/*
- * Main CEC state machine
- *
- * Wait until the thread should be stopped, or we are not transmitting and
- * a new transmit message is queued up, in which case we start transmitting
- * that message. When the adapter finished transmitting the message it will
- * call cec_transmit_done().
- *
- * If the adapter is disabled, then remove all queued messages instead.
- *
- * If the current transmit times out, then cancel that transmit.
- */
-int cec_thread_func(void *_adap)
-{
- struct cec_adapter *adap = _adap;
-
- for (;;) {
- unsigned int signal_free_time;
- struct cec_data *data;
- bool timeout = false;
- u8 attempts;
-
- if (adap->transmitting) {
- int err;
-
- /*
- * We are transmitting a message, so add a timeout
- * to prevent the state machine to get stuck waiting
- * for this message to finalize and add a check to
- * see if the adapter is disabled in which case the
- * transmit should be canceled.
- */
- err = wait_event_interruptible_timeout(adap->kthread_waitq,
- kthread_should_stop() ||
- (!adap->is_configured && !adap->is_configuring) ||
- (!adap->transmitting &&
- !list_empty(&adap->transmit_queue)),
- msecs_to_jiffies(CEC_XFER_TIMEOUT_MS));
- timeout = err == 0;
- } else {
- /* Otherwise we just wait for something to happen. */
- wait_event_interruptible(adap->kthread_waitq,
- kthread_should_stop() ||
- (!adap->transmitting &&
- !list_empty(&adap->transmit_queue)));
- }
-
- mutex_lock(&adap->lock);
-
- if ((!adap->is_configured && !adap->is_configuring) ||
- kthread_should_stop()) {
- /*
- * If the adapter is disabled, or we're asked to stop,
- * then cancel any pending transmits.
- */
- while (!list_empty(&adap->transmit_queue)) {
- data = list_first_entry(&adap->transmit_queue,
- struct cec_data, list);
- cec_data_cancel(data);
- }
- if (adap->transmitting)
- cec_data_cancel(adap->transmitting);
-
- /*
- * Cancel the pending timeout work. We have to unlock
- * the mutex when flushing the work since
- * cec_wait_timeout() will take it. This is OK since
- * no new entries can be added to wait_queue as long
- * as adap->transmitting is NULL, which it is due to
- * the cec_data_cancel() above.
- */
- while (!list_empty(&adap->wait_queue)) {
- data = list_first_entry(&adap->wait_queue,
- struct cec_data, list);
-
- if (!cancel_delayed_work(&data->work)) {
- mutex_unlock(&adap->lock);
- flush_scheduled_work();
- mutex_lock(&adap->lock);
- }
- cec_data_cancel(data);
- }
- goto unlock;
- }
-
- if (adap->transmitting && timeout) {
- /*
- * If we timeout, then log that. This really shouldn't
- * happen and is an indication of a faulty CEC adapter
- * driver, or the CEC bus is in some weird state.
- */
- dprintk(0, "message %*ph timed out!\n",
- adap->transmitting->msg.len,
- adap->transmitting->msg.msg);
- /* Just give up on this. */
- cec_data_cancel(adap->transmitting);
- goto unlock;
- }
-
- /*
- * If we are still transmitting, or there is nothing new to
- * transmit, then just continue waiting.
- */
- if (adap->transmitting || list_empty(&adap->transmit_queue))
- goto unlock;
-
- /* Get a new message to transmit */
- data = list_first_entry(&adap->transmit_queue,
- struct cec_data, list);
- list_del_init(&data->list);
- adap->transmit_queue_sz--;
- /* Make this the current transmitting message */
- adap->transmitting = data;
-
- /*
- * Suggested number of attempts as per the CEC 2.0 spec:
- * 4 attempts is the default, except for 'secondary poll
- * messages', i.e. poll messages not sent during the adapter
- * configuration phase when it allocates logical addresses.
- */
- if (data->msg.len == 1 && adap->is_configured)
- attempts = 2;
- else
- attempts = 4;
-
- /* Set the suggested signal free time */
- if (data->attempts) {
- /* should be >= 3 data bit periods for a retry */
- signal_free_time = CEC_SIGNAL_FREE_TIME_RETRY;
- } else if (data->new_initiator) {
- /* should be >= 5 data bit periods for new initiator */
- signal_free_time = CEC_SIGNAL_FREE_TIME_NEW_INITIATOR;
- } else {
- /*
- * should be >= 7 data bit periods for sending another
- * frame immediately after another.
- */
- signal_free_time = CEC_SIGNAL_FREE_TIME_NEXT_XFER;
- }
- if (data->attempts == 0)
- data->attempts = attempts;
-
- /* Tell the adapter to transmit, cancel on error */
- if (adap->ops->adap_transmit(adap, data->attempts,
- signal_free_time, &data->msg))
- cec_data_cancel(data);
-
-unlock:
- mutex_unlock(&adap->lock);
-
- if (kthread_should_stop())
- break;
- }
- return 0;
-}
-
-/*
- * Called by the CEC adapter if a transmit finished.
- */
-void cec_transmit_done(struct cec_adapter *adap, u8 status, u8 arb_lost_cnt,
- u8 nack_cnt, u8 low_drive_cnt, u8 error_cnt)
-{
- struct cec_data *data;
- struct cec_msg *msg;
- u64 ts = ktime_get_ns();
-
- dprintk(2, "cec_transmit_done %02x\n", status);
- mutex_lock(&adap->lock);
- data = adap->transmitting;
- if (!data) {
- /*
- * This can happen if a transmit was issued and the cable is
- * unplugged while the transmit is ongoing. Ignore this
- * transmit in that case.
- */
- dprintk(1, "cec_transmit_done without an ongoing transmit!\n");
- goto unlock;
- }
-
- msg = &data->msg;
-
- /* Drivers must fill in the status! */
- WARN_ON(status == 0);
- msg->tx_ts = ts;
- msg->tx_status |= status;
- msg->tx_arb_lost_cnt += arb_lost_cnt;
- msg->tx_nack_cnt += nack_cnt;
- msg->tx_low_drive_cnt += low_drive_cnt;
- msg->tx_error_cnt += error_cnt;
-
- /* Mark that we're done with this transmit */
- adap->transmitting = NULL;
-
- /*
- * If there are still retry attempts left and there was an error and
- * the hardware didn't signal that it retried itself (by setting
- * CEC_TX_STATUS_MAX_RETRIES), then we will retry ourselves.
- */
- if (data->attempts > 1 &&
- !(status & (CEC_TX_STATUS_MAX_RETRIES | CEC_TX_STATUS_OK))) {
- /* Retry this message */
- data->attempts--;
- /* Add the message in front of the transmit queue */
- list_add(&data->list, &adap->transmit_queue);
- adap->transmit_queue_sz++;
- goto wake_thread;
- }
-
- data->attempts = 0;
-
- /* Always set CEC_TX_STATUS_MAX_RETRIES on error */
- if (!(status & CEC_TX_STATUS_OK))
- msg->tx_status |= CEC_TX_STATUS_MAX_RETRIES;
-
- /* Queue transmitted message for monitoring purposes */
- cec_queue_msg_monitor(adap, msg, 1);
-
- if ((status & CEC_TX_STATUS_OK) && adap->is_configured &&
- msg->timeout) {
- /*
- * Queue the message into the wait queue if we want to wait
- * for a reply.
- */
- list_add_tail(&data->list, &adap->wait_queue);
- schedule_delayed_work(&data->work,
- msecs_to_jiffies(msg->timeout));
- } else {
- /* Otherwise we're done */
- cec_data_completed(data);
- }
-
-wake_thread:
- /*
- * Wake up the main thread to see if another message is ready
- * for transmitting or to retry the current message.
- */
- wake_up_interruptible(&adap->kthread_waitq);
-unlock:
- mutex_unlock(&adap->lock);
-}
-EXPORT_SYMBOL_GPL(cec_transmit_done);
-
-/*
- * Called when waiting for a reply times out.
- */
-static void cec_wait_timeout(struct work_struct *work)
-{
- struct cec_data *data = container_of(work, struct cec_data, work.work);
- struct cec_adapter *adap = data->adap;
-
- mutex_lock(&adap->lock);
- /*
- * Sanity check in case the timeout and the arrival of the message
- * happened at the same time.
- */
- if (list_empty(&data->list))
- goto unlock;
-
- /* Mark the message as timed out */
- list_del_init(&data->list);
- data->msg.rx_ts = ktime_get_ns();
- data->msg.rx_status = CEC_RX_STATUS_TIMEOUT;
- cec_data_completed(data);
-unlock:
- mutex_unlock(&adap->lock);
-}
-
-/*
- * Transmit a message. The fh argument may be NULL if the transmit is not
- * associated with a specific filehandle.
- *
- * This function is called with adap->lock held.
- */
-int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg,
- struct cec_fh *fh, bool block)
-{
- struct cec_data *data;
- u8 last_initiator = 0xff;
- unsigned int timeout;
- int res = 0;
-
- msg->rx_ts = 0;
- msg->tx_ts = 0;
- msg->rx_status = 0;
- msg->tx_status = 0;
- msg->tx_arb_lost_cnt = 0;
- msg->tx_nack_cnt = 0;
- msg->tx_low_drive_cnt = 0;
- msg->tx_error_cnt = 0;
- msg->flags = 0;
- msg->sequence = ++adap->sequence;
- if (!msg->sequence)
- msg->sequence = ++adap->sequence;
-
- if (msg->reply && msg->timeout == 0) {
- /* Make sure the timeout isn't 0. */
- msg->timeout = 1000;
- }
-
- /* Sanity checks */
- if (msg->len == 0 || msg->len > CEC_MAX_MSG_SIZE) {
- dprintk(1, "cec_transmit_msg: invalid length %d\n", msg->len);
- return -EINVAL;
- }
- if (msg->timeout && msg->len == 1) {
- dprintk(1, "cec_transmit_msg: can't reply for poll msg\n");
- return -EINVAL;
- }
- memset(msg->msg + msg->len, 0, sizeof(msg->msg) - msg->len);
- if (msg->len == 1) {
- if (cec_msg_initiator(msg) != 0xf ||
- cec_msg_destination(msg) == 0xf) {
- dprintk(1, "cec_transmit_msg: invalid poll message\n");
- return -EINVAL;
- }
- if (cec_has_log_addr(adap, cec_msg_destination(msg))) {
- /*
- * If the destination is a logical address our adapter
- * has already claimed, then just NACK this.
- * It depends on the hardware what it will do with a
- * POLL to itself (some OK this), so it is just as
- * easy to handle it here so the behavior will be
- * consistent.
- */
- msg->tx_ts = ktime_get_ns();
- msg->tx_status = CEC_TX_STATUS_NACK |
- CEC_TX_STATUS_MAX_RETRIES;
- msg->tx_nack_cnt = 1;
- return 0;
- }
- }
- if (msg->len > 1 && !cec_msg_is_broadcast(msg) &&
- cec_has_log_addr(adap, cec_msg_destination(msg))) {
- dprintk(1, "cec_transmit_msg: destination is the adapter itself\n");
- return -EINVAL;
- }
- if (cec_msg_initiator(msg) != 0xf &&
- !cec_has_log_addr(adap, cec_msg_initiator(msg))) {
- dprintk(1, "cec_transmit_msg: initiator has unknown logical address %d\n",
- cec_msg_initiator(msg));
- return -EINVAL;
- }
- if (!adap->is_configured && !adap->is_configuring)
- return -ENONET;
-
- if (adap->transmit_queue_sz >= CEC_MAX_MSG_TX_QUEUE_SZ)
- return -EBUSY;
-
- data = kzalloc(sizeof(*data), GFP_KERNEL);
- if (!data)
- return -ENOMEM;
-
- if (msg->len > 1 && msg->msg[1] == CEC_MSG_CDC_MESSAGE) {
- msg->msg[2] = adap->phys_addr >> 8;
- msg->msg[3] = adap->phys_addr & 0xff;
- }
-
- if (msg->timeout)
- dprintk(2, "cec_transmit_msg: %*ph (wait for 0x%02x%s)\n",
- msg->len, msg->msg, msg->reply, !block ? ", nb" : "");
- else
- dprintk(2, "cec_transmit_msg: %*ph%s\n",
- msg->len, msg->msg, !block ? " (nb)" : "");
-
- data->msg = *msg;
- data->fh = fh;
- data->adap = adap;
- data->blocking = block;
-
- /*
- * Determine if this message follows a message from the same
- * initiator. Needed to determine the free signal time later on.
- */
- if (msg->len > 1) {
- if (!(list_empty(&adap->transmit_queue))) {
- const struct cec_data *last;
-
- last = list_last_entry(&adap->transmit_queue,
- const struct cec_data, list);
- last_initiator = cec_msg_initiator(&last->msg);
- } else if (adap->transmitting) {
- last_initiator =
- cec_msg_initiator(&adap->transmitting->msg);
- }
- }
- data->new_initiator = last_initiator != cec_msg_initiator(msg);
- init_completion(&data->c);
- INIT_DELAYED_WORK(&data->work, cec_wait_timeout);
-
- if (fh)
- list_add_tail(&data->xfer_list, &fh->xfer_list);
- list_add_tail(&data->list, &adap->transmit_queue);
- adap->transmit_queue_sz++;
- if (!adap->transmitting)
- wake_up_interruptible(&adap->kthread_waitq);
-
- /* All done if we don't need to block waiting for completion */
- if (!block)
- return 0;
-
- /*
- * If we don't get a completion before this time something is really
- * wrong and we time out.
- */
- timeout = CEC_XFER_TIMEOUT_MS;
- /* Add the requested timeout if we have to wait for a reply as well */
- if (msg->timeout)
- timeout += msg->timeout;
-
- /*
- * Release the lock and wait, retake the lock afterwards.
- */
- mutex_unlock(&adap->lock);
- res = wait_for_completion_killable_timeout(&data->c,
- msecs_to_jiffies(timeout));
- mutex_lock(&adap->lock);
-
- if (data->completed) {
- /* The transmit completed (possibly with an error) */
- *msg = data->msg;
- kfree(data);
- return 0;
- }
- /*
- * The wait for completion timed out or was interrupted, so mark this
- * as non-blocking and disconnect from the filehandle since it is
- * still 'in flight'. When it finally completes it will just drop the
- * result silently.
- */
- data->blocking = false;
- if (data->fh)
- list_del(&data->xfer_list);
- data->fh = NULL;
-
- if (res == 0) { /* timed out */
- /* Check if the reply or the transmit failed */
- if (msg->timeout && (msg->tx_status & CEC_TX_STATUS_OK))
- msg->rx_status = CEC_RX_STATUS_TIMEOUT;
- else
- msg->tx_status = CEC_TX_STATUS_MAX_RETRIES;
- }
- return res > 0 ? 0 : res;
-}
-
-/* Helper function to be used by drivers and this framework. */
-int cec_transmit_msg(struct cec_adapter *adap, struct cec_msg *msg,
- bool block)
-{
- int ret;
-
- mutex_lock(&adap->lock);
- ret = cec_transmit_msg_fh(adap, msg, NULL, block);
- mutex_unlock(&adap->lock);
- return ret;
-}
-EXPORT_SYMBOL_GPL(cec_transmit_msg);
-
-/*
- * I don't like forward references but without this the low-level
- * cec_received_msg() function would come after a bunch of high-level
- * CEC protocol handling functions. That was very confusing.
- */
-static int cec_receive_notify(struct cec_adapter *adap, struct cec_msg *msg,
- bool is_reply);
-
-/* Called by the CEC adapter if a message is received */
-void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg)
-{
- struct cec_data *data;
- u8 msg_init = cec_msg_initiator(msg);
- u8 msg_dest = cec_msg_destination(msg);
- bool is_reply = false;
- bool valid_la = true;
-
- if (WARN_ON(!msg->len || msg->len > CEC_MAX_MSG_SIZE))
- return;
-
- msg->rx_ts = ktime_get_ns();
- msg->rx_status = CEC_RX_STATUS_OK;
- msg->sequence = msg->reply = msg->timeout = 0;
- msg->tx_status = 0;
- msg->tx_ts = 0;
- msg->flags = 0;
- memset(msg->msg + msg->len, 0, sizeof(msg->msg) - msg->len);
-
- mutex_lock(&adap->lock);
- dprintk(2, "cec_received_msg: %*ph\n", msg->len, msg->msg);
-
- /* Check if this message was for us (directed or broadcast). */
- if (!cec_msg_is_broadcast(msg))
- valid_la = cec_has_log_addr(adap, msg_dest);
-
- /* It's a valid message and not a poll or CDC message */
- if (valid_la && msg->len > 1 && msg->msg[1] != CEC_MSG_CDC_MESSAGE) {
- u8 cmd = msg->msg[1];
- bool abort = cmd == CEC_MSG_FEATURE_ABORT;
-
- /* The aborted command is in msg[2] */
- if (abort)
- cmd = msg->msg[2];
-
- /*
- * Walk over all transmitted messages that are waiting for a
- * reply.
- */
- list_for_each_entry(data, &adap->wait_queue, list) {
- struct cec_msg *dst = &data->msg;
-
- /* Does the command match? */
- if ((abort && cmd != dst->msg[1]) ||
- (!abort && cmd != dst->reply))
- continue;
-
- /* Does the addressing match? */
- if (msg_init != cec_msg_destination(dst) &&
- !cec_msg_is_broadcast(dst))
- continue;
-
- /* We got a reply */
- memcpy(dst->msg, msg->msg, msg->len);
- dst->len = msg->len;
- dst->rx_ts = msg->rx_ts;
- dst->rx_status = msg->rx_status;
- if (abort)
- dst->rx_status |= CEC_RX_STATUS_FEATURE_ABORT;
- /* Remove it from the wait_queue */
- list_del_init(&data->list);
-
- /* Cancel the pending timeout work */
- if (!cancel_delayed_work(&data->work)) {
- mutex_unlock(&adap->lock);
- flush_scheduled_work();
- mutex_lock(&adap->lock);
- }
- /*
- * Mark this as a reply, provided someone is still
- * waiting for the answer.
- */
- if (data->fh)
- is_reply = true;
- cec_data_completed(data);
- break;
- }
- }
- mutex_unlock(&adap->lock);
-
- /* Pass the message on to any monitoring filehandles */
- cec_queue_msg_monitor(adap, msg, valid_la);
-
- /* We're done if it is not for us or a poll message */
- if (!valid_la || msg->len <= 1)
- return;
-
- if (adap->log_addrs.log_addr_mask == 0)
- return;
-
- /*
- * Process the message on the protocol level. If is_reply is true,
- * then cec_receive_notify() won't pass on the reply to the listener(s)
- * since that was already done by cec_data_completed() above.
- */
- cec_receive_notify(adap, msg, is_reply);
-}
-EXPORT_SYMBOL_GPL(cec_received_msg);
-
-/* Logical Address Handling */
-
-/*
- * Attempt to claim a specific logical address.
- *
- * This function is called with adap->lock held.
- */
-static int cec_config_log_addr(struct cec_adapter *adap,
- unsigned int idx,
- unsigned int log_addr)
-{
- struct cec_log_addrs *las = &adap->log_addrs;
- struct cec_msg msg = { };
- int err;
-
- if (cec_has_log_addr(adap, log_addr))
- return 0;
-
- /* Send poll message */
- msg.len = 1;
- msg.msg[0] = 0xf0 | log_addr;
- err = cec_transmit_msg_fh(adap, &msg, NULL, true);
-
- /*
- * While trying to poll the physical address was reset
- * and the adapter was unconfigured, so bail out.
- */
- if (!adap->is_configuring)
- return -EINTR;
-
- if (err)
- return err;
-
- if (msg.tx_status & CEC_TX_STATUS_OK)
- return 0;
-
- /*
- * Message not acknowledged, so this logical
- * address is free to use.
- */
- err = adap->ops->adap_log_addr(adap, log_addr);
- if (err)
- return err;
-
- las->log_addr[idx] = log_addr;
- las->log_addr_mask |= 1 << log_addr;
- adap->phys_addrs[log_addr] = adap->phys_addr;
-
- dprintk(2, "claimed addr %d (%d)\n", log_addr,
- las->primary_device_type[idx]);
- return 1;
-}
-
-/*
- * Unconfigure the adapter: clear all logical addresses and send
- * the state changed event.
- *
- * This function is called with adap->lock held.
- */
-static void cec_adap_unconfigure(struct cec_adapter *adap)
-{
- WARN_ON(adap->ops->adap_log_addr(adap, CEC_LOG_ADDR_INVALID));
- adap->log_addrs.log_addr_mask = 0;
- adap->is_configuring = false;
- adap->is_configured = false;
- memset(adap->phys_addrs, 0xff, sizeof(adap->phys_addrs));
- wake_up_interruptible(&adap->kthread_waitq);
- cec_post_state_event(adap);
-}
-
-/*
- * Attempt to claim the required logical addresses.
- */
-static int cec_config_thread_func(void *arg)
-{
- /* The various LAs for each type of device */
- static const u8 tv_log_addrs[] = {
- CEC_LOG_ADDR_TV, CEC_LOG_ADDR_SPECIFIC,
- CEC_LOG_ADDR_INVALID
- };
- static const u8 record_log_addrs[] = {
- CEC_LOG_ADDR_RECORD_1, CEC_LOG_ADDR_RECORD_2,
- CEC_LOG_ADDR_RECORD_3,
- CEC_LOG_ADDR_BACKUP_1, CEC_LOG_ADDR_BACKUP_2,
- CEC_LOG_ADDR_INVALID
- };
- static const u8 tuner_log_addrs[] = {
- CEC_LOG_ADDR_TUNER_1, CEC_LOG_ADDR_TUNER_2,
- CEC_LOG_ADDR_TUNER_3, CEC_LOG_ADDR_TUNER_4,
- CEC_LOG_ADDR_BACKUP_1, CEC_LOG_ADDR_BACKUP_2,
- CEC_LOG_ADDR_INVALID
- };
- static const u8 playback_log_addrs[] = {
- CEC_LOG_ADDR_PLAYBACK_1, CEC_LOG_ADDR_PLAYBACK_2,
- CEC_LOG_ADDR_PLAYBACK_3,
- CEC_LOG_ADDR_BACKUP_1, CEC_LOG_ADDR_BACKUP_2,
- CEC_LOG_ADDR_INVALID
- };
- static const u8 audiosystem_log_addrs[] = {
- CEC_LOG_ADDR_AUDIOSYSTEM,
- CEC_LOG_ADDR_INVALID
- };
- static const u8 specific_use_log_addrs[] = {
- CEC_LOG_ADDR_SPECIFIC,
- CEC_LOG_ADDR_BACKUP_1, CEC_LOG_ADDR_BACKUP_2,
- CEC_LOG_ADDR_INVALID
- };
- static const u8 *type2addrs[6] = {
- [CEC_LOG_ADDR_TYPE_TV] = tv_log_addrs,
- [CEC_LOG_ADDR_TYPE_RECORD] = record_log_addrs,
- [CEC_LOG_ADDR_TYPE_TUNER] = tuner_log_addrs,
- [CEC_LOG_ADDR_TYPE_PLAYBACK] = playback_log_addrs,
- [CEC_LOG_ADDR_TYPE_AUDIOSYSTEM] = audiosystem_log_addrs,
- [CEC_LOG_ADDR_TYPE_SPECIFIC] = specific_use_log_addrs,
- };
- static const u16 type2mask[] = {
- [CEC_LOG_ADDR_TYPE_TV] = CEC_LOG_ADDR_MASK_TV,
- [CEC_LOG_ADDR_TYPE_RECORD] = CEC_LOG_ADDR_MASK_RECORD,
- [CEC_LOG_ADDR_TYPE_TUNER] = CEC_LOG_ADDR_MASK_TUNER,
- [CEC_LOG_ADDR_TYPE_PLAYBACK] = CEC_LOG_ADDR_MASK_PLAYBACK,
- [CEC_LOG_ADDR_TYPE_AUDIOSYSTEM] = CEC_LOG_ADDR_MASK_AUDIOSYSTEM,
- [CEC_LOG_ADDR_TYPE_SPECIFIC] = CEC_LOG_ADDR_MASK_SPECIFIC,
- };
- struct cec_adapter *adap = arg;
- struct cec_log_addrs *las = &adap->log_addrs;
- int err;
- int i, j;
-
- mutex_lock(&adap->lock);
- dprintk(1, "physical address: %x.%x.%x.%x, claim %d logical addresses\n",
- cec_phys_addr_exp(adap->phys_addr), las->num_log_addrs);
- las->log_addr_mask = 0;
-
- if (las->log_addr_type[0] == CEC_LOG_ADDR_TYPE_UNREGISTERED)
- goto configured;
-
- for (i = 0; i < las->num_log_addrs; i++) {
- unsigned int type = las->log_addr_type[i];
- const u8 *la_list;
- u8 last_la;
-
- /*
- * The TV functionality can only map to physical address 0.
- * For any other address, try the Specific functionality
- * instead as per the spec.
- */
- if (adap->phys_addr && type == CEC_LOG_ADDR_TYPE_TV)
- type = CEC_LOG_ADDR_TYPE_SPECIFIC;
-
- la_list = type2addrs[type];
- last_la = las->log_addr[i];
- las->log_addr[i] = CEC_LOG_ADDR_INVALID;
- if (last_la == CEC_LOG_ADDR_INVALID ||
- last_la == CEC_LOG_ADDR_UNREGISTERED ||
- !(last_la & type2mask[type]))
- last_la = la_list[0];
-
- err = cec_config_log_addr(adap, i, last_la);
- if (err > 0) /* Reused last LA */
- continue;
-
- if (err < 0)
- goto unconfigure;
-
- for (j = 0; la_list[j] != CEC_LOG_ADDR_INVALID; j++) {
- /* Tried this one already, skip it */
- if (la_list[j] == last_la)
- continue;
- /* The backup addresses are CEC 2.0 specific */
- if ((la_list[j] == CEC_LOG_ADDR_BACKUP_1 ||
- la_list[j] == CEC_LOG_ADDR_BACKUP_2) &&
- las->cec_version < CEC_OP_CEC_VERSION_2_0)
- continue;
-
- err = cec_config_log_addr(adap, i, la_list[j]);
- if (err == 0) /* LA is in use */
- continue;
- if (err < 0)
- goto unconfigure;
- /* Done, claimed an LA */
- break;
- }
-
- if (la_list[j] == CEC_LOG_ADDR_INVALID)
- dprintk(1, "could not claim LA %d\n", i);
- }
-
- if (adap->log_addrs.log_addr_mask == 0 &&
- !(las->flags & CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK))
- goto unconfigure;
-
-configured:
- if (adap->log_addrs.log_addr_mask == 0) {
- /* Fall back to unregistered */
- las->log_addr[0] = CEC_LOG_ADDR_UNREGISTERED;
- las->log_addr_mask = 1 << las->log_addr[0];
- for (i = 1; i < las->num_log_addrs; i++)
- las->log_addr[i] = CEC_LOG_ADDR_INVALID;
- }
- adap->is_configured = true;
- adap->is_configuring = false;
- cec_post_state_event(adap);
- mutex_unlock(&adap->lock);
-
- for (i = 0; i < las->num_log_addrs; i++) {
- if (las->log_addr[i] == CEC_LOG_ADDR_INVALID)
- continue;
-
- /*
- * Report Features must come first according
- * to CEC 2.0
- */
- if (las->log_addr[i] != CEC_LOG_ADDR_UNREGISTERED)
- cec_report_features(adap, i);
- cec_report_phys_addr(adap, i);
- }
- for (i = las->num_log_addrs; i < CEC_MAX_LOG_ADDRS; i++)
- las->log_addr[i] = CEC_LOG_ADDR_INVALID;
- mutex_lock(&adap->lock);
- adap->kthread_config = NULL;
- mutex_unlock(&adap->lock);
- complete(&adap->config_completion);
- return 0;
-
-unconfigure:
- for (i = 0; i < las->num_log_addrs; i++)
- las->log_addr[i] = CEC_LOG_ADDR_INVALID;
- cec_adap_unconfigure(adap);
- adap->kthread_config = NULL;
- mutex_unlock(&adap->lock);
- complete(&adap->config_completion);
- return 0;
-}
-
-/*
- * Called from either __cec_s_phys_addr or __cec_s_log_addrs to claim the
- * logical addresses.
- *
- * This function is called with adap->lock held.
- */
-static void cec_claim_log_addrs(struct cec_adapter *adap, bool block)
-{
- if (WARN_ON(adap->is_configuring || adap->is_configured))
- return;
-
- init_completion(&adap->config_completion);
-
- /* Ready to kick off the thread */
- adap->is_configuring = true;
- adap->kthread_config = kthread_run(cec_config_thread_func, adap,
- "ceccfg-%s", adap->name);
- if (IS_ERR(adap->kthread_config)) {
- adap->kthread_config = NULL;
- } else if (block) {
- mutex_unlock(&adap->lock);
- wait_for_completion(&adap->config_completion);
- mutex_lock(&adap->lock);
- }
-}
-
-/* Set a new physical address and send an event notifying userspace of this.
- *
- * This function is called with adap->lock held.
- */
-void __cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, bool block)
-{
- if (phys_addr == adap->phys_addr || adap->devnode.unregistered)
- return;
-
- if (phys_addr == CEC_PHYS_ADDR_INVALID ||
- adap->phys_addr != CEC_PHYS_ADDR_INVALID) {
- adap->phys_addr = CEC_PHYS_ADDR_INVALID;
- cec_post_state_event(adap);
- cec_adap_unconfigure(adap);
- /* Disabling monitor all mode should always succeed */
- if (adap->monitor_all_cnt)
- WARN_ON(call_op(adap, adap_monitor_all_enable, false));
- WARN_ON(adap->ops->adap_enable(adap, false));
- if (phys_addr == CEC_PHYS_ADDR_INVALID)
- return;
- }
-
- if (adap->ops->adap_enable(adap, true))
- return;
-
- if (adap->monitor_all_cnt &&
- call_op(adap, adap_monitor_all_enable, true)) {
- WARN_ON(adap->ops->adap_enable(adap, false));
- return;
- }
- adap->phys_addr = phys_addr;
- cec_post_state_event(adap);
- if (adap->log_addrs.num_log_addrs)
- cec_claim_log_addrs(adap, block);
-}
-
-void cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, bool block)
-{
- if (IS_ERR_OR_NULL(adap))
- return;
-
- mutex_lock(&adap->lock);
- __cec_s_phys_addr(adap, phys_addr, block);
- mutex_unlock(&adap->lock);
-}
-EXPORT_SYMBOL_GPL(cec_s_phys_addr);
-
-/*
- * Called from either the ioctl or a driver to set the logical addresses.
- *
- * This function is called with adap->lock held.
- */
-int __cec_s_log_addrs(struct cec_adapter *adap,
- struct cec_log_addrs *log_addrs, bool block)
-{
- u16 type_mask = 0;
- int i;
-
- if (adap->devnode.unregistered)
- return -ENODEV;
-
- if (!log_addrs || log_addrs->num_log_addrs == 0) {
- adap->log_addrs.num_log_addrs = 0;
- cec_adap_unconfigure(adap);
- return 0;
- }
-
- /* Ensure the osd name is 0-terminated */
- log_addrs->osd_name[sizeof(log_addrs->osd_name) - 1] = '\0';
-
- /* Sanity checks */
- if (log_addrs->num_log_addrs > adap->available_log_addrs) {
- dprintk(1, "num_log_addrs > %d\n", adap->available_log_addrs);
- return -EINVAL;
- }
-
- /*
- * Vendor ID is a 24 bit number, so check if the value is
- * within the correct range.
- */
- if (log_addrs->vendor_id != CEC_VENDOR_ID_NONE &&
- (log_addrs->vendor_id & 0xff000000) != 0)
- return -EINVAL;
-
- if (log_addrs->cec_version != CEC_OP_CEC_VERSION_1_4 &&
- log_addrs->cec_version != CEC_OP_CEC_VERSION_2_0)
- return -EINVAL;
-
- if (log_addrs->num_log_addrs > 1)
- for (i = 0; i < log_addrs->num_log_addrs; i++)
- if (log_addrs->log_addr_type[i] ==
- CEC_LOG_ADDR_TYPE_UNREGISTERED) {
- dprintk(1, "num_log_addrs > 1 can't be combined with unregistered LA\n");
- return -EINVAL;
- }
-
- for (i = 0; i < log_addrs->num_log_addrs; i++) {
- const u8 feature_sz = ARRAY_SIZE(log_addrs->features[0]);
- u8 *features = log_addrs->features[i];
- bool op_is_dev_features = false;
-
- log_addrs->log_addr[i] = CEC_LOG_ADDR_INVALID;
- if (type_mask & (1 << log_addrs->log_addr_type[i])) {
- dprintk(1, "duplicate logical address type\n");
- return -EINVAL;
- }
- type_mask |= 1 << log_addrs->log_addr_type[i];
- if ((type_mask & (1 << CEC_LOG_ADDR_TYPE_RECORD)) &&
- (type_mask & (1 << CEC_LOG_ADDR_TYPE_PLAYBACK))) {
- /* Record already contains the playback functionality */
- dprintk(1, "invalid record + playback combination\n");
- return -EINVAL;
- }
- if (log_addrs->primary_device_type[i] >
- CEC_OP_PRIM_DEVTYPE_PROCESSOR) {
- dprintk(1, "unknown primary device type\n");
- return -EINVAL;
- }
- if (log_addrs->primary_device_type[i] == 2) {
- dprintk(1, "invalid primary device type\n");
- return -EINVAL;
- }
- if (log_addrs->log_addr_type[i] > CEC_LOG_ADDR_TYPE_UNREGISTERED) {
- dprintk(1, "unknown logical address type\n");
- return -EINVAL;
- }
- for (i = 0; i < feature_sz; i++) {
- if ((features[i] & 0x80) == 0) {
- if (op_is_dev_features)
- break;
- op_is_dev_features = true;
- }
- }
- if (!op_is_dev_features || i == feature_sz) {
- dprintk(1, "malformed features\n");
- return -EINVAL;
- }
- /* Zero unused part of the feature array */
- memset(features + i + 1, 0, feature_sz - i - 1);
- }
-
- if (log_addrs->cec_version >= CEC_OP_CEC_VERSION_2_0) {
- if (log_addrs->num_log_addrs > 2) {
- dprintk(1, "CEC 2.0 allows no more than 2 logical addresses\n");
- return -EINVAL;
- }
- if (log_addrs->num_log_addrs == 2) {
- if (!(type_mask & ((1 << CEC_LOG_ADDR_TYPE_AUDIOSYSTEM) |
- (1 << CEC_LOG_ADDR_TYPE_TV)))) {
- dprintk(1, "Two LAs is only allowed for audiosystem and TV\n");
- return -EINVAL;
- }
- if (!(type_mask & ((1 << CEC_LOG_ADDR_TYPE_PLAYBACK) |
- (1 << CEC_LOG_ADDR_TYPE_RECORD)))) {
- dprintk(1, "An audiosystem/TV can only be combined with record or playback\n");
- return -EINVAL;
- }
- }
- }
-
- /* Zero unused LAs */
- for (i = log_addrs->num_log_addrs; i < CEC_MAX_LOG_ADDRS; i++) {
- log_addrs->primary_device_type[i] = 0;
- log_addrs->log_addr_type[i] = 0;
- log_addrs->all_device_types[i] = 0;
- memset(log_addrs->features[i], 0,
- sizeof(log_addrs->features[i]));
- }
-
- log_addrs->log_addr_mask = adap->log_addrs.log_addr_mask;
- adap->log_addrs = *log_addrs;
- if (adap->phys_addr != CEC_PHYS_ADDR_INVALID)
- cec_claim_log_addrs(adap, block);
- return 0;
-}
-
-int cec_s_log_addrs(struct cec_adapter *adap,
- struct cec_log_addrs *log_addrs, bool block)
-{
- int err;
-
- mutex_lock(&adap->lock);
- err = __cec_s_log_addrs(adap, log_addrs, block);
- mutex_unlock(&adap->lock);
- return err;
-}
-EXPORT_SYMBOL_GPL(cec_s_log_addrs);
-
-/* High-level core CEC message handling */
-
-/* Transmit the Report Features message */
-static int cec_report_features(struct cec_adapter *adap, unsigned int la_idx)
-{
- struct cec_msg msg = { };
- const struct cec_log_addrs *las = &adap->log_addrs;
- const u8 *features = las->features[la_idx];
- bool op_is_dev_features = false;
- unsigned int idx;
-
- /* This is 2.0 and up only */
- if (adap->log_addrs.cec_version < CEC_OP_CEC_VERSION_2_0)
- return 0;
-
- /* Report Features */
- msg.msg[0] = (las->log_addr[la_idx] << 4) | 0x0f;
- msg.len = 4;
- msg.msg[1] = CEC_MSG_REPORT_FEATURES;
- msg.msg[2] = adap->log_addrs.cec_version;
- msg.msg[3] = las->all_device_types[la_idx];
-
- /* Write RC Profiles first, then Device Features */
- for (idx = 0; idx < ARRAY_SIZE(las->features[0]); idx++) {
- msg.msg[msg.len++] = features[idx];
- if ((features[idx] & CEC_OP_FEAT_EXT) == 0) {
- if (op_is_dev_features)
- break;
- op_is_dev_features = true;
- }
- }
- return cec_transmit_msg(adap, &msg, false);
-}
-
-/* Transmit the Report Physical Address message */
-static int cec_report_phys_addr(struct cec_adapter *adap, unsigned int la_idx)
-{
- const struct cec_log_addrs *las = &adap->log_addrs;
- struct cec_msg msg = { };
-
- /* Report Physical Address */
- msg.msg[0] = (las->log_addr[la_idx] << 4) | 0x0f;
- cec_msg_report_physical_addr(&msg, adap->phys_addr,
- las->primary_device_type[la_idx]);
- dprintk(2, "config: la %d pa %x.%x.%x.%x\n",
- las->log_addr[la_idx],
- cec_phys_addr_exp(adap->phys_addr));
- return cec_transmit_msg(adap, &msg, false);
-}
-
-/* Transmit the Feature Abort message */
-static int cec_feature_abort_reason(struct cec_adapter *adap,
- struct cec_msg *msg, u8 reason)
-{
- struct cec_msg tx_msg = { };
-
- /*
- * Don't reply with CEC_MSG_FEATURE_ABORT to a CEC_MSG_FEATURE_ABORT
- * message!
- */
- if (msg->msg[1] == CEC_MSG_FEATURE_ABORT)
- return 0;
- cec_msg_set_reply_to(&tx_msg, msg);
- cec_msg_feature_abort(&tx_msg, msg->msg[1], reason);
- return cec_transmit_msg(adap, &tx_msg, false);
-}
-
-static int cec_feature_abort(struct cec_adapter *adap, struct cec_msg *msg)
-{
- return cec_feature_abort_reason(adap, msg,
- CEC_OP_ABORT_UNRECOGNIZED_OP);
-}
-
-static int cec_feature_refused(struct cec_adapter *adap, struct cec_msg *msg)
-{
- return cec_feature_abort_reason(adap, msg,
- CEC_OP_ABORT_REFUSED);
-}
-
-/*
- * Called when a CEC message is received. This function will do any
- * necessary core processing. The is_reply bool is true if this message
- * is a reply to an earlier transmit.
- *
- * The message is either a broadcast message or a valid directed message.
- */
-static int cec_receive_notify(struct cec_adapter *adap, struct cec_msg *msg,
- bool is_reply)
-{
- bool is_broadcast = cec_msg_is_broadcast(msg);
- u8 dest_laddr = cec_msg_destination(msg);
- u8 init_laddr = cec_msg_initiator(msg);
- u8 devtype = cec_log_addr2dev(adap, dest_laddr);
- int la_idx = cec_log_addr2idx(adap, dest_laddr);
- bool from_unregistered = init_laddr == 0xf;
- struct cec_msg tx_cec_msg = { };
-
- dprintk(1, "cec_receive_notify: %*ph\n", msg->len, msg->msg);
-
- if (adap->ops->received) {
- /* Allow drivers to process the message first */
- if (adap->ops->received(adap, msg) != -ENOMSG)
- return 0;
- }
-
- /*
- * REPORT_PHYSICAL_ADDR, CEC_MSG_USER_CONTROL_PRESSED and
- * CEC_MSG_USER_CONTROL_RELEASED messages always have to be
- * handled by the CEC core, even if the passthrough mode is on.
- * The others are just ignored if passthrough mode is on.
- */
- switch (msg->msg[1]) {
- case CEC_MSG_GET_CEC_VERSION:
- case CEC_MSG_GIVE_DEVICE_VENDOR_ID:
- case CEC_MSG_ABORT:
- case CEC_MSG_GIVE_DEVICE_POWER_STATUS:
- case CEC_MSG_GIVE_PHYSICAL_ADDR:
- case CEC_MSG_GIVE_OSD_NAME:
- case CEC_MSG_GIVE_FEATURES:
- /*
- * Skip processing these messages if the passthrough mode
- * is on.
- */
- if (adap->passthrough)
- goto skip_processing;
- /* Ignore if addressing is wrong */
- if (is_broadcast || from_unregistered)
- return 0;
- break;
-
- case CEC_MSG_USER_CONTROL_PRESSED:
- case CEC_MSG_USER_CONTROL_RELEASED:
- /* Wrong addressing mode: don't process */
- if (is_broadcast || from_unregistered)
- goto skip_processing;
- break;
-
- case CEC_MSG_REPORT_PHYSICAL_ADDR:
- /*
- * This message is always processed, regardless of the
- * passthrough setting.
- *
- * Exception: don't process if wrong addressing mode.
- */
- if (!is_broadcast)
- goto skip_processing;
- break;
-
- default:
- break;
- }
-
- cec_msg_set_reply_to(&tx_cec_msg, msg);
-
- switch (msg->msg[1]) {
- /* The following messages are processed but still passed through */
- case CEC_MSG_REPORT_PHYSICAL_ADDR: {
- u16 pa = (msg->msg[2] << 8) | msg->msg[3];
-
- if (!from_unregistered)
- adap->phys_addrs[init_laddr] = pa;
- dprintk(1, "Reported physical address %x.%x.%x.%x for logical address %d\n",
- cec_phys_addr_exp(pa), init_laddr);
- break;
- }
-
- case CEC_MSG_USER_CONTROL_PRESSED:
- if (!(adap->capabilities & CEC_CAP_RC))
- break;
-
-#if IS_REACHABLE(CONFIG_RC_CORE)
- switch (msg->msg[2]) {
- /*
- * Play function, this message can have variable length
- * depending on the specific play function that is used.
- */
- case 0x60:
- if (msg->len == 2)
- rc_keydown(adap->rc, RC_TYPE_CEC,
- msg->msg[2], 0);
- else
- rc_keydown(adap->rc, RC_TYPE_CEC,
- msg->msg[2] << 8 | msg->msg[3], 0);
- break;
- /*
- * Other function messages that are not handled.
- * Currently the RC framework does not allow to supply an
- * additional parameter to a keypress. These "keys" contain
- * other information such as channel number, an input number
- * etc.
- * For the time being these messages are not processed by the
- * framework and are simply forwarded to the user space.
- */
- case 0x56: case 0x57:
- case 0x67: case 0x68: case 0x69: case 0x6a:
- break;
- default:
- rc_keydown(adap->rc, RC_TYPE_CEC, msg->msg[2], 0);
- break;
- }
-#endif
- break;
-
- case CEC_MSG_USER_CONTROL_RELEASED:
- if (!(adap->capabilities & CEC_CAP_RC))
- break;
-#if IS_REACHABLE(CONFIG_RC_CORE)
- rc_keyup(adap->rc);
-#endif
- break;
-
- /*
- * The remaining messages are only processed if the passthrough mode
- * is off.
- */
- case CEC_MSG_GET_CEC_VERSION:
- cec_msg_cec_version(&tx_cec_msg, adap->log_addrs.cec_version);
- return cec_transmit_msg(adap, &tx_cec_msg, false);
-
- case CEC_MSG_GIVE_PHYSICAL_ADDR:
- /* Do nothing for CEC switches using addr 15 */
- if (devtype == CEC_OP_PRIM_DEVTYPE_SWITCH && dest_laddr == 15)
- return 0;
- cec_msg_report_physical_addr(&tx_cec_msg, adap->phys_addr, devtype);
- return cec_transmit_msg(adap, &tx_cec_msg, false);
-
- case CEC_MSG_GIVE_DEVICE_VENDOR_ID:
- if (adap->log_addrs.vendor_id == CEC_VENDOR_ID_NONE)
- return cec_feature_abort(adap, msg);
- cec_msg_device_vendor_id(&tx_cec_msg, adap->log_addrs.vendor_id);
- return cec_transmit_msg(adap, &tx_cec_msg, false);
-
- case CEC_MSG_ABORT:
- /* Do nothing for CEC switches */
- if (devtype == CEC_OP_PRIM_DEVTYPE_SWITCH)
- return 0;
- return cec_feature_refused(adap, msg);
-
- case CEC_MSG_GIVE_OSD_NAME: {
- if (adap->log_addrs.osd_name[0] == 0)
- return cec_feature_abort(adap, msg);
- cec_msg_set_osd_name(&tx_cec_msg, adap->log_addrs.osd_name);
- return cec_transmit_msg(adap, &tx_cec_msg, false);
- }
-
- case CEC_MSG_GIVE_FEATURES:
- if (adap->log_addrs.cec_version >= CEC_OP_CEC_VERSION_2_0)
- return cec_report_features(adap, la_idx);
- return 0;
-
- default:
- /*
- * Unprocessed messages are aborted if userspace isn't doing
- * any processing either.
- */
- if (!is_broadcast && !is_reply && !adap->follower_cnt &&
- !adap->cec_follower && msg->msg[1] != CEC_MSG_FEATURE_ABORT)
- return cec_feature_abort(adap, msg);
- break;
- }
-
-skip_processing:
- /* If this was a reply, then we're done */
- if (is_reply)
- return 0;
-
- /*
- * Send to the exclusive follower if there is one, otherwise send
- * to all followers.
- */
- if (adap->cec_follower)
- cec_queue_msg_fh(adap->cec_follower, msg);
- else
- cec_queue_msg_followers(adap, msg);
- return 0;
-}
-
-/*
- * Helper functions to keep track of the 'monitor all' use count.
- *
- * These functions are called with adap->lock held.
- */
-int cec_monitor_all_cnt_inc(struct cec_adapter *adap)
-{
- int ret = 0;
-
- if (adap->monitor_all_cnt == 0)
- ret = call_op(adap, adap_monitor_all_enable, 1);
- if (ret == 0)
- adap->monitor_all_cnt++;
- return ret;
-}
-
-void cec_monitor_all_cnt_dec(struct cec_adapter *adap)
-{
- adap->monitor_all_cnt--;
- if (adap->monitor_all_cnt == 0)
- WARN_ON(call_op(adap, adap_monitor_all_enable, 0));
-}
-
-#ifdef CONFIG_MEDIA_CEC_DEBUG
-/*
- * Log the current state of the CEC adapter.
- * Very useful for debugging.
- */
-int cec_adap_status(struct seq_file *file, void *priv)
-{
- struct cec_adapter *adap = dev_get_drvdata(file->private);
- struct cec_data *data;
-
- mutex_lock(&adap->lock);
- seq_printf(file, "configured: %d\n", adap->is_configured);
- seq_printf(file, "configuring: %d\n", adap->is_configuring);
- seq_printf(file, "phys_addr: %x.%x.%x.%x\n",
- cec_phys_addr_exp(adap->phys_addr));
- seq_printf(file, "number of LAs: %d\n", adap->log_addrs.num_log_addrs);
- seq_printf(file, "LA mask: 0x%04x\n", adap->log_addrs.log_addr_mask);
- if (adap->cec_follower)
- seq_printf(file, "has CEC follower%s\n",
- adap->passthrough ? " (in passthrough mode)" : "");
- if (adap->cec_initiator)
- seq_puts(file, "has CEC initiator\n");
- if (adap->monitor_all_cnt)
- seq_printf(file, "file handles in Monitor All mode: %u\n",
- adap->monitor_all_cnt);
- data = adap->transmitting;
- if (data)
- seq_printf(file, "transmitting message: %*ph (reply: %02x, timeout: %ums)\n",
- data->msg.len, data->msg.msg, data->msg.reply,
- data->msg.timeout);
- seq_printf(file, "pending transmits: %u\n", adap->transmit_queue_sz);
- list_for_each_entry(data, &adap->transmit_queue, list) {
- seq_printf(file, "queued tx message: %*ph (reply: %02x, timeout: %ums)\n",
- data->msg.len, data->msg.msg, data->msg.reply,
- data->msg.timeout);
- }
- list_for_each_entry(data, &adap->wait_queue, list) {
- seq_printf(file, "message waiting for reply: %*ph (reply: %02x, timeout: %ums)\n",
- data->msg.len, data->msg.msg, data->msg.reply,
- data->msg.timeout);
- }
-
- call_void_op(adap, adap_status, file);
- mutex_unlock(&adap->lock);
- return 0;
-}
-#endif
diff --git a/drivers/staging/media/cec/cec-api.c b/drivers/staging/media/cec/cec-api.c
deleted file mode 100644
index e274e2f22398..000000000000
--- a/drivers/staging/media/cec/cec-api.c
+++ /dev/null
@@ -1,579 +0,0 @@
-/*
- * cec-api.c - HDMI Consumer Electronics Control framework - API
- *
- * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
- *
- * This program is free software; you may redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/kmod.h>
-#include <linux/ktime.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/string.h>
-#include <linux/types.h>
-#include <linux/uaccess.h>
-#include <linux/version.h>
-
-#include "cec-priv.h"
-
-static inline struct cec_devnode *cec_devnode_data(struct file *filp)
-{
- struct cec_fh *fh = filp->private_data;
-
- return &fh->adap->devnode;
-}
-
-/* CEC file operations */
-
-static unsigned int cec_poll(struct file *filp,
- struct poll_table_struct *poll)
-{
- struct cec_devnode *devnode = cec_devnode_data(filp);
- struct cec_fh *fh = filp->private_data;
- struct cec_adapter *adap = fh->adap;
- unsigned int res = 0;
-
- if (!devnode->registered)
- return POLLERR | POLLHUP;
- mutex_lock(&adap->lock);
- if (adap->is_configured &&
- adap->transmit_queue_sz < CEC_MAX_MSG_TX_QUEUE_SZ)
- res |= POLLOUT | POLLWRNORM;
- if (fh->queued_msgs)
- res |= POLLIN | POLLRDNORM;
- if (fh->pending_events)
- res |= POLLPRI;
- poll_wait(filp, &fh->wait, poll);
- mutex_unlock(&adap->lock);
- return res;
-}
-
-static bool cec_is_busy(const struct cec_adapter *adap,
- const struct cec_fh *fh)
-{
- bool valid_initiator = adap->cec_initiator && adap->cec_initiator == fh;
- bool valid_follower = adap->cec_follower && adap->cec_follower == fh;
-
- /*
- * Exclusive initiators and followers can always access the CEC adapter
- */
- if (valid_initiator || valid_follower)
- return false;
- /*
- * All others can only access the CEC adapter if there is no
- * exclusive initiator and they are in INITIATOR mode.
- */
- return adap->cec_initiator ||
- fh->mode_initiator == CEC_MODE_NO_INITIATOR;
-}
-
-static long cec_adap_g_caps(struct cec_adapter *adap,
- struct cec_caps __user *parg)
-{
- struct cec_caps caps = {};
-
- strlcpy(caps.driver, adap->devnode.parent->driver->name,
- sizeof(caps.driver));
- strlcpy(caps.name, adap->name, sizeof(caps.name));
- caps.available_log_addrs = adap->available_log_addrs;
- caps.capabilities = adap->capabilities;
- caps.version = LINUX_VERSION_CODE;
- if (copy_to_user(parg, &caps, sizeof(caps)))
- return -EFAULT;
- return 0;
-}
-
-static long cec_adap_g_phys_addr(struct cec_adapter *adap,
- __u16 __user *parg)
-{
- u16 phys_addr;
-
- mutex_lock(&adap->lock);
- phys_addr = adap->phys_addr;
- mutex_unlock(&adap->lock);
- if (copy_to_user(parg, &phys_addr, sizeof(phys_addr)))
- return -EFAULT;
- return 0;
-}
-
-static long cec_adap_s_phys_addr(struct cec_adapter *adap, struct cec_fh *fh,
- bool block, __u16 __user *parg)
-{
- u16 phys_addr;
- long err;
-
- if (!(adap->capabilities & CEC_CAP_PHYS_ADDR))
- return -ENOTTY;
- if (copy_from_user(&phys_addr, parg, sizeof(phys_addr)))
- return -EFAULT;
-
- err = cec_phys_addr_validate(phys_addr, NULL, NULL);
- if (err)
- return err;
- mutex_lock(&adap->lock);
- if (cec_is_busy(adap, fh))
- err = -EBUSY;
- else
- __cec_s_phys_addr(adap, phys_addr, block);
- mutex_unlock(&adap->lock);
- return err;
-}
-
-static long cec_adap_g_log_addrs(struct cec_adapter *adap,
- struct cec_log_addrs __user *parg)
-{
- struct cec_log_addrs log_addrs;
-
- mutex_lock(&adap->lock);
- log_addrs = adap->log_addrs;
- if (!adap->is_configured)
- memset(log_addrs.log_addr, CEC_LOG_ADDR_INVALID,
- sizeof(log_addrs.log_addr));
- mutex_unlock(&adap->lock);
-
- if (copy_to_user(parg, &log_addrs, sizeof(log_addrs)))
- return -EFAULT;
- return 0;
-}
-
-static long cec_adap_s_log_addrs(struct cec_adapter *adap, struct cec_fh *fh,
- bool block, struct cec_log_addrs __user *parg)
-{
- struct cec_log_addrs log_addrs;
- long err = -EBUSY;
-
- if (!(adap->capabilities & CEC_CAP_LOG_ADDRS))
- return -ENOTTY;
- if (copy_from_user(&log_addrs, parg, sizeof(log_addrs)))
- return -EFAULT;
- log_addrs.flags &= CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK;
- mutex_lock(&adap->lock);
- if (!adap->is_configuring &&
- (!log_addrs.num_log_addrs || !adap->is_configured) &&
- !cec_is_busy(adap, fh)) {
- err = __cec_s_log_addrs(adap, &log_addrs, block);
- if (!err)
- log_addrs = adap->log_addrs;
- }
- mutex_unlock(&adap->lock);
- if (err)
- return err;
- if (copy_to_user(parg, &log_addrs, sizeof(log_addrs)))
- return -EFAULT;
- return 0;
-}
-
-static long cec_transmit(struct cec_adapter *adap, struct cec_fh *fh,
- bool block, struct cec_msg __user *parg)
-{
- struct cec_msg msg = {};
- long err = 0;
-
- if (!(adap->capabilities & CEC_CAP_TRANSMIT))
- return -ENOTTY;
- if (copy_from_user(&msg, parg, sizeof(msg)))
- return -EFAULT;
- mutex_lock(&adap->lock);
- if (!adap->is_configured)
- err = -ENONET;
- else if (cec_is_busy(adap, fh))
- err = -EBUSY;
- else
- err = cec_transmit_msg_fh(adap, &msg, fh, block);
- mutex_unlock(&adap->lock);
- if (err)
- return err;
- if (copy_to_user(parg, &msg, sizeof(msg)))
- return -EFAULT;
- return 0;
-}
-
-/* Called by CEC_RECEIVE: wait for a message to arrive */
-static int cec_receive_msg(struct cec_fh *fh, struct cec_msg *msg, bool block)
-{
- u32 timeout = msg->timeout;
- int res;
-
- do {
- mutex_lock(&fh->lock);
- /* Are there received messages queued up? */
- if (fh->queued_msgs) {
- /* Yes, return the first one */
- struct cec_msg_entry *entry =
- list_first_entry(&fh->msgs,
- struct cec_msg_entry, list);
-
- list_del(&entry->list);
- *msg = entry->msg;
- kfree(entry);
- fh->queued_msgs--;
- mutex_unlock(&fh->lock);
- /* restore original timeout value */
- msg->timeout = timeout;
- return 0;
- }
-
- /* No, return EAGAIN in non-blocking mode or wait */
- mutex_unlock(&fh->lock);
-
- /* Return when in non-blocking mode */
- if (!block)
- return -EAGAIN;
-
- if (msg->timeout) {
- /* The user specified a timeout */
- res = wait_event_interruptible_timeout(fh->wait,
- fh->queued_msgs,
- msecs_to_jiffies(msg->timeout));
- if (res == 0)
- res = -ETIMEDOUT;
- else if (res > 0)
- res = 0;
- } else {
- /* Wait indefinitely */
- res = wait_event_interruptible(fh->wait,
- fh->queued_msgs);
- }
- /* Exit on error, otherwise loop to get the new message */
- } while (!res);
- return res;
-}
-
-static long cec_receive(struct cec_adapter *adap, struct cec_fh *fh,
- bool block, struct cec_msg __user *parg)
-{
- struct cec_msg msg = {};
- long err = 0;
-
- if (copy_from_user(&msg, parg, sizeof(msg)))
- return -EFAULT;
- mutex_lock(&adap->lock);
- if (!adap->is_configured && fh->mode_follower < CEC_MODE_MONITOR)
- err = -ENONET;
- mutex_unlock(&adap->lock);
- if (err)
- return err;
-
- err = cec_receive_msg(fh, &msg, block);
- if (err)
- return err;
- if (copy_to_user(parg, &msg, sizeof(msg)))
- return -EFAULT;
- return 0;
-}
-
-static long cec_dqevent(struct cec_adapter *adap, struct cec_fh *fh,
- bool block, struct cec_event __user *parg)
-{
- struct cec_event *ev = NULL;
- u64 ts = ~0ULL;
- unsigned int i;
- long err = 0;
-
- mutex_lock(&fh->lock);
- while (!fh->pending_events && block) {
- mutex_unlock(&fh->lock);
- err = wait_event_interruptible(fh->wait, fh->pending_events);
- if (err)
- return err;
- mutex_lock(&fh->lock);
- }
-
- /* Find the oldest event */
- for (i = 0; i < CEC_NUM_EVENTS; i++) {
- if (fh->pending_events & (1 << (i + 1)) &&
- fh->events[i].ts <= ts) {
- ev = &fh->events[i];
- ts = ev->ts;
- }
- }
- if (!ev) {
- err = -EAGAIN;
- goto unlock;
- }
-
- if (copy_to_user(parg, ev, sizeof(*ev))) {
- err = -EFAULT;
- goto unlock;
- }
-
- fh->pending_events &= ~(1 << ev->event);
-
-unlock:
- mutex_unlock(&fh->lock);
- return err;
-}
-
-static long cec_g_mode(struct cec_adapter *adap, struct cec_fh *fh,
- u32 __user *parg)
-{
- u32 mode = fh->mode_initiator | fh->mode_follower;
-
- if (copy_to_user(parg, &mode, sizeof(mode)))
- return -EFAULT;
- return 0;
-}
-
-static long cec_s_mode(struct cec_adapter *adap, struct cec_fh *fh,
- u32 __user *parg)
-{
- u32 mode;
- u8 mode_initiator;
- u8 mode_follower;
- long err = 0;
-
- if (copy_from_user(&mode, parg, sizeof(mode)))
- return -EFAULT;
- if (mode & ~(CEC_MODE_INITIATOR_MSK | CEC_MODE_FOLLOWER_MSK))
- return -EINVAL;
-
- mode_initiator = mode & CEC_MODE_INITIATOR_MSK;
- mode_follower = mode & CEC_MODE_FOLLOWER_MSK;
-
- if (mode_initiator > CEC_MODE_EXCL_INITIATOR ||
- mode_follower > CEC_MODE_MONITOR_ALL)
- return -EINVAL;
-
- if (mode_follower == CEC_MODE_MONITOR_ALL &&
- !(adap->capabilities & CEC_CAP_MONITOR_ALL))
- return -EINVAL;
-
- /* Follower modes should always be able to send CEC messages */
- if ((mode_initiator == CEC_MODE_NO_INITIATOR ||
- !(adap->capabilities & CEC_CAP_TRANSMIT)) &&
- mode_follower >= CEC_MODE_FOLLOWER &&
- mode_follower <= CEC_MODE_EXCL_FOLLOWER_PASSTHRU)
- return -EINVAL;
-
- /* Monitor modes require CEC_MODE_NO_INITIATOR */
- if (mode_initiator && mode_follower >= CEC_MODE_MONITOR)
- return -EINVAL;
-
- /* Monitor modes require CAP_NET_ADMIN */
- if (mode_follower >= CEC_MODE_MONITOR && !capable(CAP_NET_ADMIN))
- return -EPERM;
-
- mutex_lock(&adap->lock);
- /*
- * You can't become exclusive follower if someone else already
- * has that job.
- */
- if ((mode_follower == CEC_MODE_EXCL_FOLLOWER ||
- mode_follower == CEC_MODE_EXCL_FOLLOWER_PASSTHRU) &&
- adap->cec_follower && adap->cec_follower != fh)
- err = -EBUSY;
- /*
- * You can't become exclusive initiator if someone else already
- * has that job.
- */
- if (mode_initiator == CEC_MODE_EXCL_INITIATOR &&
- adap->cec_initiator && adap->cec_initiator != fh)
- err = -EBUSY;
-
- if (!err) {
- bool old_mon_all = fh->mode_follower == CEC_MODE_MONITOR_ALL;
- bool new_mon_all = mode_follower == CEC_MODE_MONITOR_ALL;
-
- if (old_mon_all != new_mon_all) {
- if (new_mon_all)
- err = cec_monitor_all_cnt_inc(adap);
- else
- cec_monitor_all_cnt_dec(adap);
- }
- }
-
- if (err) {
- mutex_unlock(&adap->lock);
- return err;
- }
-
- if (fh->mode_follower == CEC_MODE_FOLLOWER)
- adap->follower_cnt--;
- if (mode_follower == CEC_MODE_FOLLOWER)
- adap->follower_cnt++;
- if (mode_follower == CEC_MODE_EXCL_FOLLOWER ||
- mode_follower == CEC_MODE_EXCL_FOLLOWER_PASSTHRU) {
- adap->passthrough =
- mode_follower == CEC_MODE_EXCL_FOLLOWER_PASSTHRU;
- adap->cec_follower = fh;
- } else if (adap->cec_follower == fh) {
- adap->passthrough = false;
- adap->cec_follower = NULL;
- }
- if (mode_initiator == CEC_MODE_EXCL_INITIATOR)
- adap->cec_initiator = fh;
- else if (adap->cec_initiator == fh)
- adap->cec_initiator = NULL;
- fh->mode_initiator = mode_initiator;
- fh->mode_follower = mode_follower;
- mutex_unlock(&adap->lock);
- return 0;
-}
-
-static long cec_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
- struct cec_devnode *devnode = cec_devnode_data(filp);
- struct cec_fh *fh = filp->private_data;
- struct cec_adapter *adap = fh->adap;
- bool block = !(filp->f_flags & O_NONBLOCK);
- void __user *parg = (void __user *)arg;
-
- if (!devnode->registered)
- return -ENODEV;
-
- switch (cmd) {
- case CEC_ADAP_G_CAPS:
- return cec_adap_g_caps(adap, parg);
-
- case CEC_ADAP_G_PHYS_ADDR:
- return cec_adap_g_phys_addr(adap, parg);
-
- case CEC_ADAP_S_PHYS_ADDR:
- return cec_adap_s_phys_addr(adap, fh, block, parg);
-
- case CEC_ADAP_G_LOG_ADDRS:
- return cec_adap_g_log_addrs(adap, parg);
-
- case CEC_ADAP_S_LOG_ADDRS:
- return cec_adap_s_log_addrs(adap, fh, block, parg);
-
- case CEC_TRANSMIT:
- return cec_transmit(adap, fh, block, parg);
-
- case CEC_RECEIVE:
- return cec_receive(adap, fh, block, parg);
-
- case CEC_DQEVENT:
- return cec_dqevent(adap, fh, block, parg);
-
- case CEC_G_MODE:
- return cec_g_mode(adap, fh, parg);
-
- case CEC_S_MODE:
- return cec_s_mode(adap, fh, parg);
-
- default:
- return -ENOTTY;
- }
-}
-
-static int cec_open(struct inode *inode, struct file *filp)
-{
- struct cec_devnode *devnode =
- container_of(inode->i_cdev, struct cec_devnode, cdev);
- struct cec_adapter *adap = to_cec_adapter(devnode);
- struct cec_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL);
- /*
- * Initial events that are automatically sent when the cec device is
- * opened.
- */
- struct cec_event ev_state = {
- .event = CEC_EVENT_STATE_CHANGE,
- .flags = CEC_EVENT_FL_INITIAL_STATE,
- };
- int err;
-
- if (!fh)
- return -ENOMEM;
-
- INIT_LIST_HEAD(&fh->msgs);
- INIT_LIST_HEAD(&fh->xfer_list);
- mutex_init(&fh->lock);
- init_waitqueue_head(&fh->wait);
-
- fh->mode_initiator = CEC_MODE_INITIATOR;
- fh->adap = adap;
-
- err = cec_get_device(devnode);
- if (err) {
- kfree(fh);
- return err;
- }
-
- filp->private_data = fh;
-
- mutex_lock(&devnode->lock);
- /* Queue up initial state events */
- ev_state.state_change.phys_addr = adap->phys_addr;
- ev_state.state_change.log_addr_mask = adap->log_addrs.log_addr_mask;
- cec_queue_event_fh(fh, &ev_state, 0);
-
- list_add(&fh->list, &devnode->fhs);
- mutex_unlock(&devnode->lock);
-
- return 0;
-}
-
-/* Override for the release function */
-static int cec_release(struct inode *inode, struct file *filp)
-{
- struct cec_devnode *devnode = cec_devnode_data(filp);
- struct cec_adapter *adap = to_cec_adapter(devnode);
- struct cec_fh *fh = filp->private_data;
-
- mutex_lock(&adap->lock);
- if (adap->cec_initiator == fh)
- adap->cec_initiator = NULL;
- if (adap->cec_follower == fh) {
- adap->cec_follower = NULL;
- adap->passthrough = false;
- }
- if (fh->mode_follower == CEC_MODE_FOLLOWER)
- adap->follower_cnt--;
- if (fh->mode_follower == CEC_MODE_MONITOR_ALL)
- cec_monitor_all_cnt_dec(adap);
- mutex_unlock(&adap->lock);
-
- mutex_lock(&devnode->lock);
- list_del(&fh->list);
- mutex_unlock(&devnode->lock);
-
- /* Unhook pending transmits from this filehandle. */
- mutex_lock(&adap->lock);
- while (!list_empty(&fh->xfer_list)) {
- struct cec_data *data =
- list_first_entry(&fh->xfer_list, struct cec_data, xfer_list);
-
- data->blocking = false;
- data->fh = NULL;
- list_del(&data->xfer_list);
- }
- mutex_unlock(&adap->lock);
- while (!list_empty(&fh->msgs)) {
- struct cec_msg_entry *entry =
- list_first_entry(&fh->msgs, struct cec_msg_entry, list);
-
- list_del(&entry->list);
- kfree(entry);
- }
- kfree(fh);
-
- cec_put_device(devnode);
- filp->private_data = NULL;
- return 0;
-}
-
-const struct file_operations cec_devnode_fops = {
- .owner = THIS_MODULE,
- .open = cec_open,
- .unlocked_ioctl = cec_ioctl,
- .release = cec_release,
- .poll = cec_poll,
- .llseek = no_llseek,
-};
diff --git a/drivers/staging/media/cec/cec-core.c b/drivers/staging/media/cec/cec-core.c
deleted file mode 100644
index b0137e247dc9..000000000000
--- a/drivers/staging/media/cec/cec-core.c
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * cec-core.c - HDMI Consumer Electronics Control framework - Core
- *
- * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
- *
- * This program is free software; you may redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <linux/errno.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/kmod.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/string.h>
-#include <linux/types.h>
-
-#include "cec-priv.h"
-
-#define CEC_NUM_DEVICES 256
-#define CEC_NAME "cec"
-
-int cec_debug;
-module_param_named(debug, cec_debug, int, 0644);
-MODULE_PARM_DESC(debug, "debug level (0-2)");
-
-static dev_t cec_dev_t;
-
-/* Active devices */
-static DEFINE_MUTEX(cec_devnode_lock);
-static DECLARE_BITMAP(cec_devnode_nums, CEC_NUM_DEVICES);
-
-static struct dentry *top_cec_dir;
-
-/* dev to cec_devnode */
-#define to_cec_devnode(cd) container_of(cd, struct cec_devnode, dev)
-
-int cec_get_device(struct cec_devnode *devnode)
-{
- /*
- * Check if the cec device is available. This needs to be done with
- * the devnode->lock held to prevent an open/unregister race:
- * without the lock, the device could be unregistered and freed between
- * the devnode->registered check and get_device() calls, leading to
- * a crash.
- */
- mutex_lock(&devnode->lock);
- /*
- * return ENXIO if the cec device has been removed
- * already or if it is not registered anymore.
- */
- if (!devnode->registered) {
- mutex_unlock(&devnode->lock);
- return -ENXIO;
- }
- /* and increase the device refcount */
- get_device(&devnode->dev);
- mutex_unlock(&devnode->lock);
- return 0;
-}
-
-void cec_put_device(struct cec_devnode *devnode)
-{
- put_device(&devnode->dev);
-}
-
-/* Called when the last user of the cec device exits. */
-static void cec_devnode_release(struct device *cd)
-{
- struct cec_devnode *devnode = to_cec_devnode(cd);
-
- mutex_lock(&cec_devnode_lock);
- /* Mark device node number as free */
- clear_bit(devnode->minor, cec_devnode_nums);
- mutex_unlock(&cec_devnode_lock);
-
- cec_delete_adapter(to_cec_adapter(devnode));
-}
-
-static struct bus_type cec_bus_type = {
- .name = CEC_NAME,
-};
-
-/*
- * Register a cec device node
- *
- * The registration code assigns minor numbers and registers the new device node
- * with the kernel. An error is returned if no free minor number can be found,
- * or if the registration of the device node fails.
- *
- * Zero is returned on success.
- *
- * Note that if the cec_devnode_register call fails, the release() callback of
- * the cec_devnode structure is *not* called, so the caller is responsible for
- * freeing any data.
- */
-static int __must_check cec_devnode_register(struct cec_devnode *devnode,
- struct module *owner)
-{
- int minor;
- int ret;
-
- /* Initialization */
- INIT_LIST_HEAD(&devnode->fhs);
- mutex_init(&devnode->lock);
-
- /* Part 1: Find a free minor number */
- mutex_lock(&cec_devnode_lock);
- minor = find_next_zero_bit(cec_devnode_nums, CEC_NUM_DEVICES, 0);
- if (minor == CEC_NUM_DEVICES) {
- mutex_unlock(&cec_devnode_lock);
- pr_err("could not get a free minor\n");
- return -ENFILE;
- }
-
- set_bit(minor, cec_devnode_nums);
- mutex_unlock(&cec_devnode_lock);
-
- devnode->minor = minor;
- devnode->dev.bus = &cec_bus_type;
- devnode->dev.devt = MKDEV(MAJOR(cec_dev_t), minor);
- devnode->dev.release = cec_devnode_release;
- devnode->dev.parent = devnode->parent;
- dev_set_name(&devnode->dev, "cec%d", devnode->minor);
- device_initialize(&devnode->dev);
-
- /* Part 2: Initialize and register the character device */
- cdev_init(&devnode->cdev, &cec_devnode_fops);
- devnode->cdev.kobj.parent = &devnode->dev.kobj;
- devnode->cdev.owner = owner;
-
- ret = cdev_add(&devnode->cdev, devnode->dev.devt, 1);
- if (ret < 0) {
- pr_err("%s: cdev_add failed\n", __func__);
- goto clr_bit;
- }
-
- ret = device_add(&devnode->dev);
- if (ret)
- goto cdev_del;
-
- devnode->registered = true;
- return 0;
-
-cdev_del:
- cdev_del(&devnode->cdev);
-clr_bit:
- mutex_lock(&cec_devnode_lock);
- clear_bit(devnode->minor, cec_devnode_nums);
- mutex_unlock(&cec_devnode_lock);
- return ret;
-}
-
-/*
- * Unregister a cec device node
- *
- * This unregisters the passed device. Future open calls will be met with
- * errors.
- *
- * This function can safely be called if the device node has never been
- * registered or has already been unregistered.
- */
-static void cec_devnode_unregister(struct cec_devnode *devnode)
-{
- struct cec_fh *fh;
-
- mutex_lock(&devnode->lock);
-
- /* Check if devnode was never registered or already unregistered */
- if (!devnode->registered || devnode->unregistered) {
- mutex_unlock(&devnode->lock);
- return;
- }
-
- list_for_each_entry(fh, &devnode->fhs, list)
- wake_up_interruptible(&fh->wait);
-
- devnode->registered = false;
- devnode->unregistered = true;
- mutex_unlock(&devnode->lock);
-
- device_del(&devnode->dev);
- cdev_del(&devnode->cdev);
- put_device(&devnode->dev);
-}
-
-struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops,
- void *priv, const char *name, u32 caps,
- u8 available_las, struct device *parent)
-{
- struct cec_adapter *adap;
- int res;
-
- if (WARN_ON(!parent))
- return ERR_PTR(-EINVAL);
- if (WARN_ON(!caps))
- return ERR_PTR(-EINVAL);
- if (WARN_ON(!ops))
- return ERR_PTR(-EINVAL);
- if (WARN_ON(!available_las || available_las > CEC_MAX_LOG_ADDRS))
- return ERR_PTR(-EINVAL);
- adap = kzalloc(sizeof(*adap), GFP_KERNEL);
- if (!adap)
- return ERR_PTR(-ENOMEM);
- adap->owner = parent->driver->owner;
- adap->devnode.parent = parent;
- strlcpy(adap->name, name, sizeof(adap->name));
- adap->phys_addr = CEC_PHYS_ADDR_INVALID;
- adap->log_addrs.cec_version = CEC_OP_CEC_VERSION_2_0;
- adap->log_addrs.vendor_id = CEC_VENDOR_ID_NONE;
- adap->capabilities = caps;
- adap->available_log_addrs = available_las;
- adap->sequence = 0;
- adap->ops = ops;
- adap->priv = priv;
- memset(adap->phys_addrs, 0xff, sizeof(adap->phys_addrs));
- mutex_init(&adap->lock);
- INIT_LIST_HEAD(&adap->transmit_queue);
- INIT_LIST_HEAD(&adap->wait_queue);
- init_waitqueue_head(&adap->kthread_waitq);
-
- adap->kthread = kthread_run(cec_thread_func, adap, "cec-%s", name);
- if (IS_ERR(adap->kthread)) {
- pr_err("cec-%s: kernel_thread() failed\n", name);
- res = PTR_ERR(adap->kthread);
- kfree(adap);
- return ERR_PTR(res);
- }
-
- if (!(caps & CEC_CAP_RC))
- return adap;
-
-#if IS_REACHABLE(CONFIG_RC_CORE)
- /* Prepare the RC input device */
- adap->rc = rc_allocate_device();
- if (!adap->rc) {
- pr_err("cec-%s: failed to allocate memory for rc_dev\n",
- name);
- kthread_stop(adap->kthread);
- kfree(adap);
- return ERR_PTR(-ENOMEM);
- }
-
- snprintf(adap->input_name, sizeof(adap->input_name),
- "RC for %s", name);
- snprintf(adap->input_phys, sizeof(adap->input_phys),
- "%s/input0", name);
-
- adap->rc->input_name = adap->input_name;
- adap->rc->input_phys = adap->input_phys;
- adap->rc->input_id.bustype = BUS_CEC;
- adap->rc->input_id.vendor = 0;
- adap->rc->input_id.product = 0;
- adap->rc->input_id.version = 1;
- adap->rc->dev.parent = parent;
- adap->rc->driver_type = RC_DRIVER_SCANCODE;
- adap->rc->driver_name = CEC_NAME;
- adap->rc->allowed_protocols = RC_BIT_CEC;
- adap->rc->priv = adap;
- adap->rc->map_name = RC_MAP_CEC;
- adap->rc->timeout = MS_TO_NS(100);
-#else
- adap->capabilities &= ~CEC_CAP_RC;
-#endif
- return adap;
-}
-EXPORT_SYMBOL_GPL(cec_allocate_adapter);
-
-int cec_register_adapter(struct cec_adapter *adap)
-{
- int res;
-
- if (IS_ERR_OR_NULL(adap))
- return 0;
-
-#if IS_REACHABLE(CONFIG_RC_CORE)
- if (adap->capabilities & CEC_CAP_RC) {
- res = rc_register_device(adap->rc);
-
- if (res) {
- pr_err("cec-%s: failed to prepare input device\n",
- adap->name);
- rc_free_device(adap->rc);
- adap->rc = NULL;
- return res;
- }
- }
-#endif
-
- res = cec_devnode_register(&adap->devnode, adap->owner);
- if (res) {
-#if IS_REACHABLE(CONFIG_RC_CORE)
- /* Note: rc_unregister also calls rc_free */
- rc_unregister_device(adap->rc);
- adap->rc = NULL;
-#endif
- return res;
- }
-
- dev_set_drvdata(&adap->devnode.dev, adap);
-#ifdef CONFIG_MEDIA_CEC_DEBUG
- if (!top_cec_dir)
- return 0;
-
- adap->cec_dir = debugfs_create_dir(dev_name(&adap->devnode.dev), top_cec_dir);
- if (IS_ERR_OR_NULL(adap->cec_dir)) {
- pr_warn("cec-%s: Failed to create debugfs dir\n", adap->name);
- return 0;
- }
- adap->status_file = debugfs_create_devm_seqfile(&adap->devnode.dev,
- "status", adap->cec_dir, cec_adap_status);
- if (IS_ERR_OR_NULL(adap->status_file)) {
- pr_warn("cec-%s: Failed to create status file\n", adap->name);
- debugfs_remove_recursive(adap->cec_dir);
- adap->cec_dir = NULL;
- }
-#endif
- return 0;
-}
-EXPORT_SYMBOL_GPL(cec_register_adapter);
-
-void cec_unregister_adapter(struct cec_adapter *adap)
-{
- if (IS_ERR_OR_NULL(adap))
- return;
-
-#if IS_REACHABLE(CONFIG_RC_CORE)
- /* Note: rc_unregister also calls rc_free */
- rc_unregister_device(adap->rc);
- adap->rc = NULL;
-#endif
- debugfs_remove_recursive(adap->cec_dir);
- cec_devnode_unregister(&adap->devnode);
-}
-EXPORT_SYMBOL_GPL(cec_unregister_adapter);
-
-void cec_delete_adapter(struct cec_adapter *adap)
-{
- if (IS_ERR_OR_NULL(adap))
- return;
- mutex_lock(&adap->lock);
- __cec_s_phys_addr(adap, CEC_PHYS_ADDR_INVALID, false);
- mutex_unlock(&adap->lock);
- kthread_stop(adap->kthread);
- if (adap->kthread_config)
- kthread_stop(adap->kthread_config);
-#if IS_REACHABLE(CONFIG_RC_CORE)
- rc_free_device(adap->rc);
-#endif
- kfree(adap);
-}
-EXPORT_SYMBOL_GPL(cec_delete_adapter);
-
-/*
- * Initialise cec for linux
- */
-static int __init cec_devnode_init(void)
-{
- int ret;
-
- pr_info("Linux cec interface: v0.10\n");
- ret = alloc_chrdev_region(&cec_dev_t, 0, CEC_NUM_DEVICES,
- CEC_NAME);
- if (ret < 0) {
- pr_warn("cec: unable to allocate major\n");
- return ret;
- }
-
-#ifdef CONFIG_MEDIA_CEC_DEBUG
- top_cec_dir = debugfs_create_dir("cec", NULL);
- if (IS_ERR_OR_NULL(top_cec_dir)) {
- pr_warn("cec: Failed to create debugfs cec dir\n");
- top_cec_dir = NULL;
- }
-#endif
-
- ret = bus_register(&cec_bus_type);
- if (ret < 0) {
- unregister_chrdev_region(cec_dev_t, CEC_NUM_DEVICES);
- pr_warn("cec: bus_register failed\n");
- return -EIO;
- }
-
- return 0;
-}
-
-static void __exit cec_devnode_exit(void)
-{
- debugfs_remove_recursive(top_cec_dir);
- bus_unregister(&cec_bus_type);
- unregister_chrdev_region(cec_dev_t, CEC_NUM_DEVICES);
-}
-
-subsys_initcall(cec_devnode_init);
-module_exit(cec_devnode_exit)
-
-MODULE_AUTHOR("Hans Verkuil <hans.verkuil@cisco.com>");
-MODULE_DESCRIPTION("Device node registration for cec drivers");
-MODULE_LICENSE("GPL");
diff --git a/drivers/staging/media/cec/cec-priv.h b/drivers/staging/media/cec/cec-priv.h
deleted file mode 100644
index 70767a7900f2..000000000000
--- a/drivers/staging/media/cec/cec-priv.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * cec-priv.h - HDMI Consumer Electronics Control internal header
- *
- * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
- *
- * This program is free software; you may redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifndef _CEC_PRIV_H
-#define _CEC_PRIV_H
-
-#include <linux/cec-funcs.h>
-#include <media/cec.h>
-
-#define dprintk(lvl, fmt, arg...) \
- do { \
- if (lvl <= cec_debug) \
- pr_info("cec-%s: " fmt, adap->name, ## arg); \
- } while (0)
-
-/* devnode to cec_adapter */
-#define to_cec_adapter(node) container_of(node, struct cec_adapter, devnode)
-
-/* cec-core.c */
-extern int cec_debug;
-int cec_get_device(struct cec_devnode *devnode);
-void cec_put_device(struct cec_devnode *devnode);
-
-/* cec-adap.c */
-int cec_monitor_all_cnt_inc(struct cec_adapter *adap);
-void cec_monitor_all_cnt_dec(struct cec_adapter *adap);
-int cec_adap_status(struct seq_file *file, void *priv);
-int cec_thread_func(void *_adap);
-void __cec_s_phys_addr(struct cec_adapter *adap, u16 phys_addr, bool block);
-int __cec_s_log_addrs(struct cec_adapter *adap,
- struct cec_log_addrs *log_addrs, bool block);
-int cec_transmit_msg_fh(struct cec_adapter *adap, struct cec_msg *msg,
- struct cec_fh *fh, bool block);
-void cec_queue_event_fh(struct cec_fh *fh,
- const struct cec_event *new_ev, u64 ts);
-
-/* cec-api.c */
-extern const struct file_operations cec_devnode_fops;
-
-#endif
diff --git a/drivers/staging/media/davinci_vpfe/Makefile b/drivers/staging/media/davinci_vpfe/Makefile
index c64515c644cd..3019c9ecd548 100644
--- a/drivers/staging/media/davinci_vpfe/Makefile
+++ b/drivers/staging/media/davinci_vpfe/Makefile
@@ -1,3 +1,5 @@
-obj-$(CONFIG_VIDEO_DM365_VPFE) += \
+obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci-vfpe.o
+
+davinci-vfpe-objs := \
dm365_isif.o dm365_ipipe_hw.o dm365_ipipe.o \
dm365_resizer.o dm365_ipipeif.o vpfe_mc_capture.o vpfe_video.o
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 128662623ea8..5fbc2d447ff2 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -237,9 +237,8 @@ resizer_calculate_resize_ratios(struct vpfe_resizer_device *resizer, int index)
((informat->width) * 256) / (outformat->width);
}
-void
-static resizer_enable_422_420_conversion(struct resizer_params *param,
- int index, bool en)
+static void resizer_enable_422_420_conversion(struct resizer_params *param,
+ int index, bool en)
{
param->rsz_rsc_param[index].cen = en;
param->rsz_rsc_param[index].yen = en;
@@ -490,7 +489,7 @@ resizer_configure_in_continious_mode(struct vpfe_resizer_device *resizer)
int line_len;
int ret;
- if (resizer->resizer_a.output != RESIZER_OUPUT_MEMORY) {
+ if (resizer->resizer_a.output != RESIZER_OUTPUT_MEMORY) {
dev_err(dev, "enable resizer - Resizer-A\n");
return -EINVAL;
}
@@ -502,7 +501,7 @@ resizer_configure_in_continious_mode(struct vpfe_resizer_device *resizer)
param->rsz_en[RSZ_B] = DISABLE;
param->oper_mode = RESIZER_MODE_CONTINIOUS;
- if (resizer->resizer_b.output == RESIZER_OUPUT_MEMORY) {
+ if (resizer->resizer_b.output == RESIZER_OUTPUT_MEMORY) {
struct v4l2_mbus_framefmt *outformat2;
param->rsz_en[RSZ_B] = ENABLE;
@@ -825,7 +824,7 @@ resizer_set_defualt_configuration(struct vpfe_resizer_device *resizer)
.o_hsz = WIDTH_O - 1,
.v_dif = 256,
.v_typ_y = VPFE_RSZ_INTP_CUBIC,
- .h_typ_c = VPFE_RSZ_INTP_CUBIC,
+ .v_typ_c = VPFE_RSZ_INTP_CUBIC,
.h_dif = 256,
.h_typ_y = VPFE_RSZ_INTP_CUBIC,
.h_typ_c = VPFE_RSZ_INTP_CUBIC,
@@ -843,7 +842,7 @@ resizer_set_defualt_configuration(struct vpfe_resizer_device *resizer)
.o_hsz = WIDTH_O - 1,
.v_dif = 256,
.v_typ_y = VPFE_RSZ_INTP_CUBIC,
- .h_typ_c = VPFE_RSZ_INTP_CUBIC,
+ .v_typ_c = VPFE_RSZ_INTP_CUBIC,
.h_dif = 256,
.h_typ_y = VPFE_RSZ_INTP_CUBIC,
.h_typ_c = VPFE_RSZ_INTP_CUBIC,
@@ -1043,13 +1042,13 @@ static void resizer_ss_isr(struct vpfe_resizer_device *resizer)
if (ipipeif_sink != IPIPEIF_INPUT_MEMORY)
return;
- if (resizer->resizer_a.output == RESIZER_OUPUT_MEMORY) {
+ if (resizer->resizer_a.output == RESIZER_OUTPUT_MEMORY) {
val = vpss_dma_complete_interrupt();
if (val != 0 && val != 2)
return;
}
- if (resizer->resizer_a.output == RESIZER_OUPUT_MEMORY) {
+ if (resizer->resizer_a.output == RESIZER_OUTPUT_MEMORY) {
spin_lock(&video_out->dma_queue_lock);
vpfe_video_process_buffer_complete(video_out);
video_out->state = VPFE_VIDEO_BUFFER_NOT_QUEUED;
@@ -1059,7 +1058,7 @@ static void resizer_ss_isr(struct vpfe_resizer_device *resizer)
/* If resizer B is enabled */
if (pipe->output_num > 1 && resizer->resizer_b.output ==
- RESIZER_OUPUT_MEMORY) {
+ RESIZER_OUTPUT_MEMORY) {
spin_lock(&video_out->dma_queue_lock);
vpfe_video_process_buffer_complete(video_out2);
video_out2->state = VPFE_VIDEO_BUFFER_NOT_QUEUED;
@@ -1069,7 +1068,7 @@ static void resizer_ss_isr(struct vpfe_resizer_device *resizer)
/* start HW if buffers are queued */
if (vpfe_video_is_pipe_ready(pipe) &&
- resizer->resizer_a.output == RESIZER_OUPUT_MEMORY) {
+ resizer->resizer_a.output == RESIZER_OUTPUT_MEMORY) {
resizer_enable(resizer, 1);
vpfe_ipipe_enable(vpfe_dev, 1);
vpfe_ipipeif_enable(vpfe_dev);
@@ -1237,8 +1236,8 @@ static int resizer_do_hw_setup(struct vpfe_resizer_device *resizer)
struct resizer_params *param = &resizer->config;
int ret = 0;
- if (resizer->resizer_a.output == RESIZER_OUPUT_MEMORY ||
- resizer->resizer_b.output == RESIZER_OUPUT_MEMORY) {
+ if (resizer->resizer_a.output == RESIZER_OUTPUT_MEMORY ||
+ resizer->resizer_b.output == RESIZER_OUTPUT_MEMORY) {
if (ipipeif_sink == IPIPEIF_INPUT_MEMORY &&
ipipeif_source == IPIPEIF_OUTPUT_RESIZER)
ret = resizer_configure_in_single_shot_mode(resizer);
@@ -1263,7 +1262,7 @@ static int resizer_set_stream(struct v4l2_subdev *sd, int enable)
if (&resizer->crop_resizer.subdev != sd)
return 0;
- if (resizer->resizer_a.output != RESIZER_OUPUT_MEMORY)
+ if (resizer->resizer_a.output != RESIZER_OUTPUT_MEMORY)
return 0;
switch (enable) {
@@ -1724,7 +1723,7 @@ static int resizer_link_setup(struct media_entity *entity,
}
if (resizer->resizer_a.output != RESIZER_OUTPUT_NONE)
return -EBUSY;
- resizer->resizer_a.output = RESIZER_OUPUT_MEMORY;
+ resizer->resizer_a.output = RESIZER_OUTPUT_MEMORY;
break;
default:
@@ -1749,7 +1748,7 @@ static int resizer_link_setup(struct media_entity *entity,
}
if (resizer->resizer_b.output != RESIZER_OUTPUT_NONE)
return -EBUSY;
- resizer->resizer_b.output = RESIZER_OUPUT_MEMORY;
+ resizer->resizer_b.output = RESIZER_OUTPUT_MEMORY;
break;
default:
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.h b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
index 93b0f44030aa..00e64b0d0295 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.h
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
@@ -210,7 +210,7 @@ enum resizer_input_entity {
enum resizer_output_entity {
RESIZER_OUTPUT_NONE = 0,
- RESIZER_OUPUT_MEMORY = 1,
+ RESIZER_OUTPUT_MEMORY = 1,
};
struct dm365_resizer_device {
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index c34bf4621767..c27d7e9a1bdb 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -198,7 +198,7 @@ static int vpfe_update_pipe_state(struct vpfe_video_device *video)
return 0;
}
-/* checks wether pipeline is ready for enabling */
+/* checks whether pipeline is ready for enabling */
int vpfe_video_is_pipe_ready(struct vpfe_pipeline *pipe)
{
int i;
@@ -1362,7 +1362,7 @@ static int vpfe_reqbufs(struct file *file, void *priv,
ret = vb2_queue_init(q);
if (ret) {
v4l2_err(&vpfe_dev->v4l2_dev, "vb2_queue_init() failed\n");
- return ret;
+ goto unlock_out;
}
fh->io_allowed = 1;
diff --git a/drivers/staging/media/lirc/Kconfig b/drivers/staging/media/lirc/Kconfig
index 6879c4651b46..25b7e7ccf554 100644
--- a/drivers/staging/media/lirc/Kconfig
+++ b/drivers/staging/media/lirc/Kconfig
@@ -38,19 +38,6 @@ config LIRC_SASEM
help
Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module
-config LIRC_SERIAL
- tristate "Homebrew Serial Port Receiver"
- depends on LIRC
- help
- Driver for Homebrew Serial Port Receivers
-
-config LIRC_SERIAL_TRANSMITTER
- bool "Serial Port Transmitter"
- default y
- depends on LIRC_SERIAL
- help
- Serial Port Transmitter support
-
config LIRC_SIR
tristate "Built-in SIR IrDA port"
depends on LIRC
diff --git a/drivers/staging/media/lirc/Makefile b/drivers/staging/media/lirc/Makefile
index 5430adf0475d..7f919eab1989 100644
--- a/drivers/staging/media/lirc/Makefile
+++ b/drivers/staging/media/lirc/Makefile
@@ -7,6 +7,5 @@ obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o
obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
-obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
obj-$(CONFIG_LIRC_ZILOG) += lirc_zilog.o
diff --git a/drivers/staging/media/lirc/lirc_imon.c b/drivers/staging/media/lirc/lirc_imon.c
index 198a8057f2f1..1e650fba4a92 100644
--- a/drivers/staging/media/lirc/lirc_imon.c
+++ b/drivers/staging/media/lirc/lirc_imon.c
@@ -334,7 +334,7 @@ static int send_packet(struct imon_context *context)
context->tx_urb->actual_length = 0;
- init_completion(&context->tx.finished);
+ reinit_completion(&context->tx.finished);
atomic_set(&context->tx.busy, 1);
retval = usb_submit_urb(context->tx_urb, GFP_KERNEL);
@@ -408,9 +408,8 @@ static ssize_t vfd_write(struct file *file, const char __user *buf,
data_buf = memdup_user(buf, n_bytes);
if (IS_ERR(data_buf)) {
- retval = PTR_ERR(data_buf);
- data_buf = NULL;
- goto exit;
+ mutex_unlock(&context->ctx_lock);
+ return PTR_ERR(data_buf);
}
memcpy(context->tx.data_buf, data_buf, n_bytes);
@@ -497,6 +496,8 @@ static int ir_open(void *data)
context->rx.initial_space = 1;
context->rx.prev_bit = 0;
+ init_completion(&context->tx.finished);
+
context->ir_isopen = 1;
dev_info(context->driver->dev, "IR port opened\n");
@@ -930,7 +931,7 @@ static void imon_disconnect(struct usb_interface *interface)
/* Abort ongoing write */
if (atomic_read(&context->tx.busy)) {
usb_kill_urb(context->tx_urb);
- complete_all(&context->tx.finished);
+ complete(&context->tx.finished);
}
context->dev_present = 0;
diff --git a/drivers/staging/media/lirc/lirc_sasem.c b/drivers/staging/media/lirc/lirc_sasem.c
index 920c4a1290f4..b0c176e14b6b 100644
--- a/drivers/staging/media/lirc/lirc_sasem.c
+++ b/drivers/staging/media/lirc/lirc_sasem.c
@@ -386,9 +386,8 @@ static ssize_t vfd_write(struct file *file, const char __user *buf,
data_buf = memdup_user(buf, n_bytes);
if (IS_ERR(data_buf)) {
- retval = PTR_ERR(data_buf);
- data_buf = NULL;
- goto exit;
+ mutex_unlock(&context->ctx_lock);
+ return PTR_ERR(data_buf);
}
memcpy(context->tx.data_buf, data_buf, n_bytes);
diff --git a/drivers/staging/media/lirc/lirc_serial.c b/drivers/staging/media/lirc/lirc_serial.c
deleted file mode 100644
index b798b311d32c..000000000000
--- a/drivers/staging/media/lirc/lirc_serial.c
+++ /dev/null
@@ -1,1130 +0,0 @@
-/*
- * lirc_serial.c
- *
- * lirc_serial - Device driver that records pulse- and pause-lengths
- * (space-lengths) between DDCD event on a serial port.
- *
- * Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
- * Copyright (C) 1998 Trent Piepho <xyzzy@u.washington.edu>
- * Copyright (C) 1998 Ben Pfaff <blp@gnu.org>
- * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
- * Copyright (C) 2007 Andrei Tanas <andrei@tanas.ca> (suspend/resume support)
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/*
- * Steve's changes to improve transmission fidelity:
- * - for systems with the rdtsc instruction and the clock counter, a
- * send_pule that times the pulses directly using the counter.
- * This means that the LIRC_SERIAL_TRANSMITTER_LATENCY fudge is
- * not needed. Measurement shows very stable waveform, even where
- * PCI activity slows the access to the UART, which trips up other
- * versions.
- * - For other system, non-integer-microsecond pulse/space lengths,
- * done using fixed point binary. So, much more accurate carrier
- * frequency.
- * - fine tuned transmitter latency, taking advantage of fractional
- * microseconds in previous change
- * - Fixed bug in the way transmitter latency was accounted for by
- * tuning the pulse lengths down - the send_pulse routine ignored
- * this overhead as it timed the overall pulse length - so the
- * pulse frequency was right but overall pulse length was too
- * long. Fixed by accounting for latency on each pulse/space
- * iteration.
- *
- * Steve Davies <steve@daviesfam.org> July 2001
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/fs.h>
-#include <linux/interrupt.h>
-#include <linux/ioport.h>
-#include <linux/kernel.h>
-#include <linux/serial_reg.h>
-#include <linux/ktime.h>
-#include <linux/string.h>
-#include <linux/types.h>
-#include <linux/wait.h>
-#include <linux/mm.h>
-#include <linux/delay.h>
-#include <linux/poll.h>
-#include <linux/platform_device.h>
-#include <linux/gpio.h>
-#include <linux/io.h>
-#include <linux/irq.h>
-#include <linux/fcntl.h>
-#include <linux/spinlock.h>
-
-/* From Intel IXP42X Developer's Manual (#252480-005): */
-/* ftp://download.intel.com/design/network/manuals/25248005.pdf */
-#define UART_IE_IXP42X_UUE 0x40 /* IXP42X UART Unit enable */
-#define UART_IE_IXP42X_RTOIE 0x10 /* IXP42X Receiver Data Timeout int.enable */
-
-#include <media/lirc.h>
-#include <media/lirc_dev.h>
-
-#define LIRC_DRIVER_NAME "lirc_serial"
-
-struct lirc_serial {
- int signal_pin;
- int signal_pin_change;
- u8 on;
- u8 off;
- long (*send_pulse)(unsigned long length);
- void (*send_space)(long length);
- int features;
- spinlock_t lock;
-};
-
-#define LIRC_HOMEBREW 0
-#define LIRC_IRDEO 1
-#define LIRC_IRDEO_REMOTE 2
-#define LIRC_ANIMAX 3
-#define LIRC_IGOR 4
-#define LIRC_NSLU2 5
-
-/*** module parameters ***/
-static int type;
-static int io;
-static int irq;
-static bool iommap;
-static int ioshift;
-static bool softcarrier = true;
-static bool share_irq;
-static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */
-static bool txsense; /* 0 = active high, 1 = active low */
-
-/* forward declarations */
-static long send_pulse_irdeo(unsigned long length);
-static long send_pulse_homebrew(unsigned long length);
-static void send_space_irdeo(long length);
-static void send_space_homebrew(long length);
-
-static struct lirc_serial hardware[] = {
- [LIRC_HOMEBREW] = {
- .lock = __SPIN_LOCK_UNLOCKED(hardware[LIRC_HOMEBREW].lock),
- .signal_pin = UART_MSR_DCD,
- .signal_pin_change = UART_MSR_DDCD,
- .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
- .off = (UART_MCR_RTS | UART_MCR_OUT2),
- .send_pulse = send_pulse_homebrew,
- .send_space = send_space_homebrew,
-#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
- .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
- LIRC_CAN_SET_SEND_CARRIER |
- LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
-#else
- .features = LIRC_CAN_REC_MODE2
-#endif
- },
-
- [LIRC_IRDEO] = {
- .lock = __SPIN_LOCK_UNLOCKED(hardware[LIRC_IRDEO].lock),
- .signal_pin = UART_MSR_DSR,
- .signal_pin_change = UART_MSR_DDSR,
- .on = UART_MCR_OUT2,
- .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
- .send_pulse = send_pulse_irdeo,
- .send_space = send_space_irdeo,
- .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
- LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
- },
-
- [LIRC_IRDEO_REMOTE] = {
- .lock = __SPIN_LOCK_UNLOCKED(hardware[LIRC_IRDEO_REMOTE].lock),
- .signal_pin = UART_MSR_DSR,
- .signal_pin_change = UART_MSR_DDSR,
- .on = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
- .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
- .send_pulse = send_pulse_irdeo,
- .send_space = send_space_irdeo,
- .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
- LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
- },
-
- [LIRC_ANIMAX] = {
- .lock = __SPIN_LOCK_UNLOCKED(hardware[LIRC_ANIMAX].lock),
- .signal_pin = UART_MSR_DCD,
- .signal_pin_change = UART_MSR_DDCD,
- .on = 0,
- .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
- .send_pulse = NULL,
- .send_space = NULL,
- .features = LIRC_CAN_REC_MODE2
- },
-
- [LIRC_IGOR] = {
- .lock = __SPIN_LOCK_UNLOCKED(hardware[LIRC_IGOR].lock),
- .signal_pin = UART_MSR_DSR,
- .signal_pin_change = UART_MSR_DDSR,
- .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
- .off = (UART_MCR_RTS | UART_MCR_OUT2),
- .send_pulse = send_pulse_homebrew,
- .send_space = send_space_homebrew,
-#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
- .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
- LIRC_CAN_SET_SEND_CARRIER |
- LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
-#else
- .features = LIRC_CAN_REC_MODE2
-#endif
- },
-};
-
-#define RS_ISR_PASS_LIMIT 256
-
-/*
- * A long pulse code from a remote might take up to 300 bytes. The
- * daemon should read the bytes as soon as they are generated, so take
- * the number of keys you think you can push before the daemon runs
- * and multiply by 300. The driver will warn you if you overrun this
- * buffer. If you have a slow computer or non-busmastering IDE disks,
- * maybe you will need to increase this.
- */
-
-/* This MUST be a power of two! It has to be larger than 1 as well. */
-
-#define RBUF_LEN 256
-
-static ktime_t lastkt;
-
-static struct lirc_buffer rbuf;
-
-static unsigned int freq = 38000;
-static unsigned int duty_cycle = 50;
-
-/* Initialized in init_timing_params() */
-static unsigned long period;
-static unsigned long pulse_width;
-static unsigned long space_width;
-
-#if defined(__i386__)
-/*
- * From:
- * Linux I/O port programming mini-HOWTO
- * Author: Riku Saikkonen <Riku.Saikkonen@hut.fi>
- * v, 28 December 1997
- *
- * [...]
- * Actually, a port I/O instruction on most ports in the 0-0x3ff range
- * takes almost exactly 1 microsecond, so if you're, for example, using
- * the parallel port directly, just do additional inb()s from that port
- * to delay.
- * [...]
- */
-/* transmitter latency 1.5625us 0x1.90 - this figure arrived at from
- * comment above plus trimming to match actual measured frequency.
- * This will be sensitive to cpu speed, though hopefully most of the 1.5us
- * is spent in the uart access. Still - for reference test machine was a
- * 1.13GHz Athlon system - Steve
- */
-
-/*
- * changed from 400 to 450 as this works better on slower machines;
- * faster machines will use the rdtsc code anyway
- */
-#define LIRC_SERIAL_TRANSMITTER_LATENCY 450
-
-#else
-
-/* does anybody have information on other platforms ? */
-/* 256 = 1<<8 */
-#define LIRC_SERIAL_TRANSMITTER_LATENCY 256
-
-#endif /* __i386__ */
-/*
- * FIXME: should we be using hrtimers instead of this
- * LIRC_SERIAL_TRANSMITTER_LATENCY nonsense?
- */
-
-/* fetch serial input packet (1 byte) from register offset */
-static u8 sinp(int offset)
-{
- if (iommap)
- /* the register is memory-mapped */
- offset <<= ioshift;
-
- return inb(io + offset);
-}
-
-/* write serial output packet (1 byte) of value to register offset */
-static void soutp(int offset, u8 value)
-{
- if (iommap)
- /* the register is memory-mapped */
- offset <<= ioshift;
-
- outb(value, io + offset);
-}
-
-static void on(void)
-{
- if (txsense)
- soutp(UART_MCR, hardware[type].off);
- else
- soutp(UART_MCR, hardware[type].on);
-}
-
-static void off(void)
-{
- if (txsense)
- soutp(UART_MCR, hardware[type].on);
- else
- soutp(UART_MCR, hardware[type].off);
-}
-
-#ifndef MAX_UDELAY_MS
-#define MAX_UDELAY_US 5000
-#else
-#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
-#endif
-
-static void safe_udelay(unsigned long usecs)
-{
- while (usecs > MAX_UDELAY_US) {
- udelay(MAX_UDELAY_US);
- usecs -= MAX_UDELAY_US;
- }
- udelay(usecs);
-}
-
-#ifdef USE_RDTSC
-/*
- * This is an overflow/precision juggle, complicated in that we can't
- * do long long divide in the kernel
- */
-
-/*
- * When we use the rdtsc instruction to measure clocks, we keep the
- * pulse and space widths as clock cycles. As this is CPU speed
- * dependent, the widths must be calculated in init_port and ioctl
- * time
- */
-
-static int init_timing_params(unsigned int new_duty_cycle,
- unsigned int new_freq)
-{
- __u64 loops_per_sec, work;
-
- duty_cycle = new_duty_cycle;
- freq = new_freq;
-
- loops_per_sec = __this_cpu_read(cpu.info.loops_per_jiffy);
- loops_per_sec *= HZ;
-
- /* How many clocks in a microsecond?, avoiding long long divide */
- work = loops_per_sec;
- work *= 4295; /* 4295 = 2^32 / 1e6 */
-
- /*
- * Carrier period in clocks, approach good up to 32GHz clock,
- * gets carrier frequency within 8Hz
- */
- period = loops_per_sec >> 3;
- period /= (freq >> 3);
-
- /* Derive pulse and space from the period */
- pulse_width = period * duty_cycle / 100;
- space_width = period - pulse_width;
- pr_debug("in init_timing_params, freq=%d, duty_cycle=%d, clk/jiffy=%ld, pulse=%ld, space=%ld, conv_us_to_clocks=%ld\n",
- freq, duty_cycle, __this_cpu_read(cpu_info.loops_per_jiffy),
- pulse_width, space_width, conv_us_to_clocks);
- return 0;
-}
-#else /* ! USE_RDTSC */
-static int init_timing_params(unsigned int new_duty_cycle,
- unsigned int new_freq)
-{
-/*
- * period, pulse/space width are kept with 8 binary places -
- * IE multiplied by 256.
- */
- if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
- LIRC_SERIAL_TRANSMITTER_LATENCY)
- return -EINVAL;
- if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
- LIRC_SERIAL_TRANSMITTER_LATENCY)
- return -EINVAL;
- duty_cycle = new_duty_cycle;
- freq = new_freq;
- period = 256 * 1000000L / freq;
- pulse_width = period * duty_cycle / 100;
- space_width = period - pulse_width;
- pr_debug("in init_timing_params, freq=%d pulse=%ld, space=%ld\n",
- freq, pulse_width, space_width);
- return 0;
-}
-#endif /* USE_RDTSC */
-
-
-/* return value: space length delta */
-
-static long send_pulse_irdeo(unsigned long length)
-{
- long rawbits, ret;
- int i;
- unsigned char output;
- unsigned char chunk, shifted;
-
- /* how many bits have to be sent ? */
- rawbits = length * 1152 / 10000;
- if (duty_cycle > 50)
- chunk = 3;
- else
- chunk = 1;
- for (i = 0, output = 0x7f; rawbits > 0; rawbits -= 3) {
- shifted = chunk << (i * 3);
- shifted >>= 1;
- output &= (~shifted);
- i++;
- if (i == 3) {
- soutp(UART_TX, output);
- while (!(sinp(UART_LSR) & UART_LSR_THRE))
- ;
- output = 0x7f;
- i = 0;
- }
- }
- if (i != 0) {
- soutp(UART_TX, output);
- while (!(sinp(UART_LSR) & UART_LSR_TEMT))
- ;
- }
-
- if (i == 0)
- ret = (-rawbits) * 10000 / 1152;
- else
- ret = (3 - i) * 3 * 10000 / 1152 + (-rawbits) * 10000 / 1152;
-
- return ret;
-}
-
-/* Version using udelay() */
-
-/*
- * here we use fixed point arithmetic, with 8
- * fractional bits. that gets us within 0.1% or so of the right average
- * frequency, albeit with some jitter in pulse length - Steve
- *
- * This should use ndelay instead.
- */
-
-/* To match 8 fractional bits used for pulse/space length */
-
-static long send_pulse_homebrew_softcarrier(unsigned long length)
-{
- int flag;
- unsigned long actual, target, d;
-
- length <<= 8;
-
- actual = 0; target = 0; flag = 0;
- while (actual < length) {
- if (flag) {
- off();
- target += space_width;
- } else {
- on();
- target += pulse_width;
- }
- d = (target - actual -
- LIRC_SERIAL_TRANSMITTER_LATENCY + 128) >> 8;
- /*
- * Note - we've checked in ioctl that the pulse/space
- * widths are big enough so that d is > 0
- */
- udelay(d);
- actual += (d << 8) + LIRC_SERIAL_TRANSMITTER_LATENCY;
- flag = !flag;
- }
- return (actual-length) >> 8;
-}
-
-static long send_pulse_homebrew(unsigned long length)
-{
- if (length <= 0)
- return 0;
-
- if (softcarrier)
- return send_pulse_homebrew_softcarrier(length);
-
- on();
- safe_udelay(length);
- return 0;
-}
-
-static void send_space_irdeo(long length)
-{
- if (length <= 0)
- return;
-
- safe_udelay(length);
-}
-
-static void send_space_homebrew(long length)
-{
- off();
- if (length <= 0)
- return;
- safe_udelay(length);
-}
-
-static void rbwrite(int l)
-{
- if (lirc_buffer_full(&rbuf)) {
- /* no new signals will be accepted */
- pr_debug("Buffer overrun\n");
- return;
- }
- lirc_buffer_write(&rbuf, (void *)&l);
-}
-
-static void frbwrite(int l)
-{
- /* simple noise filter */
- static int pulse, space;
- static unsigned int ptr;
-
- if (ptr > 0 && (l & PULSE_BIT)) {
- pulse += l & PULSE_MASK;
- if (pulse > 250) {
- rbwrite(space);
- rbwrite(pulse | PULSE_BIT);
- ptr = 0;
- pulse = 0;
- }
- return;
- }
- if (!(l & PULSE_BIT)) {
- if (ptr == 0) {
- if (l > 20000) {
- space = l;
- ptr++;
- return;
- }
- } else {
- if (l > 20000) {
- space += pulse;
- if (space > PULSE_MASK)
- space = PULSE_MASK;
- space += l;
- if (space > PULSE_MASK)
- space = PULSE_MASK;
- pulse = 0;
- return;
- }
- rbwrite(space);
- rbwrite(pulse | PULSE_BIT);
- ptr = 0;
- pulse = 0;
- }
- }
- rbwrite(l);
-}
-
-static irqreturn_t lirc_irq_handler(int i, void *blah)
-{
- ktime_t kt;
- int counter, dcd;
- u8 status;
- ktime_t delkt;
- int data;
- static int last_dcd = -1;
-
- if ((sinp(UART_IIR) & UART_IIR_NO_INT)) {
- /* not our interrupt */
- return IRQ_NONE;
- }
-
- counter = 0;
- do {
- counter++;
- status = sinp(UART_MSR);
- if (counter > RS_ISR_PASS_LIMIT) {
- pr_warn("AIEEEE: We're caught!\n");
- break;
- }
- if ((status & hardware[type].signal_pin_change)
- && sense != -1) {
- /* get current time */
- kt = ktime_get();
-
- /* New mode, written by Trent Piepho
- <xyzzy@u.washington.edu>. */
-
- /*
- * The old format was not very portable.
- * We now use an int to pass pulses
- * and spaces to user space.
- *
- * If PULSE_BIT is set a pulse has been
- * received, otherwise a space has been
- * received. The driver needs to know if your
- * receiver is active high or active low, or
- * the space/pulse sense could be
- * inverted. The bits denoted by PULSE_MASK are
- * the length in microseconds. Lengths greater
- * than or equal to 16 seconds are clamped to
- * PULSE_MASK. All other bits are unused.
- * This is a much simpler interface for user
- * programs, as well as eliminating "out of
- * phase" errors with space/pulse
- * autodetection.
- */
-
- /* calc time since last interrupt in microseconds */
- dcd = (status & hardware[type].signal_pin) ? 1 : 0;
-
- if (dcd == last_dcd) {
- pr_warn("ignoring spike: %d %d %llx %llx\n",
- dcd, sense, ktime_to_us(kt),
- ktime_to_us(lastkt));
- continue;
- }
-
- delkt = ktime_sub(kt, lastkt);
- if (ktime_compare(delkt, ktime_set(15, 0)) > 0) {
- data = PULSE_MASK; /* really long time */
- if (!(dcd^sense)) {
- /* sanity check */
- pr_warn("AIEEEE: %d %d %llx %llx\n",
- dcd, sense, ktime_to_us(kt),
- ktime_to_us(lastkt));
- /*
- * detecting pulse while this
- * MUST be a space!
- */
- sense = sense ? 0 : 1;
- }
- } else
- data = (int) ktime_to_us(delkt);
- frbwrite(dcd^sense ? data : (data|PULSE_BIT));
- lastkt = kt;
- last_dcd = dcd;
- wake_up_interruptible(&rbuf.wait_poll);
- }
- } while (!(sinp(UART_IIR) & UART_IIR_NO_INT)); /* still pending ? */
- return IRQ_HANDLED;
-}
-
-
-static int hardware_init_port(void)
-{
- u8 scratch, scratch2, scratch3;
-
- /*
- * This is a simple port existence test, borrowed from the autoconfig
- * function in drivers/serial/8250.c
- */
- scratch = sinp(UART_IER);
- soutp(UART_IER, 0);
-#ifdef __i386__
- outb(0xff, 0x080);
-#endif
- scratch2 = sinp(UART_IER) & 0x0f;
- soutp(UART_IER, 0x0f);
-#ifdef __i386__
- outb(0x00, 0x080);
-#endif
- scratch3 = sinp(UART_IER) & 0x0f;
- soutp(UART_IER, scratch);
- if (scratch2 != 0 || scratch3 != 0x0f) {
- /* we fail, there's nothing here */
- pr_err("port existence test failed, cannot continue\n");
- return -ENODEV;
- }
-
-
-
- /* Set DLAB 0. */
- soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
-
- /* First of all, disable all interrupts */
- soutp(UART_IER, sinp(UART_IER) &
- (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
-
- /* Clear registers. */
- sinp(UART_LSR);
- sinp(UART_RX);
- sinp(UART_IIR);
- sinp(UART_MSR);
-
- /* Set line for power source */
- off();
-
- /* Clear registers again to be sure. */
- sinp(UART_LSR);
- sinp(UART_RX);
- sinp(UART_IIR);
- sinp(UART_MSR);
-
- switch (type) {
- case LIRC_IRDEO:
- case LIRC_IRDEO_REMOTE:
- /* setup port to 7N1 @ 115200 Baud */
- /* 7N1+start = 9 bits at 115200 ~ 3 bits at 38kHz */
-
- /* Set DLAB 1. */
- soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
- /* Set divisor to 1 => 115200 Baud */
- soutp(UART_DLM, 0);
- soutp(UART_DLL, 1);
- /* Set DLAB 0 + 7N1 */
- soutp(UART_LCR, UART_LCR_WLEN7);
- /* THR interrupt already disabled at this point */
- break;
- default:
- break;
- }
-
- return 0;
-}
-
-static int lirc_serial_probe(struct platform_device *dev)
-{
- int i, nlow, nhigh, result;
-
- result = devm_request_irq(&dev->dev, irq, lirc_irq_handler,
- (share_irq ? IRQF_SHARED : 0),
- LIRC_DRIVER_NAME, &hardware);
- if (result < 0) {
- if (result == -EBUSY)
- dev_err(&dev->dev, "IRQ %d busy\n", irq);
- else if (result == -EINVAL)
- dev_err(&dev->dev, "Bad irq number or handler\n");
- return result;
- }
-
- /* Reserve io region. */
- /*
- * Future MMAP-Developers: Attention!
- * For memory mapped I/O you *might* need to use ioremap() first,
- * for the NSLU2 it's done in boot code.
- */
- if (((iommap)
- && (devm_request_mem_region(&dev->dev, iommap, 8 << ioshift,
- LIRC_DRIVER_NAME) == NULL))
- || ((!iommap)
- && (devm_request_region(&dev->dev, io, 8,
- LIRC_DRIVER_NAME) == NULL))) {
- dev_err(&dev->dev, "port %04x already in use\n", io);
- dev_warn(&dev->dev, "use 'setserial /dev/ttySX uart none'\n");
- dev_warn(&dev->dev,
- "or compile the serial port driver as module and\n");
- dev_warn(&dev->dev, "make sure this module is loaded first\n");
- return -EBUSY;
- }
-
- result = hardware_init_port();
- if (result < 0)
- return result;
-
- /* Initialize pulse/space widths */
- init_timing_params(duty_cycle, freq);
-
- /* If pin is high, then this must be an active low receiver. */
- if (sense == -1) {
- /* wait 1/2 sec for the power supply */
- msleep(500);
-
- /*
- * probe 9 times every 0.04s, collect "votes" for
- * active high/low
- */
- nlow = 0;
- nhigh = 0;
- for (i = 0; i < 9; i++) {
- if (sinp(UART_MSR) & hardware[type].signal_pin)
- nlow++;
- else
- nhigh++;
- msleep(40);
- }
- sense = nlow >= nhigh ? 1 : 0;
- dev_info(&dev->dev, "auto-detected active %s receiver\n",
- sense ? "low" : "high");
- } else
- dev_info(&dev->dev, "Manually using active %s receiver\n",
- sense ? "low" : "high");
-
- dev_dbg(&dev->dev, "Interrupt %d, port %04x obtained\n", irq, io);
- return 0;
-}
-
-static int set_use_inc(void *data)
-{
- unsigned long flags;
-
- /* initialize timestamp */
- lastkt = ktime_get();
-
- spin_lock_irqsave(&hardware[type].lock, flags);
-
- /* Set DLAB 0. */
- soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
-
- soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
-
- spin_unlock_irqrestore(&hardware[type].lock, flags);
-
- return 0;
-}
-
-static void set_use_dec(void *data)
-{ unsigned long flags;
-
- spin_lock_irqsave(&hardware[type].lock, flags);
-
- /* Set DLAB 0. */
- soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
-
- /* First of all, disable all interrupts */
- soutp(UART_IER, sinp(UART_IER) &
- (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
- spin_unlock_irqrestore(&hardware[type].lock, flags);
-}
-
-static ssize_t lirc_write(struct file *file, const char __user *buf,
- size_t n, loff_t *ppos)
-{
- int i, count;
- unsigned long flags;
- long delta = 0;
- int *wbuf;
-
- if (!(hardware[type].features & LIRC_CAN_SEND_PULSE))
- return -EPERM;
-
- count = n / sizeof(int);
- if (n % sizeof(int) || count % 2 == 0)
- return -EINVAL;
- wbuf = memdup_user(buf, n);
- if (IS_ERR(wbuf))
- return PTR_ERR(wbuf);
- spin_lock_irqsave(&hardware[type].lock, flags);
- if (type == LIRC_IRDEO) {
- /* DTR, RTS down */
- on();
- }
- for (i = 0; i < count; i++) {
- if (i%2)
- hardware[type].send_space(wbuf[i] - delta);
- else
- delta = hardware[type].send_pulse(wbuf[i]);
- }
- off();
- spin_unlock_irqrestore(&hardware[type].lock, flags);
- kfree(wbuf);
- return n;
-}
-
-static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
-{
- int result;
- u32 __user *uptr = (u32 __user *)arg;
- u32 value;
-
- switch (cmd) {
- case LIRC_GET_SEND_MODE:
- if (!(hardware[type].features&LIRC_CAN_SEND_MASK))
- return -ENOIOCTLCMD;
-
- result = put_user(LIRC_SEND2MODE
- (hardware[type].features&LIRC_CAN_SEND_MASK),
- uptr);
- if (result)
- return result;
- break;
-
- case LIRC_SET_SEND_MODE:
- if (!(hardware[type].features&LIRC_CAN_SEND_MASK))
- return -ENOIOCTLCMD;
-
- result = get_user(value, uptr);
- if (result)
- return result;
- /* only LIRC_MODE_PULSE supported */
- if (value != LIRC_MODE_PULSE)
- return -EINVAL;
- break;
-
- case LIRC_GET_LENGTH:
- return -ENOIOCTLCMD;
-
- case LIRC_SET_SEND_DUTY_CYCLE:
- pr_debug("SET_SEND_DUTY_CYCLE\n");
- if (!(hardware[type].features&LIRC_CAN_SET_SEND_DUTY_CYCLE))
- return -ENOIOCTLCMD;
-
- result = get_user(value, uptr);
- if (result)
- return result;
- if (value <= 0 || value > 100)
- return -EINVAL;
- return init_timing_params(value, freq);
-
- case LIRC_SET_SEND_CARRIER:
- pr_debug("SET_SEND_CARRIER\n");
- if (!(hardware[type].features&LIRC_CAN_SET_SEND_CARRIER))
- return -ENOIOCTLCMD;
-
- result = get_user(value, uptr);
- if (result)
- return result;
- if (value > 500000 || value < 20000)
- return -EINVAL;
- return init_timing_params(duty_cycle, value);
-
- default:
- return lirc_dev_fop_ioctl(filep, cmd, arg);
- }
- return 0;
-}
-
-static const struct file_operations lirc_fops = {
- .owner = THIS_MODULE,
- .write = lirc_write,
- .unlocked_ioctl = lirc_ioctl,
-#ifdef CONFIG_COMPAT
- .compat_ioctl = lirc_ioctl,
-#endif
- .read = lirc_dev_fop_read,
- .poll = lirc_dev_fop_poll,
- .open = lirc_dev_fop_open,
- .release = lirc_dev_fop_close,
- .llseek = no_llseek,
-};
-
-static struct lirc_driver driver = {
- .name = LIRC_DRIVER_NAME,
- .minor = -1,
- .code_length = 1,
- .sample_rate = 0,
- .data = NULL,
- .add_to_buf = NULL,
- .rbuf = &rbuf,
- .set_use_inc = set_use_inc,
- .set_use_dec = set_use_dec,
- .fops = &lirc_fops,
- .dev = NULL,
- .owner = THIS_MODULE,
-};
-
-static struct platform_device *lirc_serial_dev;
-
-static int lirc_serial_suspend(struct platform_device *dev,
- pm_message_t state)
-{
- /* Set DLAB 0. */
- soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
-
- /* Disable all interrupts */
- soutp(UART_IER, sinp(UART_IER) &
- (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
-
- /* Clear registers. */
- sinp(UART_LSR);
- sinp(UART_RX);
- sinp(UART_IIR);
- sinp(UART_MSR);
-
- return 0;
-}
-
-/* twisty maze... need a forward-declaration here... */
-static void lirc_serial_exit(void);
-
-static int lirc_serial_resume(struct platform_device *dev)
-{
- unsigned long flags;
- int result;
-
- result = hardware_init_port();
- if (result < 0)
- return result;
-
- spin_lock_irqsave(&hardware[type].lock, flags);
- /* Enable Interrupt */
- lastkt = ktime_get();
- soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
- off();
-
- lirc_buffer_clear(&rbuf);
-
- spin_unlock_irqrestore(&hardware[type].lock, flags);
-
- return 0;
-}
-
-static struct platform_driver lirc_serial_driver = {
- .probe = lirc_serial_probe,
- .suspend = lirc_serial_suspend,
- .resume = lirc_serial_resume,
- .driver = {
- .name = "lirc_serial",
- },
-};
-
-static int __init lirc_serial_init(void)
-{
- int result;
-
- /* Init read buffer. */
- result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
- if (result < 0)
- return result;
-
- result = platform_driver_register(&lirc_serial_driver);
- if (result) {
- printk("lirc register returned %d\n", result);
- goto exit_buffer_free;
- }
-
- lirc_serial_dev = platform_device_alloc("lirc_serial", 0);
- if (!lirc_serial_dev) {
- result = -ENOMEM;
- goto exit_driver_unregister;
- }
-
- result = platform_device_add(lirc_serial_dev);
- if (result)
- goto exit_device_put;
-
- return 0;
-
-exit_device_put:
- platform_device_put(lirc_serial_dev);
-exit_driver_unregister:
- platform_driver_unregister(&lirc_serial_driver);
-exit_buffer_free:
- lirc_buffer_free(&rbuf);
- return result;
-}
-
-static void lirc_serial_exit(void)
-{
- platform_device_unregister(lirc_serial_dev);
- platform_driver_unregister(&lirc_serial_driver);
- lirc_buffer_free(&rbuf);
-}
-
-static int __init lirc_serial_init_module(void)
-{
- int result;
-
- switch (type) {
- case LIRC_HOMEBREW:
- case LIRC_IRDEO:
- case LIRC_IRDEO_REMOTE:
- case LIRC_ANIMAX:
- case LIRC_IGOR:
- /* if nothing specified, use ttyS0/com1 and irq 4 */
- io = io ? io : 0x3f8;
- irq = irq ? irq : 4;
- break;
- default:
- return -EINVAL;
- }
- if (!softcarrier) {
- switch (type) {
- case LIRC_HOMEBREW:
- case LIRC_IGOR:
- hardware[type].features &=
- ~(LIRC_CAN_SET_SEND_DUTY_CYCLE|
- LIRC_CAN_SET_SEND_CARRIER);
- break;
- }
- }
-
- /* make sure sense is either -1, 0, or 1 */
- if (sense != -1)
- sense = !!sense;
-
- result = lirc_serial_init();
- if (result)
- return result;
-
- driver.features = hardware[type].features;
- driver.dev = &lirc_serial_dev->dev;
- driver.minor = lirc_register_driver(&driver);
- if (driver.minor < 0) {
- pr_err("register_chrdev failed!\n");
- lirc_serial_exit();
- return driver.minor;
- }
- return 0;
-}
-
-static void __exit lirc_serial_exit_module(void)
-{
- lirc_unregister_driver(driver.minor);
- lirc_serial_exit();
- pr_debug("cleaned up module\n");
-}
-
-
-module_init(lirc_serial_init_module);
-module_exit(lirc_serial_exit_module);
-
-MODULE_DESCRIPTION("Infra-red receiver driver for serial ports.");
-MODULE_AUTHOR("Ralph Metzler, Trent Piepho, Ben Pfaff, "
- "Christoph Bartelmus, Andrei Tanas");
-MODULE_LICENSE("GPL");
-
-module_param(type, int, S_IRUGO);
-MODULE_PARM_DESC(type, "Hardware type (0 = home-brew, 1 = IRdeo,"
- " 2 = IRdeo Remote, 3 = AnimaX, 4 = IgorPlug,"
- " 5 = NSLU2 RX:CTS2/TX:GreenLED)");
-
-module_param(io, int, S_IRUGO);
-MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
-
-/* some architectures (e.g. intel xscale) have memory mapped registers */
-module_param(iommap, bool, S_IRUGO);
-MODULE_PARM_DESC(iommap, "physical base for memory mapped I/O"
- " (0 = no memory mapped io)");
-
-/*
- * some architectures (e.g. intel xscale) align the 8bit serial registers
- * on 32bit word boundaries.
- * See linux-kernel/drivers/tty/serial/8250/8250.c serial_in()/out()
- */
-module_param(ioshift, int, S_IRUGO);
-MODULE_PARM_DESC(ioshift, "shift I/O register offset (0 = no shift)");
-
-module_param(irq, int, S_IRUGO);
-MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
-
-module_param(share_irq, bool, S_IRUGO);
-MODULE_PARM_DESC(share_irq, "Share interrupts (0 = off, 1 = on)");
-
-module_param(sense, int, S_IRUGO);
-MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
- " (0 = active high, 1 = active low )");
-
-#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
-module_param(txsense, bool, S_IRUGO);
-MODULE_PARM_DESC(txsense, "Sense of transmitter circuit"
- " (0 = active high, 1 = active low )");
-#endif
-
-module_param(softcarrier, bool, S_IRUGO);
-MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
diff --git a/drivers/staging/media/pulse8-cec/Kconfig b/drivers/staging/media/pulse8-cec/Kconfig
deleted file mode 100644
index c6aa2d1c9df0..000000000000
--- a/drivers/staging/media/pulse8-cec/Kconfig
+++ /dev/null
@@ -1,10 +0,0 @@
-config USB_PULSE8_CEC
- tristate "Pulse Eight HDMI CEC"
- depends on USB_ACM && MEDIA_CEC
- select SERIO
- select SERIO_SERPORT
- ---help---
- This is a cec driver for the Pulse Eight HDMI CEC device.
-
- To compile this driver as a module, choose M here: the
- module will be called pulse8-cec.
diff --git a/drivers/staging/media/pulse8-cec/Makefile b/drivers/staging/media/pulse8-cec/Makefile
deleted file mode 100644
index 9800690bc25a..000000000000
--- a/drivers/staging/media/pulse8-cec/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-obj-$(CONFIG_USB_PULSE8_CEC) += pulse8-cec.o
diff --git a/drivers/staging/media/pulse8-cec/TODO b/drivers/staging/media/pulse8-cec/TODO
deleted file mode 100644
index fa6660245e5f..000000000000
--- a/drivers/staging/media/pulse8-cec/TODO
+++ /dev/null
@@ -1,52 +0,0 @@
-This driver needs to mature a bit more and another round of
-code cleanups.
-
-Otherwise it looks to be in good shape. And of course the fact
-that the CEC framework is in staging at the moment also prevents
-this driver from being mainlined.
-
-Some notes:
-
-1) Regarding the "autonomous" mode of the Pulse-Eight: currently this
-is disabled, but the idea is that this allows basic functionality
-when the PC is off, and it can wake-up the PC through USB.
-
-To prevent the device to go into autonomous mode the driver would
-have to send MSGCODE_SET_CONTROLLED 1 and then send a ping every
-30 seconds (in practice once every 15 seconds would be good). When
-powering off or going to standby send MSGCODE_SET_CONTROLLED 0 to
-turn the autonomous mode back on.
-
-This needs to be implemented in the driver. Autonomous mode was
-added in firmware v2.
-
-2) Writing to the EEPROM can only be done once every 10 seconds.
-
-3) To use this driver you also need to patch the inputattach utility,
-this patch will be submitted once this driver is moved out of staging.
-
-diff -urN linuxconsoletools-1.4.9/utils/inputattach.c linuxconsoletools-1.4.9.new/utils/inputattach.c
---- linuxconsoletools-1.4.9/utils/inputattach.c 2016-01-09 16:27:02.000000000 +0100
-+++ linuxconsoletools-1.4.9.new/utils/inputattach.c 2016-03-20 11:35:31.707788967 +0100
-@@ -861,6 +861,9 @@
- { "--wacom_iv", "-wacom_iv", "Wacom protocol IV tablet",
- B9600, CS8 | CRTSCTS,
- SERIO_WACOM_IV, 0x00, 0x00, 0, wacom_iv_init },
-+{ "--pulse8-cec", "-pulse8-cec", "Pulse Eight HDMI CEC dongle",
-+ B9600, CS8,
-+ SERIO_PULSE8_CEC, 0x00, 0x00, 0, NULL },
- { NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, NULL }
- };
-
-diff -urN linuxconsoletools-1.4.9/utils/serio-ids.h linuxconsoletools-1.4.9.new/utils/serio-ids.h
---- linuxconsoletools-1.4.9/utils/serio-ids.h 2015-04-26 18:29:42.000000000 +0200
-+++ linuxconsoletools-1.4.9.new/utils/serio-ids.h 2016-03-20 11:41:00.153558539 +0100
-@@ -131,5 +131,8 @@
- #ifndef SERIO_EASYPEN
- # define SERIO_EASYPEN 0x3f
- #endif
-+#ifndef SERIO_PULSE8_CEC
-+# define SERIO_PULSE8_CEC 0x40
-+#endif
-
- #endif
diff --git a/drivers/staging/media/pulse8-cec/pulse8-cec.c b/drivers/staging/media/pulse8-cec/pulse8-cec.c
deleted file mode 100644
index 1732c3857b8e..000000000000
--- a/drivers/staging/media/pulse8-cec/pulse8-cec.c
+++ /dev/null
@@ -1,753 +0,0 @@
-/*
- * Pulse Eight HDMI CEC driver
- *
- * Copyright 2016 Hans Verkuil <hverkuil@xs4all.nl
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version of 2 of the License, or (at your
- * option) any later version. See the file COPYING in the main directory of
- * this archive for more details.
- */
-
-/*
- * Notes:
- *
- * - Devices with firmware version < 2 do not store their configuration in
- * EEPROM.
- *
- * - In autonomous mode, only messages from a TV will be acknowledged, even
- * polling messages. Upon receiving a message from a TV, the dongle will
- * respond to messages from any logical address.
- *
- * - In autonomous mode, the dongle will by default reply Feature Abort
- * [Unrecognized Opcode] when it receives Give Device Vendor ID. It will
- * however observe vendor ID's reported by other devices and possibly
- * alter this behavior. When TV's (and TV's only) report that their vendor ID
- * is LG (0x00e091), the dongle will itself reply that it has the same vendor
- * ID, and it will respond to at least one vendor specific command.
- *
- * - In autonomous mode, the dongle is known to attempt wakeup if it receives
- * <User Control Pressed> ["Power On"], ["Power] or ["Power Toggle"], or if it
- * receives <Set Stream Path> with its own physical address. It also does this
- * if it receives <Vendor Specific Command> [0x03 0x00] from an LG TV.
- */
-
-#include <linux/completion.h>
-#include <linux/init.h>
-#include <linux/interrupt.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/workqueue.h>
-#include <linux/serio.h>
-#include <linux/slab.h>
-#include <linux/time.h>
-#include <linux/delay.h>
-
-#include <media/cec.h>
-
-MODULE_AUTHOR("Hans Verkuil <hverkuil@xs4all.nl>");
-MODULE_DESCRIPTION("Pulse Eight HDMI CEC driver");
-MODULE_LICENSE("GPL");
-
-static int debug;
-static int persistent_config = 1;
-module_param(debug, int, 0644);
-module_param(persistent_config, int, 0644);
-MODULE_PARM_DESC(debug, "debug level (0-1)");
-MODULE_PARM_DESC(persistent_config, "read config from persistent memory (0-1)");
-
-enum pulse8_msgcodes {
- MSGCODE_NOTHING = 0,
- MSGCODE_PING,
- MSGCODE_TIMEOUT_ERROR,
- MSGCODE_HIGH_ERROR,
- MSGCODE_LOW_ERROR,
- MSGCODE_FRAME_START,
- MSGCODE_FRAME_DATA,
- MSGCODE_RECEIVE_FAILED,
- MSGCODE_COMMAND_ACCEPTED, /* 0x08 */
- MSGCODE_COMMAND_REJECTED,
- MSGCODE_SET_ACK_MASK,
- MSGCODE_TRANSMIT,
- MSGCODE_TRANSMIT_EOM,
- MSGCODE_TRANSMIT_IDLETIME,
- MSGCODE_TRANSMIT_ACK_POLARITY,
- MSGCODE_TRANSMIT_LINE_TIMEOUT,
- MSGCODE_TRANSMIT_SUCCEEDED, /* 0x10 */
- MSGCODE_TRANSMIT_FAILED_LINE,
- MSGCODE_TRANSMIT_FAILED_ACK,
- MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA,
- MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE,
- MSGCODE_FIRMWARE_VERSION,
- MSGCODE_START_BOOTLOADER,
- MSGCODE_GET_BUILDDATE,
- MSGCODE_SET_CONTROLLED, /* 0x18 */
- MSGCODE_GET_AUTO_ENABLED,
- MSGCODE_SET_AUTO_ENABLED,
- MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS,
- MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS,
- MSGCODE_GET_LOGICAL_ADDRESS_MASK,
- MSGCODE_SET_LOGICAL_ADDRESS_MASK,
- MSGCODE_GET_PHYSICAL_ADDRESS,
- MSGCODE_SET_PHYSICAL_ADDRESS, /* 0x20 */
- MSGCODE_GET_DEVICE_TYPE,
- MSGCODE_SET_DEVICE_TYPE,
- MSGCODE_GET_HDMI_VERSION,
- MSGCODE_SET_HDMI_VERSION,
- MSGCODE_GET_OSD_NAME,
- MSGCODE_SET_OSD_NAME,
- MSGCODE_WRITE_EEPROM,
- MSGCODE_GET_ADAPTER_TYPE, /* 0x28 */
- MSGCODE_SET_ACTIVE_SOURCE,
-
- MSGCODE_FRAME_EOM = 0x80,
- MSGCODE_FRAME_ACK = 0x40,
-};
-
-#define MSGSTART 0xff
-#define MSGEND 0xfe
-#define MSGESC 0xfd
-#define MSGOFFSET 3
-
-#define DATA_SIZE 256
-
-#define PING_PERIOD (15 * HZ)
-
-struct pulse8 {
- struct device *dev;
- struct serio *serio;
- struct cec_adapter *adap;
- unsigned int vers;
- struct completion cmd_done;
- struct work_struct work;
- struct delayed_work ping_eeprom_work;
- struct cec_msg rx_msg;
- u8 data[DATA_SIZE];
- unsigned int len;
- u8 buf[DATA_SIZE];
- unsigned int idx;
- bool escape;
- bool started;
- struct mutex config_lock;
- struct mutex write_lock;
- bool config_pending;
- bool restoring_config;
- bool autonomous;
-};
-
-static void pulse8_ping_eeprom_work_handler(struct work_struct *work);
-
-static void pulse8_irq_work_handler(struct work_struct *work)
-{
- struct pulse8 *pulse8 =
- container_of(work, struct pulse8, work);
-
- switch (pulse8->data[0] & 0x3f) {
- case MSGCODE_FRAME_DATA:
- cec_received_msg(pulse8->adap, &pulse8->rx_msg);
- break;
- case MSGCODE_TRANSMIT_SUCCEEDED:
- cec_transmit_done(pulse8->adap, CEC_TX_STATUS_OK,
- 0, 0, 0, 0);
- break;
- case MSGCODE_TRANSMIT_FAILED_ACK:
- cec_transmit_done(pulse8->adap, CEC_TX_STATUS_NACK,
- 0, 1, 0, 0);
- break;
- case MSGCODE_TRANSMIT_FAILED_LINE:
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA:
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE:
- cec_transmit_done(pulse8->adap, CEC_TX_STATUS_ERROR,
- 0, 0, 0, 1);
- break;
- }
-}
-
-static irqreturn_t pulse8_interrupt(struct serio *serio, unsigned char data,
- unsigned int flags)
-{
- struct pulse8 *pulse8 = serio_get_drvdata(serio);
-
- if (!pulse8->started && data != MSGSTART)
- return IRQ_HANDLED;
- if (data == MSGESC) {
- pulse8->escape = true;
- return IRQ_HANDLED;
- }
- if (pulse8->escape) {
- data += MSGOFFSET;
- pulse8->escape = false;
- } else if (data == MSGEND) {
- struct cec_msg *msg = &pulse8->rx_msg;
-
- if (debug)
- dev_info(pulse8->dev, "received: %*ph\n",
- pulse8->idx, pulse8->buf);
- pulse8->data[0] = pulse8->buf[0];
- switch (pulse8->buf[0] & 0x3f) {
- case MSGCODE_FRAME_START:
- msg->len = 1;
- msg->msg[0] = pulse8->buf[1];
- break;
- case MSGCODE_FRAME_DATA:
- if (msg->len == CEC_MAX_MSG_SIZE)
- break;
- msg->msg[msg->len++] = pulse8->buf[1];
- if (pulse8->buf[0] & MSGCODE_FRAME_EOM)
- schedule_work(&pulse8->work);
- break;
- case MSGCODE_TRANSMIT_SUCCEEDED:
- case MSGCODE_TRANSMIT_FAILED_LINE:
- case MSGCODE_TRANSMIT_FAILED_ACK:
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA:
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE:
- schedule_work(&pulse8->work);
- break;
- case MSGCODE_HIGH_ERROR:
- case MSGCODE_LOW_ERROR:
- case MSGCODE_RECEIVE_FAILED:
- case MSGCODE_TIMEOUT_ERROR:
- break;
- case MSGCODE_COMMAND_ACCEPTED:
- case MSGCODE_COMMAND_REJECTED:
- default:
- if (pulse8->idx == 0)
- break;
- memcpy(pulse8->data, pulse8->buf, pulse8->idx);
- pulse8->len = pulse8->idx;
- complete(&pulse8->cmd_done);
- break;
- }
- pulse8->idx = 0;
- pulse8->started = false;
- return IRQ_HANDLED;
- } else if (data == MSGSTART) {
- pulse8->idx = 0;
- pulse8->started = true;
- return IRQ_HANDLED;
- }
-
- if (pulse8->idx >= DATA_SIZE) {
- dev_dbg(pulse8->dev,
- "throwing away %d bytes of garbage\n", pulse8->idx);
- pulse8->idx = 0;
- }
- pulse8->buf[pulse8->idx++] = data;
- return IRQ_HANDLED;
-}
-
-static void pulse8_disconnect(struct serio *serio)
-{
- struct pulse8 *pulse8 = serio_get_drvdata(serio);
-
- cec_unregister_adapter(pulse8->adap);
- cancel_delayed_work_sync(&pulse8->ping_eeprom_work);
- dev_info(&serio->dev, "disconnected\n");
- serio_close(serio);
- serio_set_drvdata(serio, NULL);
- kfree(pulse8);
-}
-
-static int pulse8_send(struct serio *serio, const u8 *command, u8 cmd_len)
-{
- int err = 0;
-
- err = serio_write(serio, MSGSTART);
- if (err)
- return err;
- for (; !err && cmd_len; command++, cmd_len--) {
- if (*command >= MSGESC) {
- err = serio_write(serio, MSGESC);
- if (!err)
- err = serio_write(serio, *command - MSGOFFSET);
- } else {
- err = serio_write(serio, *command);
- }
- }
- if (!err)
- err = serio_write(serio, MSGEND);
-
- return err;
-}
-
-static int pulse8_send_and_wait_once(struct pulse8 *pulse8,
- const u8 *cmd, u8 cmd_len,
- u8 response, u8 size)
-{
- int err;
-
- /*dev_info(pulse8->dev, "transmit: %*ph\n", cmd_len, cmd);*/
- init_completion(&pulse8->cmd_done);
-
- err = pulse8_send(pulse8->serio, cmd, cmd_len);
- if (err)
- return err;
-
- if (!wait_for_completion_timeout(&pulse8->cmd_done, HZ))
- return -ETIMEDOUT;
- if ((pulse8->data[0] & 0x3f) == MSGCODE_COMMAND_REJECTED &&
- cmd[0] != MSGCODE_SET_CONTROLLED &&
- cmd[0] != MSGCODE_SET_AUTO_ENABLED &&
- cmd[0] != MSGCODE_GET_BUILDDATE)
- return -ENOTTY;
- if (response &&
- ((pulse8->data[0] & 0x3f) != response || pulse8->len < size + 1)) {
- dev_info(pulse8->dev, "transmit: failed %02x\n",
- pulse8->data[0] & 0x3f);
- return -EIO;
- }
- return 0;
-}
-
-static int pulse8_send_and_wait(struct pulse8 *pulse8,
- const u8 *cmd, u8 cmd_len, u8 response, u8 size)
-{
- u8 cmd_sc[2];
- int err;
-
- mutex_lock(&pulse8->write_lock);
- err = pulse8_send_and_wait_once(pulse8, cmd, cmd_len, response, size);
-
- if (err == -ENOTTY) {
- cmd_sc[0] = MSGCODE_SET_CONTROLLED;
- cmd_sc[1] = 1;
- err = pulse8_send_and_wait_once(pulse8, cmd_sc, 2,
- MSGCODE_COMMAND_ACCEPTED, 1);
- if (err)
- goto unlock;
- err = pulse8_send_and_wait_once(pulse8, cmd, cmd_len,
- response, size);
- }
-
-unlock:
- mutex_unlock(&pulse8->write_lock);
- return err == -ENOTTY ? -EIO : err;
-}
-
-static int pulse8_setup(struct pulse8 *pulse8, struct serio *serio,
- struct cec_log_addrs *log_addrs, u16 *pa)
-{
- u8 *data = pulse8->data + 1;
- u8 cmd[2];
- int err;
- struct tm tm;
- time_t date;
-
- pulse8->vers = 0;
-
- cmd[0] = MSGCODE_FIRMWARE_VERSION;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 2);
- if (err)
- return err;
- pulse8->vers = (data[0] << 8) | data[1];
- dev_info(pulse8->dev, "Firmware version %04x\n", pulse8->vers);
- if (pulse8->vers < 2) {
- *pa = CEC_PHYS_ADDR_INVALID;
- return 0;
- }
-
- cmd[0] = MSGCODE_GET_BUILDDATE;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 4);
- if (err)
- return err;
- date = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
- time_to_tm(date, 0, &tm);
- dev_info(pulse8->dev, "Firmware build date %04ld.%02d.%02d %02d:%02d:%02d\n",
- tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
- tm.tm_hour, tm.tm_min, tm.tm_sec);
-
- dev_dbg(pulse8->dev, "Persistent config:\n");
- cmd[0] = MSGCODE_GET_AUTO_ENABLED;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1);
- if (err)
- return err;
- pulse8->autonomous = data[0];
- dev_dbg(pulse8->dev, "Autonomous mode: %s",
- data[0] ? "on" : "off");
-
- cmd[0] = MSGCODE_GET_DEVICE_TYPE;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1);
- if (err)
- return err;
- log_addrs->primary_device_type[0] = data[0];
- dev_dbg(pulse8->dev, "Primary device type: %d\n", data[0]);
- switch (log_addrs->primary_device_type[0]) {
- case CEC_OP_PRIM_DEVTYPE_TV:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_TV;
- break;
- case CEC_OP_PRIM_DEVTYPE_RECORD:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_RECORD;
- break;
- case CEC_OP_PRIM_DEVTYPE_TUNER:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_TUNER;
- break;
- case CEC_OP_PRIM_DEVTYPE_PLAYBACK:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_PLAYBACK;
- break;
- case CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_PLAYBACK;
- break;
- case CEC_OP_PRIM_DEVTYPE_SWITCH:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_UNREGISTERED;
- break;
- case CEC_OP_PRIM_DEVTYPE_PROCESSOR:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_SPECIFIC;
- break;
- default:
- log_addrs->log_addr_type[0] = CEC_LOG_ADDR_TYPE_UNREGISTERED;
- dev_info(pulse8->dev, "Unknown Primary Device Type: %d\n",
- log_addrs->primary_device_type[0]);
- break;
- }
-
- cmd[0] = MSGCODE_GET_LOGICAL_ADDRESS_MASK;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 2);
- if (err)
- return err;
- log_addrs->log_addr_mask = (data[0] << 8) | data[1];
- dev_dbg(pulse8->dev, "Logical address ACK mask: %x\n",
- log_addrs->log_addr_mask);
- if (log_addrs->log_addr_mask)
- log_addrs->num_log_addrs = 1;
-
- cmd[0] = MSGCODE_GET_PHYSICAL_ADDRESS;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1);
- if (err)
- return err;
- *pa = (data[0] << 8) | data[1];
- dev_dbg(pulse8->dev, "Physical address: %x.%x.%x.%x\n",
- cec_phys_addr_exp(*pa));
-
- cmd[0] = MSGCODE_GET_HDMI_VERSION;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 1);
- if (err)
- return err;
- log_addrs->cec_version = data[0];
- dev_dbg(pulse8->dev, "CEC version: %d\n", log_addrs->cec_version);
-
- cmd[0] = MSGCODE_GET_OSD_NAME;
- err = pulse8_send_and_wait(pulse8, cmd, 1, cmd[0], 0);
- if (err)
- return err;
- strncpy(log_addrs->osd_name, data, 13);
- dev_dbg(pulse8->dev, "OSD name: %s\n", log_addrs->osd_name);
-
- return 0;
-}
-
-static int pulse8_apply_persistent_config(struct pulse8 *pulse8,
- struct cec_log_addrs *log_addrs,
- u16 pa)
-{
- int err;
-
- err = cec_s_log_addrs(pulse8->adap, log_addrs, false);
- if (err)
- return err;
-
- cec_s_phys_addr(pulse8->adap, pa, false);
-
- return 0;
-}
-
-static int pulse8_cec_adap_enable(struct cec_adapter *adap, bool enable)
-{
- struct pulse8 *pulse8 = adap->priv;
- u8 cmd[16];
- int err;
-
- cmd[0] = MSGCODE_SET_CONTROLLED;
- cmd[1] = enable;
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 1);
- return enable ? err : 0;
-}
-
-static int pulse8_cec_adap_log_addr(struct cec_adapter *adap, u8 log_addr)
-{
- struct pulse8 *pulse8 = adap->priv;
- u16 mask = 0;
- u16 pa = adap->phys_addr;
- u8 cmd[16];
- int err = 0;
-
- mutex_lock(&pulse8->config_lock);
- if (log_addr != CEC_LOG_ADDR_INVALID)
- mask = 1 << log_addr;
- cmd[0] = MSGCODE_SET_ACK_MASK;
- cmd[1] = mask >> 8;
- cmd[2] = mask & 0xff;
- err = pulse8_send_and_wait(pulse8, cmd, 3,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if ((err && mask != 0) || pulse8->restoring_config)
- goto unlock;
-
- cmd[0] = MSGCODE_SET_AUTO_ENABLED;
- cmd[1] = log_addr == CEC_LOG_ADDR_INVALID ? 0 : 1;
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if (err)
- goto unlock;
- pulse8->autonomous = cmd[1];
- if (log_addr == CEC_LOG_ADDR_INVALID)
- goto unlock;
-
- cmd[0] = MSGCODE_SET_DEVICE_TYPE;
- cmd[1] = adap->log_addrs.primary_device_type[0];
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if (err)
- goto unlock;
-
- switch (adap->log_addrs.primary_device_type[0]) {
- case CEC_OP_PRIM_DEVTYPE_TV:
- mask = CEC_LOG_ADDR_MASK_TV;
- break;
- case CEC_OP_PRIM_DEVTYPE_RECORD:
- mask = CEC_LOG_ADDR_MASK_RECORD;
- break;
- case CEC_OP_PRIM_DEVTYPE_TUNER:
- mask = CEC_LOG_ADDR_MASK_TUNER;
- break;
- case CEC_OP_PRIM_DEVTYPE_PLAYBACK:
- mask = CEC_LOG_ADDR_MASK_PLAYBACK;
- break;
- case CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM:
- mask = CEC_LOG_ADDR_MASK_AUDIOSYSTEM;
- break;
- case CEC_OP_PRIM_DEVTYPE_SWITCH:
- mask = CEC_LOG_ADDR_MASK_UNREGISTERED;
- break;
- case CEC_OP_PRIM_DEVTYPE_PROCESSOR:
- mask = CEC_LOG_ADDR_MASK_SPECIFIC;
- break;
- default:
- mask = 0;
- break;
- }
- cmd[0] = MSGCODE_SET_LOGICAL_ADDRESS_MASK;
- cmd[1] = mask >> 8;
- cmd[2] = mask & 0xff;
- err = pulse8_send_and_wait(pulse8, cmd, 3,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if (err)
- goto unlock;
-
- cmd[0] = MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS;
- cmd[1] = log_addr;
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if (err)
- goto unlock;
-
- cmd[0] = MSGCODE_SET_PHYSICAL_ADDRESS;
- cmd[1] = pa >> 8;
- cmd[2] = pa & 0xff;
- err = pulse8_send_and_wait(pulse8, cmd, 3,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if (err)
- goto unlock;
-
- cmd[0] = MSGCODE_SET_HDMI_VERSION;
- cmd[1] = adap->log_addrs.cec_version;
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if (err)
- goto unlock;
-
- if (adap->log_addrs.osd_name[0]) {
- size_t osd_len = strlen(adap->log_addrs.osd_name);
- char *osd_str = cmd + 1;
-
- cmd[0] = MSGCODE_SET_OSD_NAME;
- strncpy(cmd + 1, adap->log_addrs.osd_name, 13);
- if (osd_len < 4) {
- memset(osd_str + osd_len, ' ', 4 - osd_len);
- osd_len = 4;
- osd_str[osd_len] = '\0';
- strcpy(adap->log_addrs.osd_name, osd_str);
- }
- err = pulse8_send_and_wait(pulse8, cmd, 1 + osd_len,
- MSGCODE_COMMAND_ACCEPTED, 0);
- if (err)
- goto unlock;
- }
-
-unlock:
- if (pulse8->restoring_config)
- pulse8->restoring_config = false;
- else
- pulse8->config_pending = true;
- mutex_unlock(&pulse8->config_lock);
- return err;
-}
-
-static int pulse8_cec_adap_transmit(struct cec_adapter *adap, u8 attempts,
- u32 signal_free_time, struct cec_msg *msg)
-{
- struct pulse8 *pulse8 = adap->priv;
- u8 cmd[2];
- unsigned int i;
- int err;
-
- cmd[0] = MSGCODE_TRANSMIT_IDLETIME;
- cmd[1] = signal_free_time;
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 1);
- cmd[0] = MSGCODE_TRANSMIT_ACK_POLARITY;
- cmd[1] = cec_msg_is_broadcast(msg);
- if (!err)
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 1);
- cmd[0] = msg->len == 1 ? MSGCODE_TRANSMIT_EOM : MSGCODE_TRANSMIT;
- cmd[1] = msg->msg[0];
- if (!err)
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 1);
- if (!err && msg->len > 1) {
- cmd[0] = msg->len == 2 ? MSGCODE_TRANSMIT_EOM :
- MSGCODE_TRANSMIT;
- cmd[1] = msg->msg[1];
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 1);
- for (i = 0; !err && i + 2 < msg->len; i++) {
- cmd[0] = (i + 2 == msg->len - 1) ?
- MSGCODE_TRANSMIT_EOM : MSGCODE_TRANSMIT;
- cmd[1] = msg->msg[i + 2];
- err = pulse8_send_and_wait(pulse8, cmd, 2,
- MSGCODE_COMMAND_ACCEPTED, 1);
- }
- }
-
- return err;
-}
-
-static int pulse8_received(struct cec_adapter *adap, struct cec_msg *msg)
-{
- return -ENOMSG;
-}
-
-static const struct cec_adap_ops pulse8_cec_adap_ops = {
- .adap_enable = pulse8_cec_adap_enable,
- .adap_log_addr = pulse8_cec_adap_log_addr,
- .adap_transmit = pulse8_cec_adap_transmit,
- .received = pulse8_received,
-};
-
-static int pulse8_connect(struct serio *serio, struct serio_driver *drv)
-{
- u32 caps = CEC_CAP_TRANSMIT | CEC_CAP_LOG_ADDRS | CEC_CAP_PHYS_ADDR |
- CEC_CAP_PASSTHROUGH | CEC_CAP_RC | CEC_CAP_MONITOR_ALL;
- struct pulse8 *pulse8;
- int err = -ENOMEM;
- struct cec_log_addrs log_addrs = {};
- u16 pa = CEC_PHYS_ADDR_INVALID;
-
- pulse8 = kzalloc(sizeof(*pulse8), GFP_KERNEL);
-
- if (!pulse8)
- return -ENOMEM;
-
- pulse8->serio = serio;
- pulse8->adap = cec_allocate_adapter(&pulse8_cec_adap_ops, pulse8,
- "HDMI CEC", caps, 1, &serio->dev);
- err = PTR_ERR_OR_ZERO(pulse8->adap);
- if (err < 0)
- goto free_device;
-
- pulse8->dev = &serio->dev;
- serio_set_drvdata(serio, pulse8);
- INIT_WORK(&pulse8->work, pulse8_irq_work_handler);
- mutex_init(&pulse8->write_lock);
- mutex_init(&pulse8->config_lock);
- pulse8->config_pending = false;
-
- err = serio_open(serio, drv);
- if (err)
- goto delete_adap;
-
- err = pulse8_setup(pulse8, serio, &log_addrs, &pa);
- if (err)
- goto close_serio;
-
- err = cec_register_adapter(pulse8->adap);
- if (err < 0)
- goto close_serio;
-
- pulse8->dev = &pulse8->adap->devnode.dev;
-
- if (persistent_config && pulse8->autonomous) {
- err = pulse8_apply_persistent_config(pulse8, &log_addrs, pa);
- if (err)
- goto close_serio;
- pulse8->restoring_config = true;
- }
-
- INIT_DELAYED_WORK(&pulse8->ping_eeprom_work,
- pulse8_ping_eeprom_work_handler);
- schedule_delayed_work(&pulse8->ping_eeprom_work, PING_PERIOD);
-
- return 0;
-
-close_serio:
- serio_close(serio);
-delete_adap:
- cec_delete_adapter(pulse8->adap);
- serio_set_drvdata(serio, NULL);
-free_device:
- kfree(pulse8);
- return err;
-}
-
-static void pulse8_ping_eeprom_work_handler(struct work_struct *work)
-{
- struct pulse8 *pulse8 =
- container_of(work, struct pulse8, ping_eeprom_work.work);
- u8 cmd;
-
- schedule_delayed_work(&pulse8->ping_eeprom_work, PING_PERIOD);
- cmd = MSGCODE_PING;
- pulse8_send_and_wait(pulse8, &cmd, 1,
- MSGCODE_COMMAND_ACCEPTED, 0);
-
- if (pulse8->vers < 2)
- return;
-
- mutex_lock(&pulse8->config_lock);
- if (pulse8->config_pending && persistent_config) {
- dev_dbg(pulse8->dev, "writing pending config to EEPROM\n");
- cmd = MSGCODE_WRITE_EEPROM;
- if (pulse8_send_and_wait(pulse8, &cmd, 1,
- MSGCODE_COMMAND_ACCEPTED, 0))
- dev_info(pulse8->dev, "failed to write pending config to EEPROM\n");
- else
- pulse8->config_pending = false;
- }
- mutex_unlock(&pulse8->config_lock);
-}
-
-static struct serio_device_id pulse8_serio_ids[] = {
- {
- .type = SERIO_RS232,
- .proto = SERIO_PULSE8_CEC,
- .id = SERIO_ANY,
- .extra = SERIO_ANY,
- },
- { 0 }
-};
-
-MODULE_DEVICE_TABLE(serio, pulse8_serio_ids);
-
-static struct serio_driver pulse8_drv = {
- .driver = {
- .name = "pulse8-cec",
- },
- .description = "Pulse Eight HDMI CEC driver",
- .id_table = pulse8_serio_ids,
- .interrupt = pulse8_interrupt,
- .connect = pulse8_connect,
- .disconnect = pulse8_disconnect,
-};
-
-module_serio_driver(pulse8_drv);
diff --git a/drivers/staging/media/s5p-cec/Kconfig b/drivers/staging/media/s5p-cec/Kconfig
index 0315fd7ad0f1..ddfd955da0d4 100644
--- a/drivers/staging/media/s5p-cec/Kconfig
+++ b/drivers/staging/media/s5p-cec/Kconfig
@@ -1,6 +1,6 @@
config VIDEO_SAMSUNG_S5P_CEC
tristate "Samsung S5P CEC driver"
- depends on VIDEO_DEV && MEDIA_CEC && (PLAT_S5P || ARCH_EXYNOS || COMPILE_TEST)
+ depends on VIDEO_DEV && MEDIA_CEC_SUPPORT && (PLAT_S5P || ARCH_EXYNOS || COMPILE_TEST)
---help---
This is a driver for Samsung S5P HDMI CEC interface. It uses the
generic CEC framework interface.
diff --git a/drivers/staging/media/s5p-cec/TODO b/drivers/staging/media/s5p-cec/TODO
index f51d5268ac40..64f21bab38f5 100644
--- a/drivers/staging/media/s5p-cec/TODO
+++ b/drivers/staging/media/s5p-cec/TODO
@@ -1,7 +1,7 @@
-This driver depends on the CEC framework, which is currently in
-staging, so therefor this driver is in staging as well.
+This driver requires that userspace sets the physical address.
+However, this should be passed on from the corresponding
+Samsung HDMI driver.
-In addition, this driver requires that userspace sets the physical
-address. However, this should be passed on from the corresponding
-samsung HDMI driver. It is very annoying if userspace has to do this,
-and other than USB CEC adapters this must be handled automatically.
+We have to wait until the HDMI notifier framework has been merged
+in order to handle this gracefully, until that time this driver
+has to remain in staging.
diff --git a/drivers/staging/media/s5p-cec/s5p_cec.c b/drivers/staging/media/s5p-cec/s5p_cec.c
index aef962b6af31..2a07968b5ac6 100644
--- a/drivers/staging/media/s5p-cec/s5p_cec.c
+++ b/drivers/staging/media/s5p-cec/s5p_cec.c
@@ -203,12 +203,11 @@ static int s5p_cec_probe(struct platform_device *pdev)
cec->adap = cec_allocate_adapter(&s5p_cec_adap_ops, cec,
CEC_NAME,
CEC_CAP_PHYS_ADDR | CEC_CAP_LOG_ADDRS | CEC_CAP_TRANSMIT |
- CEC_CAP_PASSTHROUGH | CEC_CAP_RC,
- 1, &pdev->dev);
+ CEC_CAP_PASSTHROUGH | CEC_CAP_RC, 1);
ret = PTR_ERR_OR_ZERO(cec->adap);
if (ret)
return ret;
- ret = cec_register_adapter(cec->adap);
+ ret = cec_register_adapter(cec->adap, &pdev->dev);
if (ret) {
cec_delete_adapter(cec->adap);
return ret;
@@ -230,7 +229,7 @@ static int s5p_cec_remove(struct platform_device *pdev)
return 0;
}
-static int s5p_cec_runtime_suspend(struct device *dev)
+static int __maybe_unused s5p_cec_runtime_suspend(struct device *dev)
{
struct s5p_cec_dev *cec = dev_get_drvdata(dev);
@@ -238,7 +237,7 @@ static int s5p_cec_runtime_suspend(struct device *dev)
return 0;
}
-static int s5p_cec_runtime_resume(struct device *dev)
+static int __maybe_unused s5p_cec_runtime_resume(struct device *dev)
{
struct s5p_cec_dev *cec = dev_get_drvdata(dev);
int ret;
@@ -262,6 +261,7 @@ static const struct of_device_id s5p_cec_match[] = {
},
{},
};
+MODULE_DEVICE_TABLE(of, s5p_cec_match);
static struct platform_driver s5p_cec_pdrv = {
.probe = s5p_cec_probe,
diff --git a/drivers/staging/media/st-cec/Kconfig b/drivers/staging/media/st-cec/Kconfig
index 784d2c600aca..c04283db58d6 100644
--- a/drivers/staging/media/st-cec/Kconfig
+++ b/drivers/staging/media/st-cec/Kconfig
@@ -1,6 +1,6 @@
config VIDEO_STI_HDMI_CEC
tristate "STMicroelectronics STiH4xx HDMI CEC driver"
- depends on VIDEO_DEV && MEDIA_CEC && (ARCH_STI || COMPILE_TEST)
+ depends on VIDEO_DEV && MEDIA_CEC_SUPPORT && (ARCH_STI || COMPILE_TEST)
---help---
This is a driver for STIH4xx HDMI CEC interface. It uses the
generic CEC framework interface.
diff --git a/drivers/staging/media/st-cec/TODO b/drivers/staging/media/st-cec/TODO
new file mode 100644
index 000000000000..c61289742c5c
--- /dev/null
+++ b/drivers/staging/media/st-cec/TODO
@@ -0,0 +1,7 @@
+This driver requires that userspace sets the physical address.
+However, this should be passed on from the corresponding
+ST HDMI driver.
+
+We have to wait until the HDMI notifier framework has been merged
+in order to handle this gracefully, until that time this driver
+has to remain in staging.
diff --git a/drivers/staging/media/st-cec/stih-cec.c b/drivers/staging/media/st-cec/stih-cec.c
index b22394ac4ec4..3c25638a9610 100644
--- a/drivers/staging/media/st-cec/stih-cec.c
+++ b/drivers/staging/media/st-cec/stih-cec.c
@@ -16,7 +16,6 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
-#include <linux/version.h>
#include <media/cec.h>
@@ -336,13 +335,12 @@ static int stih_cec_probe(struct platform_device *pdev)
cec->adap = cec_allocate_adapter(&sti_cec_adap_ops, cec,
CEC_NAME,
CEC_CAP_LOG_ADDRS | CEC_CAP_PASSTHROUGH |
- CEC_CAP_PHYS_ADDR | CEC_CAP_TRANSMIT,
- 1, &pdev->dev);
+ CEC_CAP_PHYS_ADDR | CEC_CAP_TRANSMIT, 1);
ret = PTR_ERR_OR_ZERO(cec->adap);
if (ret)
return ret;
- ret = cec_register_adapter(cec->adap);
+ ret = cec_register_adapter(cec->adap, &pdev->dev);
if (ret) {
cec_delete_adapter(cec->adap);
return ret;
@@ -363,6 +361,7 @@ static const struct of_device_id stih_cec_match[] = {
},
{},
};
+MODULE_DEVICE_TABLE(of, stih_cec_match);
static struct platform_driver stih_cec_pdrv = {
.probe = stih_cec_probe,