diff options
Diffstat (limited to 'drivers/staging')
909 files changed, 63037 insertions, 87362 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 7fec86946131..5cfabd5376cc 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -42,8 +42,6 @@ source "drivers/staging/rts5208/Kconfig" source "drivers/staging/octeon/Kconfig" -source "drivers/staging/octeon-usb/Kconfig" - source "drivers/staging/vt6655/Kconfig" source "drivers/staging/vt6656/Kconfig" @@ -58,20 +56,10 @@ source "drivers/staging/nvec/Kconfig" source "drivers/staging/media/Kconfig" -source "drivers/staging/android/Kconfig" - source "drivers/staging/board/Kconfig" source "drivers/staging/gdm724x/Kconfig" -source "drivers/staging/fwserial/Kconfig" - -source "drivers/staging/gs_fpgaboot/Kconfig" - -source "drivers/staging/unisys/Kconfig" - -source "drivers/staging/clocking-wizard/Kconfig" - source "drivers/staging/fbtft/Kconfig" source "drivers/staging/most/Kconfig" @@ -84,18 +72,12 @@ source "drivers/staging/vc04_services/Kconfig" source "drivers/staging/pi433/Kconfig" -source "drivers/staging/mt7621-dma/Kconfig" - -source "drivers/staging/ralink-gdma/Kconfig" - -source "drivers/staging/mt7621-dts/Kconfig" - source "drivers/staging/axis-fifo/Kconfig" source "drivers/staging/fieldbus/Kconfig" source "drivers/staging/qlge/Kconfig" -source "drivers/staging/wfx/Kconfig" +source "drivers/staging/vme_user/Kconfig" endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index e66e19c45425..f8c3aa9c2418 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -11,31 +11,21 @@ obj-$(CONFIG_R8712U) += rtl8712/ obj-$(CONFIG_R8188EU) += r8188eu/ obj-$(CONFIG_RTS5208) += rts5208/ obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ -obj-$(CONFIG_OCTEON_USB) += octeon-usb/ obj-$(CONFIG_VT6655) += vt6655/ obj-$(CONFIG_VT6656) += vt6656/ -obj-$(CONFIG_VME_BUS) += vme/ +obj-$(CONFIG_VME_BUS) += vme_user/ obj-$(CONFIG_IIO) += iio/ obj-$(CONFIG_FB_SM750) += sm750fb/ obj-$(CONFIG_USB_EMXX) += emxx_udc/ obj-$(CONFIG_MFD_NVEC) += nvec/ -obj-$(CONFIG_ANDROID) += android/ obj-$(CONFIG_STAGING_BOARD) += board/ obj-$(CONFIG_LTE_GDM724X) += gdm724x/ -obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ -obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/ -obj-$(CONFIG_UNISYSSPAR) += unisys/ -obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clocking-wizard/ obj-$(CONFIG_FB_TFT) += fbtft/ obj-$(CONFIG_MOST) += most/ obj-$(CONFIG_KS7010) += ks7010/ obj-$(CONFIG_GREYBUS) += greybus/ obj-$(CONFIG_BCM2835_VCHIQ) += vc04_services/ obj-$(CONFIG_PI433) += pi433/ -obj-$(CONFIG_SOC_MT7621) += mt7621-dma/ -obj-$(CONFIG_DMA_RALINK) += ralink-gdma/ -obj-$(CONFIG_SOC_MT7621) += mt7621-dts/ obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ obj-$(CONFIG_QLGE) += qlge/ -obj-$(CONFIG_WFX) += wfx/ diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig deleted file mode 100644 index 70498adb1575..000000000000 --- a/drivers/staging/android/Kconfig +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -menu "Android" - -if ANDROID - -config ASHMEM - bool "Enable the Anonymous Shared Memory Subsystem" - depends on SHMEM - help - The ashmem subsystem is a new shared memory allocator, similar to - POSIX SHM but with different behavior and sporting a simpler - file-based API. - - It is, in theory, a good memory allocator for low-memory devices, - because it can discard shared memory units when under memory pressure. - -endif # if ANDROID - -endmenu diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile deleted file mode 100644 index e9a55a5e6529..000000000000 --- a/drivers/staging/android/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -ccflags-y += -I$(src) # needed for trace events - -obj-$(CONFIG_ASHMEM) += ashmem.o diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO deleted file mode 100644 index f74eb44d8e45..000000000000 --- a/drivers/staging/android/TODO +++ /dev/null @@ -1,8 +0,0 @@ -TODO: - - sparse fixes - - rename files to be not so "generic" - - add proper arch dependencies as needed - - audit userspace interfaces to make sure they are sane - -Please send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc: -Arve HjønnevÃ¥g <arve@android.com> and Riley Andrews <riandrews@android.com> diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c deleted file mode 100644 index ddbde3f8430e..000000000000 --- a/drivers/staging/android/ashmem.c +++ /dev/null @@ -1,970 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* mm/ashmem.c - * - * Anonymous Shared Memory Subsystem, ashmem - * - * Copyright (C) 2008 Google, Inc. - * - * Robert Love <rlove@google.com> - */ - -#define pr_fmt(fmt) "ashmem: " fmt - -#include <linux/init.h> -#include <linux/export.h> -#include <linux/file.h> -#include <linux/fs.h> -#include <linux/falloc.h> -#include <linux/miscdevice.h> -#include <linux/security.h> -#include <linux/mm.h> -#include <linux/mman.h> -#include <linux/uaccess.h> -#include <linux/personality.h> -#include <linux/bitops.h> -#include <linux/mutex.h> -#include <linux/shmem_fs.h> -#include "ashmem.h" - -#define ASHMEM_NAME_PREFIX "dev/ashmem/" -#define ASHMEM_NAME_PREFIX_LEN (sizeof(ASHMEM_NAME_PREFIX) - 1) -#define ASHMEM_FULL_NAME_LEN (ASHMEM_NAME_LEN + ASHMEM_NAME_PREFIX_LEN) - -/** - * struct ashmem_area - The anonymous shared memory area - * @name: The optional name in /proc/pid/maps - * @unpinned_list: The list of all ashmem areas - * @file: The shmem-based backing file - * @size: The size of the mapping, in bytes - * @prot_mask: The allowed protection bits, as vm_flags - * - * The lifecycle of this structure is from our parent file's open() until - * its release(). It is also protected by 'ashmem_mutex' - * - * Warning: Mappings do NOT pin this structure; It dies on close() - */ -struct ashmem_area { - char name[ASHMEM_FULL_NAME_LEN]; - struct list_head unpinned_list; - struct file *file; - size_t size; - unsigned long prot_mask; -}; - -/** - * struct ashmem_range - A range of unpinned/evictable pages - * @lru: The entry in the LRU list - * @unpinned: The entry in its area's unpinned list - * @asma: The associated anonymous shared memory area. - * @pgstart: The starting page (inclusive) - * @pgend: The ending page (inclusive) - * @purged: The purge status (ASHMEM_NOT or ASHMEM_WAS_PURGED) - * - * The lifecycle of this structure is from unpin to pin. - * It is protected by 'ashmem_mutex' - */ -struct ashmem_range { - struct list_head lru; - struct list_head unpinned; - struct ashmem_area *asma; - size_t pgstart; - size_t pgend; - unsigned int purged; -}; - -/* LRU list of unpinned pages, protected by ashmem_mutex */ -static LIST_HEAD(ashmem_lru_list); - -static atomic_t ashmem_shrink_inflight = ATOMIC_INIT(0); -static DECLARE_WAIT_QUEUE_HEAD(ashmem_shrink_wait); - -/* - * long lru_count - The count of pages on our LRU list. - * - * This is protected by ashmem_mutex. - */ -static unsigned long lru_count; - -/* - * ashmem_mutex - protects the list of and each individual ashmem_area - * - * Lock Ordering: ashmex_mutex -> i_mutex -> i_alloc_sem - */ -static DEFINE_MUTEX(ashmem_mutex); - -static struct kmem_cache *ashmem_area_cachep __read_mostly; -static struct kmem_cache *ashmem_range_cachep __read_mostly; - -/* - * A separate lockdep class for the backing shmem inodes to resolve the lockdep - * warning about the race between kswapd taking fs_reclaim before inode_lock - * and write syscall taking inode_lock and then fs_reclaim. - * Note that such race is impossible because ashmem does not support write - * syscalls operating on the backing shmem. - */ -static struct lock_class_key backing_shmem_inode_class; - -static inline unsigned long range_size(struct ashmem_range *range) -{ - return range->pgend - range->pgstart + 1; -} - -static inline bool range_on_lru(struct ashmem_range *range) -{ - return range->purged == ASHMEM_NOT_PURGED; -} - -static inline bool page_range_subsumes_range(struct ashmem_range *range, - size_t start, size_t end) -{ - return (range->pgstart >= start) && (range->pgend <= end); -} - -static inline bool page_range_subsumed_by_range(struct ashmem_range *range, - size_t start, size_t end) -{ - return (range->pgstart <= start) && (range->pgend >= end); -} - -static inline bool page_in_range(struct ashmem_range *range, size_t page) -{ - return (range->pgstart <= page) && (range->pgend >= page); -} - -static inline bool page_range_in_range(struct ashmem_range *range, - size_t start, size_t end) -{ - return page_in_range(range, start) || page_in_range(range, end) || - page_range_subsumes_range(range, start, end); -} - -static inline bool range_before_page(struct ashmem_range *range, - size_t page) -{ - return range->pgend < page; -} - -#define PROT_MASK (PROT_EXEC | PROT_READ | PROT_WRITE) - -/** - * lru_add() - Adds a range of memory to the LRU list - * @range: The memory range being added. - * - * The range is first added to the end (tail) of the LRU list. - * After this, the size of the range is added to @lru_count - */ -static inline void lru_add(struct ashmem_range *range) -{ - list_add_tail(&range->lru, &ashmem_lru_list); - lru_count += range_size(range); -} - -/** - * lru_del() - Removes a range of memory from the LRU list - * @range: The memory range being removed - * - * The range is first deleted from the LRU list. - * After this, the size of the range is removed from @lru_count - */ -static inline void lru_del(struct ashmem_range *range) -{ - list_del(&range->lru); - lru_count -= range_size(range); -} - -/** - * range_alloc() - Allocates and initializes a new ashmem_range structure - * @asma: The associated ashmem_area - * @prev_range: The previous ashmem_range in the sorted asma->unpinned list - * @purged: Initial purge status (ASMEM_NOT_PURGED or ASHMEM_WAS_PURGED) - * @start: The starting page (inclusive) - * @end: The ending page (inclusive) - * @new_range: The placeholder for the new range - * - * This function is protected by ashmem_mutex. - */ -static void range_alloc(struct ashmem_area *asma, - struct ashmem_range *prev_range, unsigned int purged, - size_t start, size_t end, - struct ashmem_range **new_range) -{ - struct ashmem_range *range = *new_range; - - *new_range = NULL; - range->asma = asma; - range->pgstart = start; - range->pgend = end; - range->purged = purged; - - list_add_tail(&range->unpinned, &prev_range->unpinned); - - if (range_on_lru(range)) - lru_add(range); -} - -/** - * range_del() - Deletes and deallocates an ashmem_range structure - * @range: The associated ashmem_range that has previously been allocated - */ -static void range_del(struct ashmem_range *range) -{ - list_del(&range->unpinned); - if (range_on_lru(range)) - lru_del(range); - kmem_cache_free(ashmem_range_cachep, range); -} - -/** - * range_shrink() - Shrinks an ashmem_range - * @range: The associated ashmem_range being shrunk - * @start: The starting byte of the new range - * @end: The ending byte of the new range - * - * This does not modify the data inside the existing range in any way - It - * simply shrinks the boundaries of the range. - * - * Theoretically, with a little tweaking, this could eventually be changed - * to range_resize, and expand the lru_count if the new range is larger. - */ -static inline void range_shrink(struct ashmem_range *range, - size_t start, size_t end) -{ - size_t pre = range_size(range); - - range->pgstart = start; - range->pgend = end; - - if (range_on_lru(range)) - lru_count -= pre - range_size(range); -} - -/** - * ashmem_open() - Opens an Anonymous Shared Memory structure - * @inode: The backing file's index node(?) - * @file: The backing file - * - * Please note that the ashmem_area is not returned by this function - It is - * instead written to "file->private_data". - * - * Return: 0 if successful, or another code if unsuccessful. - */ -static int ashmem_open(struct inode *inode, struct file *file) -{ - struct ashmem_area *asma; - int ret; - - ret = generic_file_open(inode, file); - if (ret) - return ret; - - asma = kmem_cache_zalloc(ashmem_area_cachep, GFP_KERNEL); - if (!asma) - return -ENOMEM; - - INIT_LIST_HEAD(&asma->unpinned_list); - memcpy(asma->name, ASHMEM_NAME_PREFIX, ASHMEM_NAME_PREFIX_LEN); - asma->prot_mask = PROT_MASK; - file->private_data = asma; - - return 0; -} - -/** - * ashmem_release() - Releases an Anonymous Shared Memory structure - * @ignored: The backing file's Index Node(?) - It is ignored here. - * @file: The backing file - * - * Return: 0 if successful. If it is anything else, go have a coffee and - * try again. - */ -static int ashmem_release(struct inode *ignored, struct file *file) -{ - struct ashmem_area *asma = file->private_data; - struct ashmem_range *range, *next; - - mutex_lock(&ashmem_mutex); - list_for_each_entry_safe(range, next, &asma->unpinned_list, unpinned) - range_del(range); - mutex_unlock(&ashmem_mutex); - - if (asma->file) - fput(asma->file); - kmem_cache_free(ashmem_area_cachep, asma); - - return 0; -} - -static ssize_t ashmem_read_iter(struct kiocb *iocb, struct iov_iter *iter) -{ - struct ashmem_area *asma = iocb->ki_filp->private_data; - int ret = 0; - - mutex_lock(&ashmem_mutex); - - /* If size is not set, or set to 0, always return EOF. */ - if (asma->size == 0) - goto out_unlock; - - if (!asma->file) { - ret = -EBADF; - goto out_unlock; - } - - /* - * asma and asma->file are used outside the lock here. We assume - * once asma->file is set it will never be changed, and will not - * be destroyed until all references to the file are dropped and - * ashmem_release is called. - */ - mutex_unlock(&ashmem_mutex); - ret = vfs_iter_read(asma->file, iter, &iocb->ki_pos, 0); - mutex_lock(&ashmem_mutex); - if (ret > 0) - asma->file->f_pos = iocb->ki_pos; -out_unlock: - mutex_unlock(&ashmem_mutex); - return ret; -} - -static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin) -{ - struct ashmem_area *asma = file->private_data; - loff_t ret; - - mutex_lock(&ashmem_mutex); - - if (asma->size == 0) { - mutex_unlock(&ashmem_mutex); - return -EINVAL; - } - - if (!asma->file) { - mutex_unlock(&ashmem_mutex); - return -EBADF; - } - - mutex_unlock(&ashmem_mutex); - - ret = vfs_llseek(asma->file, offset, origin); - if (ret < 0) - return ret; - - /** Copy f_pos from backing file, since f_ops->llseek() sets it */ - file->f_pos = asma->file->f_pos; - return ret; -} - -static inline vm_flags_t calc_vm_may_flags(unsigned long prot) -{ - return _calc_vm_trans(prot, PROT_READ, VM_MAYREAD) | - _calc_vm_trans(prot, PROT_WRITE, VM_MAYWRITE) | - _calc_vm_trans(prot, PROT_EXEC, VM_MAYEXEC); -} - -static int ashmem_vmfile_mmap(struct file *file, struct vm_area_struct *vma) -{ - /* do not allow to mmap ashmem backing shmem file directly */ - return -EPERM; -} - -static unsigned long -ashmem_vmfile_get_unmapped_area(struct file *file, unsigned long addr, - unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - return current->mm->get_unmapped_area(file, addr, len, pgoff, flags); -} - -static int ashmem_mmap(struct file *file, struct vm_area_struct *vma) -{ - static struct file_operations vmfile_fops; - struct ashmem_area *asma = file->private_data; - int ret = 0; - - mutex_lock(&ashmem_mutex); - - /* user needs to SET_SIZE before mapping */ - if (!asma->size) { - ret = -EINVAL; - goto out; - } - - /* requested mapping size larger than object size */ - if (vma->vm_end - vma->vm_start > PAGE_ALIGN(asma->size)) { - ret = -EINVAL; - goto out; - } - - /* requested protection bits must match our allowed protection mask */ - if ((vma->vm_flags & ~calc_vm_prot_bits(asma->prot_mask, 0)) & - calc_vm_prot_bits(PROT_MASK, 0)) { - ret = -EPERM; - goto out; - } - vma->vm_flags &= ~calc_vm_may_flags(~asma->prot_mask); - - if (!asma->file) { - char *name = ASHMEM_NAME_DEF; - struct file *vmfile; - struct inode *inode; - - if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0') - name = asma->name; - - /* ... and allocate the backing shmem file */ - vmfile = shmem_file_setup(name, asma->size, vma->vm_flags); - if (IS_ERR(vmfile)) { - ret = PTR_ERR(vmfile); - goto out; - } - vmfile->f_mode |= FMODE_LSEEK; - inode = file_inode(vmfile); - lockdep_set_class(&inode->i_rwsem, &backing_shmem_inode_class); - asma->file = vmfile; - /* - * override mmap operation of the vmfile so that it can't be - * remapped which would lead to creation of a new vma with no - * asma permission checks. Have to override get_unmapped_area - * as well to prevent VM_BUG_ON check for f_ops modification. - */ - if (!vmfile_fops.mmap) { - vmfile_fops = *vmfile->f_op; - vmfile_fops.mmap = ashmem_vmfile_mmap; - vmfile_fops.get_unmapped_area = - ashmem_vmfile_get_unmapped_area; - } - vmfile->f_op = &vmfile_fops; - } - get_file(asma->file); - - /* - * XXX - Reworked to use shmem_zero_setup() instead of - * shmem_set_file while we're in staging. -jstultz - */ - if (vma->vm_flags & VM_SHARED) { - ret = shmem_zero_setup(vma); - if (ret) { - fput(asma->file); - goto out; - } - } else { - vma_set_anonymous(vma); - } - - vma_set_file(vma, asma->file); - /* XXX: merge this with the get_file() above if possible */ - fput(asma->file); - -out: - mutex_unlock(&ashmem_mutex); - return ret; -} - -/* - * ashmem_shrink - our cache shrinker, called from mm/vmscan.c - * - * 'nr_to_scan' is the number of objects to scan for freeing. - * - * 'gfp_mask' is the mask of the allocation that got us into this mess. - * - * Return value is the number of objects freed or -1 if we cannot - * proceed without risk of deadlock (due to gfp_mask). - * - * We approximate LRU via least-recently-unpinned, jettisoning unpinned partial - * chunks of ashmem regions LRU-wise one-at-a-time until we hit 'nr_to_scan' - * pages freed. - */ -static unsigned long -ashmem_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) -{ - unsigned long freed = 0; - - /* We might recurse into filesystem code, so bail out if necessary */ - if (!(sc->gfp_mask & __GFP_FS)) - return SHRINK_STOP; - - if (!mutex_trylock(&ashmem_mutex)) - return -1; - - while (!list_empty(&ashmem_lru_list)) { - struct ashmem_range *range = - list_first_entry(&ashmem_lru_list, typeof(*range), lru); - loff_t start = range->pgstart * PAGE_SIZE; - loff_t end = (range->pgend + 1) * PAGE_SIZE; - struct file *f = range->asma->file; - - get_file(f); - atomic_inc(&ashmem_shrink_inflight); - range->purged = ASHMEM_WAS_PURGED; - lru_del(range); - - freed += range_size(range); - mutex_unlock(&ashmem_mutex); - f->f_op->fallocate(f, - FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - start, end - start); - fput(f); - if (atomic_dec_and_test(&ashmem_shrink_inflight)) - wake_up_all(&ashmem_shrink_wait); - if (!mutex_trylock(&ashmem_mutex)) - goto out; - if (--sc->nr_to_scan <= 0) - break; - } - mutex_unlock(&ashmem_mutex); -out: - return freed; -} - -static unsigned long -ashmem_shrink_count(struct shrinker *shrink, struct shrink_control *sc) -{ - /* - * note that lru_count is count of pages on the lru, not a count of - * objects on the list. This means the scan function needs to return the - * number of pages freed, not the number of objects scanned. - */ - return lru_count; -} - -static struct shrinker ashmem_shrinker = { - .count_objects = ashmem_shrink_count, - .scan_objects = ashmem_shrink_scan, - /* - * XXX (dchinner): I wish people would comment on why they need on - * significant changes to the default value here - */ - .seeks = DEFAULT_SEEKS * 4, -}; - -static int set_prot_mask(struct ashmem_area *asma, unsigned long prot) -{ - int ret = 0; - - mutex_lock(&ashmem_mutex); - - /* the user can only remove, not add, protection bits */ - if ((asma->prot_mask & prot) != prot) { - ret = -EINVAL; - goto out; - } - - /* does the application expect PROT_READ to imply PROT_EXEC? */ - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC)) - prot |= PROT_EXEC; - - asma->prot_mask = prot; - -out: - mutex_unlock(&ashmem_mutex); - return ret; -} - -static int set_name(struct ashmem_area *asma, void __user *name) -{ - int len; - int ret = 0; - char local_name[ASHMEM_NAME_LEN]; - - /* - * Holding the ashmem_mutex while doing a copy_from_user might cause - * an data abort which would try to access mmap_lock. If another - * thread has invoked ashmem_mmap then it will be holding the - * semaphore and will be waiting for ashmem_mutex, there by leading to - * deadlock. We'll release the mutex and take the name to a local - * variable that does not need protection and later copy the local - * variable to the structure member with lock held. - */ - len = strncpy_from_user(local_name, name, ASHMEM_NAME_LEN); - if (len < 0) - return len; - - mutex_lock(&ashmem_mutex); - /* cannot change an existing mapping's name */ - if (asma->file) - ret = -EINVAL; - else - strscpy(asma->name + ASHMEM_NAME_PREFIX_LEN, local_name, - ASHMEM_NAME_LEN); - - mutex_unlock(&ashmem_mutex); - return ret; -} - -static int get_name(struct ashmem_area *asma, void __user *name) -{ - int ret = 0; - size_t len; - /* - * Have a local variable to which we'll copy the content - * from asma with the lock held. Later we can copy this to the user - * space safely without holding any locks. So even if we proceed to - * wait for mmap_lock, it won't lead to deadlock. - */ - char local_name[ASHMEM_NAME_LEN]; - - mutex_lock(&ashmem_mutex); - if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0') { - /* - * Copying only `len', instead of ASHMEM_NAME_LEN, bytes - * prevents us from revealing one user's stack to another. - */ - len = strlen(asma->name + ASHMEM_NAME_PREFIX_LEN) + 1; - memcpy(local_name, asma->name + ASHMEM_NAME_PREFIX_LEN, len); - } else { - len = sizeof(ASHMEM_NAME_DEF); - memcpy(local_name, ASHMEM_NAME_DEF, len); - } - mutex_unlock(&ashmem_mutex); - - /* - * Now we are just copying from the stack variable to userland - * No lock held - */ - if (copy_to_user(name, local_name, len)) - ret = -EFAULT; - return ret; -} - -/* - * ashmem_pin - pin the given ashmem region, returning whether it was - * previously purged (ASHMEM_WAS_PURGED) or not (ASHMEM_NOT_PURGED). - * - * Caller must hold ashmem_mutex. - */ -static int ashmem_pin(struct ashmem_area *asma, size_t pgstart, size_t pgend, - struct ashmem_range **new_range) -{ - struct ashmem_range *range, *next; - int ret = ASHMEM_NOT_PURGED; - - list_for_each_entry_safe(range, next, &asma->unpinned_list, unpinned) { - /* moved past last applicable page; we can short circuit */ - if (range_before_page(range, pgstart)) - break; - - /* - * The user can ask us to pin pages that span multiple ranges, - * or to pin pages that aren't even unpinned, so this is messy. - * - * Four cases: - * 1. The requested range subsumes an existing range, so we - * just remove the entire matching range. - * 2. The requested range overlaps the start of an existing - * range, so we just update that range. - * 3. The requested range overlaps the end of an existing - * range, so we just update that range. - * 4. The requested range punches a hole in an existing range, - * so we have to update one side of the range and then - * create a new range for the other side. - */ - if (page_range_in_range(range, pgstart, pgend)) { - ret |= range->purged; - - /* Case #1: Easy. Just nuke the whole thing. */ - if (page_range_subsumes_range(range, pgstart, pgend)) { - range_del(range); - continue; - } - - /* Case #2: We overlap from the start, so adjust it */ - if (range->pgstart >= pgstart) { - range_shrink(range, pgend + 1, range->pgend); - continue; - } - - /* Case #3: We overlap from the rear, so adjust it */ - if (range->pgend <= pgend) { - range_shrink(range, range->pgstart, - pgstart - 1); - continue; - } - - /* - * Case #4: We eat a chunk out of the middle. A bit - * more complicated, we allocate a new range for the - * second half and adjust the first chunk's endpoint. - */ - range_alloc(asma, range, range->purged, - pgend + 1, range->pgend, new_range); - range_shrink(range, range->pgstart, pgstart - 1); - break; - } - } - - return ret; -} - -/* - * ashmem_unpin - unpin the given range of pages. Returns zero on success. - * - * Caller must hold ashmem_mutex. - */ -static int ashmem_unpin(struct ashmem_area *asma, size_t pgstart, size_t pgend, - struct ashmem_range **new_range) -{ - struct ashmem_range *range, *next; - unsigned int purged = ASHMEM_NOT_PURGED; - -restart: - list_for_each_entry_safe(range, next, &asma->unpinned_list, unpinned) { - /* short circuit: this is our insertion point */ - if (range_before_page(range, pgstart)) - break; - - /* - * The user can ask us to unpin pages that are already entirely - * or partially pinned. We handle those two cases here. - */ - if (page_range_subsumed_by_range(range, pgstart, pgend)) - return 0; - if (page_range_in_range(range, pgstart, pgend)) { - pgstart = min(range->pgstart, pgstart); - pgend = max(range->pgend, pgend); - purged |= range->purged; - range_del(range); - goto restart; - } - } - - range_alloc(asma, range, purged, pgstart, pgend, new_range); - return 0; -} - -/* - * ashmem_get_pin_status - Returns ASHMEM_IS_UNPINNED if _any_ pages in the - * given interval are unpinned and ASHMEM_IS_PINNED otherwise. - * - * Caller must hold ashmem_mutex. - */ -static int ashmem_get_pin_status(struct ashmem_area *asma, size_t pgstart, - size_t pgend) -{ - struct ashmem_range *range; - int ret = ASHMEM_IS_PINNED; - - list_for_each_entry(range, &asma->unpinned_list, unpinned) { - if (range_before_page(range, pgstart)) - break; - if (page_range_in_range(range, pgstart, pgend)) { - ret = ASHMEM_IS_UNPINNED; - break; - } - } - - return ret; -} - -static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd, - void __user *p) -{ - struct ashmem_pin pin; - size_t pgstart, pgend; - int ret = -EINVAL; - struct ashmem_range *range = NULL; - - if (copy_from_user(&pin, p, sizeof(pin))) - return -EFAULT; - - if (cmd == ASHMEM_PIN || cmd == ASHMEM_UNPIN) { - range = kmem_cache_zalloc(ashmem_range_cachep, GFP_KERNEL); - if (!range) - return -ENOMEM; - } - - mutex_lock(&ashmem_mutex); - wait_event(ashmem_shrink_wait, !atomic_read(&ashmem_shrink_inflight)); - - if (!asma->file) - goto out_unlock; - - /* per custom, you can pass zero for len to mean "everything onward" */ - if (!pin.len) - pin.len = PAGE_ALIGN(asma->size) - pin.offset; - - if ((pin.offset | pin.len) & ~PAGE_MASK) - goto out_unlock; - - if (((__u32)-1) - pin.offset < pin.len) - goto out_unlock; - - if (PAGE_ALIGN(asma->size) < pin.offset + pin.len) - goto out_unlock; - - pgstart = pin.offset / PAGE_SIZE; - pgend = pgstart + (pin.len / PAGE_SIZE) - 1; - - switch (cmd) { - case ASHMEM_PIN: - ret = ashmem_pin(asma, pgstart, pgend, &range); - break; - case ASHMEM_UNPIN: - ret = ashmem_unpin(asma, pgstart, pgend, &range); - break; - case ASHMEM_GET_PIN_STATUS: - ret = ashmem_get_pin_status(asma, pgstart, pgend); - break; - } - -out_unlock: - mutex_unlock(&ashmem_mutex); - if (range) - kmem_cache_free(ashmem_range_cachep, range); - - return ret; -} - -static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - struct ashmem_area *asma = file->private_data; - long ret = -ENOTTY; - - switch (cmd) { - case ASHMEM_SET_NAME: - ret = set_name(asma, (void __user *)arg); - break; - case ASHMEM_GET_NAME: - ret = get_name(asma, (void __user *)arg); - break; - case ASHMEM_SET_SIZE: - ret = -EINVAL; - mutex_lock(&ashmem_mutex); - if (!asma->file) { - ret = 0; - asma->size = (size_t)arg; - } - mutex_unlock(&ashmem_mutex); - break; - case ASHMEM_GET_SIZE: - ret = asma->size; - break; - case ASHMEM_SET_PROT_MASK: - ret = set_prot_mask(asma, arg); - break; - case ASHMEM_GET_PROT_MASK: - ret = asma->prot_mask; - break; - case ASHMEM_PIN: - case ASHMEM_UNPIN: - case ASHMEM_GET_PIN_STATUS: - ret = ashmem_pin_unpin(asma, cmd, (void __user *)arg); - break; - case ASHMEM_PURGE_ALL_CACHES: - ret = -EPERM; - if (capable(CAP_SYS_ADMIN)) { - struct shrink_control sc = { - .gfp_mask = GFP_KERNEL, - .nr_to_scan = LONG_MAX, - }; - ret = ashmem_shrink_count(&ashmem_shrinker, &sc); - ashmem_shrink_scan(&ashmem_shrinker, &sc); - } - break; - } - - return ret; -} - -/* support of 32bit userspace on 64bit platforms */ -#ifdef CONFIG_COMPAT -static long compat_ashmem_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - switch (cmd) { - case COMPAT_ASHMEM_SET_SIZE: - cmd = ASHMEM_SET_SIZE; - break; - case COMPAT_ASHMEM_SET_PROT_MASK: - cmd = ASHMEM_SET_PROT_MASK; - break; - } - return ashmem_ioctl(file, cmd, arg); -} -#endif -#ifdef CONFIG_PROC_FS -static void ashmem_show_fdinfo(struct seq_file *m, struct file *file) -{ - struct ashmem_area *asma = file->private_data; - - mutex_lock(&ashmem_mutex); - - if (asma->file) - seq_printf(m, "inode:\t%ld\n", file_inode(asma->file)->i_ino); - - if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0') - seq_printf(m, "name:\t%s\n", - asma->name + ASHMEM_NAME_PREFIX_LEN); - - seq_printf(m, "size:\t%zu\n", asma->size); - - mutex_unlock(&ashmem_mutex); -} -#endif -static const struct file_operations ashmem_fops = { - .owner = THIS_MODULE, - .open = ashmem_open, - .release = ashmem_release, - .read_iter = ashmem_read_iter, - .llseek = ashmem_llseek, - .mmap = ashmem_mmap, - .unlocked_ioctl = ashmem_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = compat_ashmem_ioctl, -#endif -#ifdef CONFIG_PROC_FS - .show_fdinfo = ashmem_show_fdinfo, -#endif -}; - -static struct miscdevice ashmem_misc = { - .minor = MISC_DYNAMIC_MINOR, - .name = "ashmem", - .fops = &ashmem_fops, -}; - -static int __init ashmem_init(void) -{ - int ret = -ENOMEM; - - ashmem_area_cachep = kmem_cache_create("ashmem_area_cache", - sizeof(struct ashmem_area), - 0, 0, NULL); - if (!ashmem_area_cachep) { - pr_err("failed to create slab cache\n"); - goto out; - } - - ashmem_range_cachep = kmem_cache_create("ashmem_range_cache", - sizeof(struct ashmem_range), - 0, SLAB_RECLAIM_ACCOUNT, NULL); - if (!ashmem_range_cachep) { - pr_err("failed to create slab cache\n"); - goto out_free1; - } - - ret = misc_register(&ashmem_misc); - if (ret) { - pr_err("failed to register misc device!\n"); - goto out_free2; - } - - ret = register_shrinker(&ashmem_shrinker); - if (ret) { - pr_err("failed to register shrinker!\n"); - goto out_demisc; - } - - pr_info("initialized\n"); - - return 0; - -out_demisc: - misc_deregister(&ashmem_misc); -out_free2: - kmem_cache_destroy(ashmem_range_cachep); -out_free1: - kmem_cache_destroy(ashmem_area_cachep); -out: - return ret; -} -device_initcall(ashmem_init); diff --git a/drivers/staging/android/ashmem.h b/drivers/staging/android/ashmem.h deleted file mode 100644 index 1a478173cd21..000000000000 --- a/drivers/staging/android/ashmem.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 OR Apache-2.0 */ -/* - * include/linux/ashmem.h - * - * Copyright 2008 Google Inc. - * Author: Robert Love - */ - -#ifndef _LINUX_ASHMEM_H -#define _LINUX_ASHMEM_H - -#include <linux/limits.h> -#include <linux/ioctl.h> -#include <linux/compat.h> - -#include "uapi/ashmem.h" - -/* support of 32bit userspace on 64bit platforms */ -#ifdef CONFIG_COMPAT -#define COMPAT_ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, compat_size_t) -#define COMPAT_ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned int) -#endif - -#endif /* _LINUX_ASHMEM_H */ diff --git a/drivers/staging/android/uapi/ashmem.h b/drivers/staging/android/uapi/ashmem.h deleted file mode 100644 index 134efacb3219..000000000000 --- a/drivers/staging/android/uapi/ashmem.h +++ /dev/null @@ -1,43 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 OR Apache-2.0 */ -/* - * Copyright 2008 Google Inc. - * Author: Robert Love - */ - -#ifndef _UAPI_LINUX_ASHMEM_H -#define _UAPI_LINUX_ASHMEM_H - -#include <linux/ioctl.h> -#include <linux/types.h> - -#define ASHMEM_NAME_LEN 256 - -#define ASHMEM_NAME_DEF "dev/ashmem" - -/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ -#define ASHMEM_NOT_PURGED 0 -#define ASHMEM_WAS_PURGED 1 - -/* Return values from ASHMEM_GET_PIN_STATUS: Is the mapping pinned? */ -#define ASHMEM_IS_UNPINNED 0 -#define ASHMEM_IS_PINNED 1 - -struct ashmem_pin { - __u32 offset; /* offset into region, in bytes, page-aligned */ - __u32 len; /* length forward from offset, in bytes, page-aligned */ -}; - -#define __ASHMEMIOC 0x77 - -#define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) -#define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) -#define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) -#define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) -#define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) -#define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) -#define ASHMEM_PIN _IOW(__ASHMEMIOC, 7, struct ashmem_pin) -#define ASHMEM_UNPIN _IOW(__ASHMEMIOC, 8, struct ashmem_pin) -#define ASHMEM_GET_PIN_STATUS _IO(__ASHMEMIOC, 9) -#define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) - -#endif /* _UAPI_LINUX_ASHMEM_H */ diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c index 632f140dddbc..dfd2b357f484 100644 --- a/drivers/staging/axis-fifo/axis-fifo.c +++ b/drivers/staging/axis-fifo/axis-fifo.c @@ -809,7 +809,6 @@ end: static int axis_fifo_probe(struct platform_device *pdev) { - struct resource *r_irq; /* interrupt resources */ struct resource *r_mem; /* IO mem resources */ struct device *dev = &pdev->dev; /* OS device (from device tree) */ struct axis_fifo *fifo = NULL; @@ -882,16 +881,12 @@ static int axis_fifo_probe(struct platform_device *pdev) */ /* get IRQ resource */ - r_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (!r_irq) { - dev_err(fifo->dt_device, "no IRQ found for 0x%pa\n", - &r_mem->start); - rc = -EIO; + rc = platform_get_irq(pdev, 0); + if (rc < 0) goto err_initial; - } /* request IRQ */ - fifo->irq = r_irq->start; + fifo->irq = rc; rc = devm_request_irq(fifo->dt_device, fifo->irq, &axis_fifo_irq, 0, DRIVER_NAME, fifo); if (rc) { diff --git a/drivers/staging/clocking-wizard/Kconfig b/drivers/staging/clocking-wizard/Kconfig deleted file mode 100644 index 2324b5d73788..000000000000 --- a/drivers/staging/clocking-wizard/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Xilinx Clocking Wizard Driver -# - -config COMMON_CLK_XLNX_CLKWZRD - tristate "Xilinx Clocking Wizard" - depends on COMMON_CLK && OF && HAS_IOMEM - help - Support for the Xilinx Clocking Wizard IP core clock generator. diff --git a/drivers/staging/clocking-wizard/Makefile b/drivers/staging/clocking-wizard/Makefile deleted file mode 100644 index b1f915224d96..000000000000 --- a/drivers/staging/clocking-wizard/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clk-xlnx-clock-wizard.o diff --git a/drivers/staging/clocking-wizard/TODO b/drivers/staging/clocking-wizard/TODO deleted file mode 100644 index c7e1dc58dfba..000000000000 --- a/drivers/staging/clocking-wizard/TODO +++ /dev/null @@ -1,13 +0,0 @@ -TODO: - - support for fractional multiplier - - support for fractional divider (output 0 only) - - support for set_rate() operations (may benefit from Stephen Boyd's - refactoring of the clk primitives: - https://lore.kernel.org/lkml/1409957256-23729-1-git-send-email-sboyd@codeaurora.org) - - review arithmetic - - overflow after multiplication? - - maximize accuracy before divisions - -Patches to: - Greg Kroah-Hartman <gregkh@linuxfoundation.org> - Sören Brinkmann <soren.brinkmann@xilinx.com> diff --git a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c deleted file mode 100644 index 39367712ef54..000000000000 --- a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c +++ /dev/null @@ -1,634 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Xilinx 'Clocking Wizard' driver - * - * Copyright (C) 2013 - 2014 Xilinx - * - * Sören Brinkmann <soren.brinkmann@xilinx.com> - */ - -#include <linux/platform_device.h> -#include <linux/clk.h> -#include <linux/clk-provider.h> -#include <linux/slab.h> -#include <linux/io.h> -#include <linux/of.h> -#include <linux/module.h> -#include <linux/err.h> -#include <linux/iopoll.h> - -#define WZRD_NUM_OUTPUTS 7 -#define WZRD_ACLK_MAX_FREQ 250000000UL - -#define WZRD_CLK_CFG_REG(n) (0x200 + 4 * (n)) - -#define WZRD_CLKOUT0_FRAC_EN BIT(18) -#define WZRD_CLKFBOUT_FRAC_EN BIT(26) - -#define WZRD_CLKFBOUT_MULT_SHIFT 8 -#define WZRD_CLKFBOUT_MULT_MASK (0xff << WZRD_CLKFBOUT_MULT_SHIFT) -#define WZRD_CLKFBOUT_FRAC_SHIFT 16 -#define WZRD_CLKFBOUT_FRAC_MASK (0x3ff << WZRD_CLKFBOUT_FRAC_SHIFT) -#define WZRD_DIVCLK_DIVIDE_SHIFT 0 -#define WZRD_DIVCLK_DIVIDE_MASK (0xff << WZRD_DIVCLK_DIVIDE_SHIFT) -#define WZRD_CLKOUT_DIVIDE_SHIFT 0 -#define WZRD_CLKOUT_DIVIDE_WIDTH 8 -#define WZRD_CLKOUT_DIVIDE_MASK (0xff << WZRD_DIVCLK_DIVIDE_SHIFT) -#define WZRD_CLKOUT_FRAC_SHIFT 8 -#define WZRD_CLKOUT_FRAC_MASK 0x3ff - -#define WZRD_DR_MAX_INT_DIV_VALUE 255 -#define WZRD_DR_STATUS_REG_OFFSET 0x04 -#define WZRD_DR_LOCK_BIT_MASK 0x00000001 -#define WZRD_DR_INIT_REG_OFFSET 0x25C -#define WZRD_DR_DIV_TO_PHASE_OFFSET 4 -#define WZRD_DR_BEGIN_DYNA_RECONF 0x03 - -#define WZRD_USEC_POLL 10 -#define WZRD_TIMEOUT_POLL 1000 -/* Get the mask from width */ -#define div_mask(width) ((1 << (width)) - 1) - -/* Extract divider instance from clock hardware instance */ -#define to_clk_wzrd_divider(_hw) container_of(_hw, struct clk_wzrd_divider, hw) - -enum clk_wzrd_int_clks { - wzrd_clk_mul, - wzrd_clk_mul_div, - wzrd_clk_mul_frac, - wzrd_clk_int_max -}; - -/** - * struct clk_wzrd - Clock wizard private data structure - * - * @clk_data: Clock data - * @nb: Notifier block - * @base: Memory base - * @clk_in1: Handle to input clock 'clk_in1' - * @axi_clk: Handle to input clock 's_axi_aclk' - * @clks_internal: Internal clocks - * @clkout: Output clocks - * @speed_grade: Speed grade of the device - * @suspended: Flag indicating power state of the device - */ -struct clk_wzrd { - struct clk_onecell_data clk_data; - struct notifier_block nb; - void __iomem *base; - struct clk *clk_in1; - struct clk *axi_clk; - struct clk *clks_internal[wzrd_clk_int_max]; - struct clk *clkout[WZRD_NUM_OUTPUTS]; - unsigned int speed_grade; - bool suspended; -}; - -/** - * struct clk_wzrd_divider - clock divider specific to clk_wzrd - * - * @hw: handle between common and hardware-specific interfaces - * @base: base address of register containing the divider - * @offset: offset address of register containing the divider - * @shift: shift to the divider bit field - * @width: width of the divider bit field - * @flags: clk_wzrd divider flags - * @table: array of value/divider pairs, last entry should have div = 0 - * @lock: register lock - */ -struct clk_wzrd_divider { - struct clk_hw hw; - void __iomem *base; - u16 offset; - u8 shift; - u8 width; - u8 flags; - const struct clk_div_table *table; - spinlock_t *lock; /* divider lock */ -}; - -#define to_clk_wzrd(_nb) container_of(_nb, struct clk_wzrd, nb) - -/* maximum frequencies for input/output clocks per speed grade */ -static const unsigned long clk_wzrd_max_freq[] = { - 800000000UL, - 933000000UL, - 1066000000UL -}; - -/* spin lock variable for clk_wzrd */ -static DEFINE_SPINLOCK(clkwzrd_lock); - -static unsigned long clk_wzrd_recalc_rate(struct clk_hw *hw, - unsigned long parent_rate) -{ - struct clk_wzrd_divider *divider = to_clk_wzrd_divider(hw); - void __iomem *div_addr = divider->base + divider->offset; - unsigned int val; - - val = readl(div_addr) >> divider->shift; - val &= div_mask(divider->width); - - return divider_recalc_rate(hw, parent_rate, val, divider->table, - divider->flags, divider->width); -} - -static int clk_wzrd_dynamic_reconfig(struct clk_hw *hw, unsigned long rate, - unsigned long parent_rate) -{ - int err; - u32 value; - unsigned long flags = 0; - struct clk_wzrd_divider *divider = to_clk_wzrd_divider(hw); - void __iomem *div_addr = divider->base + divider->offset; - - if (divider->lock) - spin_lock_irqsave(divider->lock, flags); - else - __acquire(divider->lock); - - value = DIV_ROUND_CLOSEST(parent_rate, rate); - - /* Cap the value to max */ - min_t(u32, value, WZRD_DR_MAX_INT_DIV_VALUE); - - /* Set divisor and clear phase offset */ - writel(value, div_addr); - writel(0x00, div_addr + WZRD_DR_DIV_TO_PHASE_OFFSET); - - /* Check status register */ - err = readl_poll_timeout(divider->base + WZRD_DR_STATUS_REG_OFFSET, - value, value & WZRD_DR_LOCK_BIT_MASK, - WZRD_USEC_POLL, WZRD_TIMEOUT_POLL); - if (err) - goto err_reconfig; - - /* Initiate reconfiguration */ - writel(WZRD_DR_BEGIN_DYNA_RECONF, - divider->base + WZRD_DR_INIT_REG_OFFSET); - - /* Check status register */ - err = readl_poll_timeout(divider->base + WZRD_DR_STATUS_REG_OFFSET, - value, value & WZRD_DR_LOCK_BIT_MASK, - WZRD_USEC_POLL, WZRD_TIMEOUT_POLL); -err_reconfig: - if (divider->lock) - spin_unlock_irqrestore(divider->lock, flags); - else - __release(divider->lock); - return err; -} - -static long clk_wzrd_round_rate(struct clk_hw *hw, unsigned long rate, - unsigned long *prate) -{ - u8 div; - - /* - * since we don't change parent rate we just round rate to closest - * achievable - */ - div = DIV_ROUND_CLOSEST(*prate, rate); - - return *prate / div; -} - -static const struct clk_ops clk_wzrd_clk_divider_ops = { - .round_rate = clk_wzrd_round_rate, - .set_rate = clk_wzrd_dynamic_reconfig, - .recalc_rate = clk_wzrd_recalc_rate, -}; - -static unsigned long clk_wzrd_recalc_ratef(struct clk_hw *hw, - unsigned long parent_rate) -{ - unsigned int val; - u32 div, frac; - struct clk_wzrd_divider *divider = to_clk_wzrd_divider(hw); - void __iomem *div_addr = divider->base + divider->offset; - - val = readl(div_addr); - div = val & div_mask(divider->width); - frac = (val >> WZRD_CLKOUT_FRAC_SHIFT) & WZRD_CLKOUT_FRAC_MASK; - - return mult_frac(parent_rate, 1000, (div * 1000) + frac); -} - -static int clk_wzrd_dynamic_reconfig_f(struct clk_hw *hw, unsigned long rate, - unsigned long parent_rate) -{ - int err; - u32 value, pre; - unsigned long rate_div, f, clockout0_div; - struct clk_wzrd_divider *divider = to_clk_wzrd_divider(hw); - void __iomem *div_addr = divider->base + divider->offset; - - rate_div = ((parent_rate * 1000) / rate); - clockout0_div = rate_div / 1000; - - pre = DIV_ROUND_CLOSEST((parent_rate * 1000), rate); - f = (u32)(pre - (clockout0_div * 1000)); - f = f & WZRD_CLKOUT_FRAC_MASK; - f = f << WZRD_CLKOUT_DIVIDE_WIDTH; - - value = (f | (clockout0_div & WZRD_CLKOUT_DIVIDE_MASK)); - - /* Set divisor and clear phase offset */ - writel(value, div_addr); - writel(0x0, div_addr + WZRD_DR_DIV_TO_PHASE_OFFSET); - - /* Check status register */ - err = readl_poll_timeout(divider->base + WZRD_DR_STATUS_REG_OFFSET, value, - value & WZRD_DR_LOCK_BIT_MASK, - WZRD_USEC_POLL, WZRD_TIMEOUT_POLL); - if (err) - return err; - - /* Initiate reconfiguration */ - writel(WZRD_DR_BEGIN_DYNA_RECONF, - divider->base + WZRD_DR_INIT_REG_OFFSET); - - /* Check status register */ - return readl_poll_timeout(divider->base + WZRD_DR_STATUS_REG_OFFSET, value, - value & WZRD_DR_LOCK_BIT_MASK, - WZRD_USEC_POLL, WZRD_TIMEOUT_POLL); -} - -static long clk_wzrd_round_rate_f(struct clk_hw *hw, unsigned long rate, - unsigned long *prate) -{ - return rate; -} - -static const struct clk_ops clk_wzrd_clk_divider_ops_f = { - .round_rate = clk_wzrd_round_rate_f, - .set_rate = clk_wzrd_dynamic_reconfig_f, - .recalc_rate = clk_wzrd_recalc_ratef, -}; - -static struct clk *clk_wzrd_register_divf(struct device *dev, - const char *name, - const char *parent_name, - unsigned long flags, - void __iomem *base, u16 offset, - u8 shift, u8 width, - u8 clk_divider_flags, - const struct clk_div_table *table, - spinlock_t *lock) -{ - struct clk_wzrd_divider *div; - struct clk_hw *hw; - struct clk_init_data init; - int ret; - - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); - if (!div) - return ERR_PTR(-ENOMEM); - - init.name = name; - - init.ops = &clk_wzrd_clk_divider_ops_f; - - init.flags = flags; - init.parent_names = &parent_name; - init.num_parents = 1; - - div->base = base; - div->offset = offset; - div->shift = shift; - div->width = width; - div->flags = clk_divider_flags; - div->lock = lock; - div->hw.init = &init; - div->table = table; - - hw = &div->hw; - ret = devm_clk_hw_register(dev, hw); - if (ret) - return ERR_PTR(ret); - - return hw->clk; -} - -static struct clk *clk_wzrd_register_divider(struct device *dev, - const char *name, - const char *parent_name, - unsigned long flags, - void __iomem *base, u16 offset, - u8 shift, u8 width, - u8 clk_divider_flags, - const struct clk_div_table *table, - spinlock_t *lock) -{ - struct clk_wzrd_divider *div; - struct clk_hw *hw; - struct clk_init_data init; - int ret; - - div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL); - if (!div) - return ERR_PTR(-ENOMEM); - - init.name = name; - init.ops = &clk_wzrd_clk_divider_ops; - init.flags = flags; - init.parent_names = &parent_name; - init.num_parents = 1; - - div->base = base; - div->offset = offset; - div->shift = shift; - div->width = width; - div->flags = clk_divider_flags; - div->lock = lock; - div->hw.init = &init; - div->table = table; - - hw = &div->hw; - ret = devm_clk_hw_register(dev, hw); - if (ret) - hw = ERR_PTR(ret); - - return hw->clk; -} - -static int clk_wzrd_clk_notifier(struct notifier_block *nb, unsigned long event, - void *data) -{ - unsigned long max; - struct clk_notifier_data *ndata = data; - struct clk_wzrd *clk_wzrd = to_clk_wzrd(nb); - - if (clk_wzrd->suspended) - return NOTIFY_OK; - - if (ndata->clk == clk_wzrd->clk_in1) - max = clk_wzrd_max_freq[clk_wzrd->speed_grade - 1]; - else if (ndata->clk == clk_wzrd->axi_clk) - max = WZRD_ACLK_MAX_FREQ; - else - return NOTIFY_DONE; /* should never happen */ - - switch (event) { - case PRE_RATE_CHANGE: - if (ndata->new_rate > max) - return NOTIFY_BAD; - return NOTIFY_OK; - case POST_RATE_CHANGE: - case ABORT_RATE_CHANGE: - default: - return NOTIFY_DONE; - } -} - -static int __maybe_unused clk_wzrd_suspend(struct device *dev) -{ - struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev); - - clk_disable_unprepare(clk_wzrd->axi_clk); - clk_wzrd->suspended = true; - - return 0; -} - -static int __maybe_unused clk_wzrd_resume(struct device *dev) -{ - int ret; - struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev); - - ret = clk_prepare_enable(clk_wzrd->axi_clk); - if (ret) { - dev_err(dev, "unable to enable s_axi_aclk\n"); - return ret; - } - - clk_wzrd->suspended = false; - - return 0; -} - -static SIMPLE_DEV_PM_OPS(clk_wzrd_dev_pm_ops, clk_wzrd_suspend, - clk_wzrd_resume); - -static int clk_wzrd_probe(struct platform_device *pdev) -{ - int i, ret; - u32 reg, reg_f, mult; - unsigned long rate; - const char *clk_name; - void __iomem *ctrl_reg; - struct clk_wzrd *clk_wzrd; - struct device_node *np = pdev->dev.of_node; - int nr_outputs; - unsigned long flags = 0; - - clk_wzrd = devm_kzalloc(&pdev->dev, sizeof(*clk_wzrd), GFP_KERNEL); - if (!clk_wzrd) - return -ENOMEM; - platform_set_drvdata(pdev, clk_wzrd); - - clk_wzrd->base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(clk_wzrd->base)) - return PTR_ERR(clk_wzrd->base); - - ret = of_property_read_u32(np, "xlnx,speed-grade", &clk_wzrd->speed_grade); - if (!ret) { - if (clk_wzrd->speed_grade < 1 || clk_wzrd->speed_grade > 3) { - dev_warn(&pdev->dev, "invalid speed grade '%d'\n", - clk_wzrd->speed_grade); - clk_wzrd->speed_grade = 0; - } - } - - clk_wzrd->clk_in1 = devm_clk_get(&pdev->dev, "clk_in1"); - if (IS_ERR(clk_wzrd->clk_in1)) { - if (clk_wzrd->clk_in1 != ERR_PTR(-EPROBE_DEFER)) - dev_err(&pdev->dev, "clk_in1 not found\n"); - return PTR_ERR(clk_wzrd->clk_in1); - } - - clk_wzrd->axi_clk = devm_clk_get(&pdev->dev, "s_axi_aclk"); - if (IS_ERR(clk_wzrd->axi_clk)) { - if (clk_wzrd->axi_clk != ERR_PTR(-EPROBE_DEFER)) - dev_err(&pdev->dev, "s_axi_aclk not found\n"); - return PTR_ERR(clk_wzrd->axi_clk); - } - ret = clk_prepare_enable(clk_wzrd->axi_clk); - if (ret) { - dev_err(&pdev->dev, "enabling s_axi_aclk failed\n"); - return ret; - } - rate = clk_get_rate(clk_wzrd->axi_clk); - if (rate > WZRD_ACLK_MAX_FREQ) { - dev_err(&pdev->dev, "s_axi_aclk frequency (%lu) too high\n", - rate); - ret = -EINVAL; - goto err_disable_clk; - } - - reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)); - reg_f = reg & WZRD_CLKFBOUT_FRAC_MASK; - reg_f = reg_f >> WZRD_CLKFBOUT_FRAC_SHIFT; - - reg = reg & WZRD_CLKFBOUT_MULT_MASK; - reg = reg >> WZRD_CLKFBOUT_MULT_SHIFT; - mult = (reg * 1000) + reg_f; - clk_name = kasprintf(GFP_KERNEL, "%s_mul", dev_name(&pdev->dev)); - if (!clk_name) { - ret = -ENOMEM; - goto err_disable_clk; - } - - ret = of_property_read_u32(np, "nr-outputs", &nr_outputs); - if (ret || nr_outputs > WZRD_NUM_OUTPUTS) { - ret = -EINVAL; - goto err_disable_clk; - } - if (nr_outputs == 1) - flags = CLK_SET_RATE_PARENT; - - clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor - (&pdev->dev, clk_name, - __clk_get_name(clk_wzrd->clk_in1), - 0, mult, 1000); - if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul])) { - dev_err(&pdev->dev, "unable to register fixed-factor clock\n"); - ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul]); - goto err_disable_clk; - } - - clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(&pdev->dev)); - if (!clk_name) { - ret = -ENOMEM; - goto err_rm_int_clk; - } - - ctrl_reg = clk_wzrd->base + WZRD_CLK_CFG_REG(0); - /* register div */ - clk_wzrd->clks_internal[wzrd_clk_mul_div] = clk_register_divider - (&pdev->dev, clk_name, - __clk_get_name(clk_wzrd->clks_internal[wzrd_clk_mul]), - flags, ctrl_reg, 0, 8, CLK_DIVIDER_ONE_BASED | - CLK_DIVIDER_ALLOW_ZERO, &clkwzrd_lock); - if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div])) { - dev_err(&pdev->dev, "unable to register divider clock\n"); - ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div]); - goto err_rm_int_clk; - } - - /* register div per output */ - for (i = nr_outputs - 1; i >= 0 ; i--) { - const char *clkout_name; - - clkout_name = kasprintf(GFP_KERNEL, "%s_out%d", dev_name(&pdev->dev), i); - if (!clkout_name) { - ret = -ENOMEM; - goto err_rm_int_clk; - } - - if (!i) - clk_wzrd->clkout[i] = clk_wzrd_register_divf - (&pdev->dev, clkout_name, - clk_name, flags, - clk_wzrd->base, (WZRD_CLK_CFG_REG(2) + i * 12), - WZRD_CLKOUT_DIVIDE_SHIFT, - WZRD_CLKOUT_DIVIDE_WIDTH, - CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, - NULL, &clkwzrd_lock); - else - clk_wzrd->clkout[i] = clk_wzrd_register_divider - (&pdev->dev, clkout_name, - clk_name, 0, - clk_wzrd->base, (WZRD_CLK_CFG_REG(2) + i * 12), - WZRD_CLKOUT_DIVIDE_SHIFT, - WZRD_CLKOUT_DIVIDE_WIDTH, - CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO, - NULL, &clkwzrd_lock); - if (IS_ERR(clk_wzrd->clkout[i])) { - int j; - - for (j = i + 1; j < nr_outputs; j++) - clk_unregister(clk_wzrd->clkout[j]); - dev_err(&pdev->dev, - "unable to register divider clock\n"); - ret = PTR_ERR(clk_wzrd->clkout[i]); - goto err_rm_int_clks; - } - } - - kfree(clk_name); - - clk_wzrd->clk_data.clks = clk_wzrd->clkout; - clk_wzrd->clk_data.clk_num = ARRAY_SIZE(clk_wzrd->clkout); - of_clk_add_provider(np, of_clk_src_onecell_get, &clk_wzrd->clk_data); - - if (clk_wzrd->speed_grade) { - clk_wzrd->nb.notifier_call = clk_wzrd_clk_notifier; - - ret = clk_notifier_register(clk_wzrd->clk_in1, - &clk_wzrd->nb); - if (ret) - dev_warn(&pdev->dev, - "unable to register clock notifier\n"); - - ret = clk_notifier_register(clk_wzrd->axi_clk, &clk_wzrd->nb); - if (ret) - dev_warn(&pdev->dev, - "unable to register clock notifier\n"); - } - - return 0; - -err_rm_int_clks: - clk_unregister(clk_wzrd->clks_internal[1]); -err_rm_int_clk: - kfree(clk_name); - clk_unregister(clk_wzrd->clks_internal[0]); -err_disable_clk: - clk_disable_unprepare(clk_wzrd->axi_clk); - - return ret; -} - -static int clk_wzrd_remove(struct platform_device *pdev) -{ - int i; - struct clk_wzrd *clk_wzrd = platform_get_drvdata(pdev); - - of_clk_del_provider(pdev->dev.of_node); - - for (i = 0; i < WZRD_NUM_OUTPUTS; i++) - clk_unregister(clk_wzrd->clkout[i]); - for (i = 0; i < wzrd_clk_int_max; i++) - clk_unregister(clk_wzrd->clks_internal[i]); - - if (clk_wzrd->speed_grade) { - clk_notifier_unregister(clk_wzrd->axi_clk, &clk_wzrd->nb); - clk_notifier_unregister(clk_wzrd->clk_in1, &clk_wzrd->nb); - } - - clk_disable_unprepare(clk_wzrd->axi_clk); - - return 0; -} - -static const struct of_device_id clk_wzrd_ids[] = { - { .compatible = "xlnx,clocking-wizard" }, - { }, -}; -MODULE_DEVICE_TABLE(of, clk_wzrd_ids); - -static struct platform_driver clk_wzrd_driver = { - .driver = { - .name = "clk-wizard", - .of_match_table = clk_wzrd_ids, - .pm = &clk_wzrd_dev_pm_ops, - }, - .probe = clk_wzrd_probe, - .remove = clk_wzrd_remove, -}; -module_platform_driver(clk_wzrd_driver); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Soeren Brinkmann <soren.brinkmann@xilinx.com"); -MODULE_DESCRIPTION("Driver for the Xilinx Clocking Wizard IP core"); diff --git a/drivers/staging/clocking-wizard/dt-binding.txt b/drivers/staging/clocking-wizard/dt-binding.txt deleted file mode 100644 index efb67ff9f76c..000000000000 --- a/drivers/staging/clocking-wizard/dt-binding.txt +++ /dev/null @@ -1,30 +0,0 @@ -Binding for Xilinx Clocking Wizard IP Core - -This binding uses the common clock binding[1]. Details about the devices can be -found in the product guide[2]. - -[1] Documentation/devicetree/bindings/clock/clock-bindings.txt -[2] Clocking Wizard Product Guide -https://www.xilinx.com/support/documentation/ip_documentation/clk_wiz/v5_1/pg065-clk-wiz.pdf - -Required properties: - - compatible: Must be 'xlnx,clocking-wizard' - - reg: Base and size of the cores register space - - clocks: Handle to input clock - - clock-names: Tuple containing 'clk_in1' and 's_axi_aclk' - - clock-output-names: Names for the output clocks - -Optional properties: - - speed-grade: Speed grade of the device (valid values are 1..3) - -Example: - clock-generator@40040000 { - reg = <0x40040000 0x1000>; - compatible = "xlnx,clocking-wizard"; - speed-grade = <1>; - clock-names = "clk_in1", "s_axi_aclk"; - clocks = <&clkc 15>, <&clkc 15>; - clock-output-names = "clk_out0", "clk_out1", "clk_out2", - "clk_out3", "clk_out4", "clk_out5", - "clk_out6", "clk_out7"; - }; diff --git a/drivers/staging/fbtft/Kconfig b/drivers/staging/fbtft/Kconfig index dad1ddcd7b0c..4d29e8c1014e 100644 --- a/drivers/staging/fbtft/Kconfig +++ b/drivers/staging/fbtft/Kconfig @@ -200,9 +200,3 @@ config FB_TFT_UPD161704 depends on FB_TFT help Generic Framebuffer support for uPD161704 - -config FB_TFT_WATTEROTT - tristate "FB driver for the WATTEROTT LCD Controller" - depends on FB_TFT - help - Generic Framebuffer support for WATTEROTT diff --git a/drivers/staging/fbtft/Makefile b/drivers/staging/fbtft/Makefile index e87193f7df14..e9cdf0f0a7da 100644 --- a/drivers/staging/fbtft/Makefile +++ b/drivers/staging/fbtft/Makefile @@ -36,4 +36,3 @@ obj-$(CONFIG_FB_TFT_TLS8204) += fb_tls8204.o obj-$(CONFIG_FB_TFT_UC1611) += fb_uc1611.o obj-$(CONFIG_FB_TFT_UC1701) += fb_uc1701.o obj-$(CONFIG_FB_TFT_UPD161704) += fb_upd161704.o -obj-$(CONFIG_FB_TFT_WATTEROTT) += fb_watterott.o diff --git a/drivers/staging/fbtft/fb_sh1106.c b/drivers/staging/fbtft/fb_sh1106.c index 7b9ab39e1c1a..9685ca516a0e 100644 --- a/drivers/staging/fbtft/fb_sh1106.c +++ b/drivers/staging/fbtft/fb_sh1106.c @@ -173,12 +173,7 @@ static struct fbtft_display display = { }, }; -FBTFT_REGISTER_DRIVER(DRVNAME, "sinowealth,sh1106", &display); - -MODULE_ALIAS("spi:" DRVNAME); -MODULE_ALIAS("platform:" DRVNAME); -MODULE_ALIAS("spi:sh1106"); -MODULE_ALIAS("platform:sh1106"); +FBTFT_REGISTER_SPI_DRIVER(DRVNAME, "sinowealth", "sh1106", &display); MODULE_DESCRIPTION("SH1106 OLED Driver"); MODULE_AUTHOR("Heiner Kallweit"); diff --git a/drivers/staging/fbtft/fb_ssd1351.c b/drivers/staging/fbtft/fb_ssd1351.c index 6fd549a424d5..b8d55aa8c5c7 100644 --- a/drivers/staging/fbtft/fb_ssd1351.c +++ b/drivers/staging/fbtft/fb_ssd1351.c @@ -196,8 +196,7 @@ static int update_onboard_backlight(struct backlight_device *bd) "%s: power=%d, fb_blank=%d\n", __func__, bd->props.power, bd->props.fb_blank); - on = (bd->props.power == FB_BLANK_UNBLANK) && - (bd->props.fb_blank == FB_BLANK_UNBLANK); + on = !backlight_is_blank(bd); /* Onboard backlight connected to GPIO0 on SSD1351, GPIO1 unused */ write_reg(par, 0xB5, on ? 0x03 : 0x02); diff --git a/drivers/staging/fbtft/fb_st7789v.c b/drivers/staging/fbtft/fb_st7789v.c index abe9395a0aef..861a154144e6 100644 --- a/drivers/staging/fbtft/fb_st7789v.c +++ b/drivers/staging/fbtft/fb_st7789v.c @@ -144,6 +144,8 @@ static int init_display(struct fbtft_par *par) { int rc; + par->fbtftops.reset(par); + rc = init_tearing_effect_line(par); if (rc) return rc; diff --git a/drivers/staging/fbtft/fb_watterott.c b/drivers/staging/fbtft/fb_watterott.c deleted file mode 100644 index a57e1f4feef3..000000000000 --- a/drivers/staging/fbtft/fb_watterott.c +++ /dev/null @@ -1,302 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * FB driver for the Watterott LCD Controller - * - * Copyright (C) 2013 Noralf Tronnes - */ - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/delay.h> - -#include "fbtft.h" - -#define DRVNAME "fb_watterott" -#define WIDTH 320 -#define HEIGHT 240 -#define FPS 5 -#define TXBUFLEN 1024 -#define DEFAULT_BRIGHTNESS 50 - -#define CMD_VERSION 0x01 -#define CMD_LCD_LED 0x10 -#define CMD_LCD_RESET 0x11 -#define CMD_LCD_ORIENTATION 0x20 -#define CMD_LCD_DRAWIMAGE 0x27 -#define COLOR_RGB323 8 -#define COLOR_RGB332 9 -#define COLOR_RGB233 10 -#define COLOR_RGB565 16 - -static short mode = 565; -module_param(mode, short, 0000); -MODULE_PARM_DESC(mode, "RGB color transfer mode: 332, 565 (default)"); - -static void write_reg8_bus8(struct fbtft_par *par, int len, ...) -{ - va_list args; - int i, ret; - u8 *buf = par->buf; - - va_start(args, len); - for (i = 0; i < len; i++) - *buf++ = (u8)va_arg(args, unsigned int); - va_end(args); - - fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, - par->info->device, u8, par->buf, - len, "%s: ", __func__); - - ret = par->fbtftops.write(par, par->buf, len); - if (ret < 0) { - dev_err(par->info->device, - "write() failed and returned %d\n", ret); - return; - } -} - -static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) -{ - unsigned int start_line, end_line; - u16 *vmem16 = (u16 *)(par->info->screen_buffer + offset); - __be16 *pos = par->txbuf.buf + 1; - __be16 *buf16 = par->txbuf.buf + 10; - int i, j; - int ret = 0; - - start_line = offset / par->info->fix.line_length; - end_line = start_line + (len / par->info->fix.line_length) - 1; - - /* Set command header. pos: x, y, w, h */ - ((u8 *)par->txbuf.buf)[0] = CMD_LCD_DRAWIMAGE; - pos[0] = 0; - pos[2] = cpu_to_be16(par->info->var.xres); - pos[3] = cpu_to_be16(1); - ((u8 *)par->txbuf.buf)[9] = COLOR_RGB565; - - for (i = start_line; i <= end_line; i++) { - pos[1] = cpu_to_be16(i); - for (j = 0; j < par->info->var.xres; j++) - buf16[j] = cpu_to_be16(*vmem16++); - ret = par->fbtftops.write(par, - par->txbuf.buf, 10 + par->info->fix.line_length); - if (ret < 0) - return ret; - udelay(300); - } - - return 0; -} - -static inline int rgb565_to_rgb332(u16 c) -{ - return ((c & 0xE000) >> 8) | ((c & 000700) >> 6) | ((c & 0x0018) >> 3); -} - -static int write_vmem_8bit(struct fbtft_par *par, size_t offset, size_t len) -{ - unsigned int start_line, end_line; - u16 *vmem16 = (u16 *)(par->info->screen_buffer + offset); - __be16 *pos = par->txbuf.buf + 1; - u8 *buf8 = par->txbuf.buf + 10; - int i, j; - int ret = 0; - - start_line = offset / par->info->fix.line_length; - end_line = start_line + (len / par->info->fix.line_length) - 1; - - /* Set command header. pos: x, y, w, h */ - ((u8 *)par->txbuf.buf)[0] = CMD_LCD_DRAWIMAGE; - pos[0] = 0; - pos[2] = cpu_to_be16(par->info->var.xres); - pos[3] = cpu_to_be16(1); - ((u8 *)par->txbuf.buf)[9] = COLOR_RGB332; - - for (i = start_line; i <= end_line; i++) { - pos[1] = cpu_to_be16(i); - for (j = 0; j < par->info->var.xres; j++) { - buf8[j] = rgb565_to_rgb332(*vmem16); - vmem16++; - } - ret = par->fbtftops.write(par, - par->txbuf.buf, 10 + par->info->var.xres); - if (ret < 0) - return ret; - udelay(700); - } - - return 0; -} - -static unsigned int firmware_version(struct fbtft_par *par) -{ - u8 rxbuf[4] = {0, }; - - write_reg(par, CMD_VERSION); - par->fbtftops.read(par, rxbuf, 4); - if (rxbuf[1] != '.') - return 0; - - return (rxbuf[0] - '0') << 8 | (rxbuf[2] - '0') << 4 | (rxbuf[3] - '0'); -} - -static int init_display(struct fbtft_par *par) -{ - int ret; - unsigned int version; - u8 save_mode; - - /* enable SPI interface by having CS and MOSI low during reset */ - save_mode = par->spi->mode; - /* - * Set CS active inverse polarity: just setting SPI_CS_HIGH does not - * work with GPIO based chip selects that are logically active high - * but inverted inside the GPIO library, so enforce inverted - * semantics. - */ - par->spi->mode ^= SPI_CS_HIGH; - ret = spi_setup(par->spi); - if (ret) { - dev_err(par->info->device, - "Could not set inverse CS polarity\n"); - return ret; - } - write_reg(par, 0x00); /* make sure mode is set */ - - mdelay(50); - par->fbtftops.reset(par); - mdelay(1000); - par->spi->mode = save_mode; - ret = spi_setup(par->spi); - if (ret) { - dev_err(par->info->device, "Could not restore SPI mode\n"); - return ret; - } - write_reg(par, 0x00); - - version = firmware_version(par); - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "Firmware version: %x.%02x\n", - version >> 8, version & 0xFF); - - if (mode == 332) - par->fbtftops.write_vmem = write_vmem_8bit; - return 0; -} - -static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) -{ - /* not used on this controller */ -} - -static int set_var(struct fbtft_par *par) -{ - u8 rotate; - - /* this controller rotates clock wise */ - switch (par->info->var.rotate) { - case 90: - rotate = 27; - break; - case 180: - rotate = 18; - break; - case 270: - rotate = 9; - break; - default: - rotate = 0; - } - write_reg(par, CMD_LCD_ORIENTATION, rotate); - - return 0; -} - -static int verify_gpios(struct fbtft_par *par) -{ - if (!par->gpio.reset) { - dev_err(par->info->device, "Missing 'reset' gpio. Aborting.\n"); - return -EINVAL; - } - return 0; -} - -#ifdef CONFIG_FB_BACKLIGHT -static int backlight_chip_update_status(struct backlight_device *bd) -{ - struct fbtft_par *par = bl_get_data(bd); - int brightness = bd->props.brightness; - - fbtft_par_dbg(DEBUG_BACKLIGHT, par, - "%s: brightness=%d, power=%d, fb_blank=%d\n", __func__, - bd->props.brightness, bd->props.power, - bd->props.fb_blank); - - if (bd->props.power != FB_BLANK_UNBLANK) - brightness = 0; - - if (bd->props.fb_blank != FB_BLANK_UNBLANK) - brightness = 0; - - write_reg(par, CMD_LCD_LED, brightness); - - return 0; -} - -static const struct backlight_ops bl_ops = { - .update_status = backlight_chip_update_status, -}; - -static void register_chip_backlight(struct fbtft_par *par) -{ - struct backlight_device *bd; - struct backlight_properties bl_props = { 0, }; - - bl_props.type = BACKLIGHT_RAW; - bl_props.power = FB_BLANK_POWERDOWN; - bl_props.max_brightness = 100; - bl_props.brightness = DEFAULT_BRIGHTNESS; - - bd = backlight_device_register(dev_driver_string(par->info->device), - par->info->device, par, &bl_ops, - &bl_props); - if (IS_ERR(bd)) { - dev_err(par->info->device, - "cannot register backlight device (%ld)\n", - PTR_ERR(bd)); - return; - } - par->info->bl_dev = bd; - - if (!par->fbtftops.unregister_backlight) - par->fbtftops.unregister_backlight = fbtft_unregister_backlight; -} -#else -#define register_chip_backlight NULL -#endif - -static struct fbtft_display display = { - .regwidth = 8, - .buswidth = 8, - .width = WIDTH, - .height = HEIGHT, - .fps = FPS, - .txbuflen = TXBUFLEN, - .fbtftops = { - .write_register = write_reg8_bus8, - .write_vmem = write_vmem, - .init_display = init_display, - .set_addr_win = set_addr_win, - .set_var = set_var, - .verify_gpios = verify_gpios, - .register_backlight = register_chip_backlight, - }, -}; - -FBTFT_REGISTER_DRIVER(DRVNAME, "watterott,openlcd", &display); - -MODULE_ALIAS("spi:" DRVNAME); - -MODULE_DESCRIPTION("FB driver for the Watterott LCD Controller"); -MODULE_AUTHOR("Noralf Tronnes"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c index f2684d2d6851..afaba94d1d1c 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -49,7 +49,7 @@ int fbtft_write_buf_dc(struct fbtft_par *par, void *buf, size_t len, int dc) EXPORT_SYMBOL(fbtft_write_buf_dc); void fbtft_dbg_hex(const struct device *dev, int groupsize, - void *buf, size_t len, const char *fmt, ...) + const void *buf, size_t len, const char *fmt, ...) { va_list args; static char textbuf[512]; @@ -137,8 +137,7 @@ static int fbtft_backlight_update_status(struct backlight_device *bd) "%s: polarity=%d, power=%d, fb_blank=%d\n", __func__, polarity, bd->props.power, bd->props.fb_blank); - if ((bd->props.power == FB_BLANK_UNBLANK) && - (bd->props.fb_blank == FB_BLANK_UNBLANK)) + if (!backlight_is_blank(bd)) gpiod_set_value(par->gpio.led[0], polarity); else gpiod_set_value(par->gpio.led[0], !polarity); @@ -322,12 +321,11 @@ static void fbtft_mkdirty(struct fb_info *info, int y, int height) schedule_delayed_work(&info->deferred_work, fbdefio->delay); } -static void fbtft_deferred_io(struct fb_info *info, struct list_head *pagelist) +static void fbtft_deferred_io(struct fb_info *info, struct list_head *pagereflist) { struct fbtft_par *par = info->par; unsigned int dirty_lines_start, dirty_lines_end; - struct page *page; - unsigned long index; + struct fb_deferred_io_pageref *pageref; unsigned int y_low = 0, y_high = 0; int count = 0; @@ -340,14 +338,13 @@ static void fbtft_deferred_io(struct fb_info *info, struct list_head *pagelist) spin_unlock(&par->dirty_lock); /* Mark display lines as dirty */ - list_for_each_entry(page, pagelist, lru) { + list_for_each_entry(pageref, pagereflist, list) { count++; - index = page->index << PAGE_SHIFT; - y_low = index / info->fix.line_length; - y_high = (index + PAGE_SIZE - 1) / info->fix.line_length; + y_low = pageref->offset / info->fix.line_length; + y_high = (pageref->offset + PAGE_SIZE - 1) / info->fix.line_length; dev_dbg(info->device, "page->index=%lu y_low=%d y_high=%d\n", - page->index, y_low, y_high); + pageref->page->index, y_low, y_high); if (y_high > info->var.yres - 1) y_high = info->var.yres - 1; if (y_low < dirty_lines_start) @@ -652,10 +649,11 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, fbops->fb_imageblit = fbtft_fb_imageblit; fbops->fb_setcolreg = fbtft_fb_setcolreg; fbops->fb_blank = fbtft_fb_blank; + fbops->fb_mmap = fb_deferred_io_mmap; - fbdefio->delay = HZ / fps; - fbdefio->deferred_io = fbtft_deferred_io; - fb_deferred_io_init(info); + fbdefio->delay = HZ / fps; + fbdefio->sort_pagereflist = true; + fbdefio->deferred_io = fbtft_deferred_io; snprintf(info->fix.id, sizeof(info->fix.id), "%s", dev->driver->name); info->fix.type = FB_TYPE_PACKED_PIXELS; @@ -666,6 +664,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, info->fix.line_length = width * bpp / 8; info->fix.accel = FB_ACCEL_NONE; info->fix.smem_len = vmem_size; + fb_deferred_io_init(info); info->var.rotate = pdata->rotate; info->var.xres = width; @@ -1034,10 +1033,9 @@ int fbtft_init_display(struct fbtft_par *par) for (j = 0; par->init_sequence[i + 1 + j] >= 0; j++) ; - fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, - "init: write(0x%02X) %*ph\n", - par->init_sequence[i], j, - &par->init_sequence[i + 1]); + fbtft_par_dbg_hex(DEBUG_INIT_DISPLAY, par, par->info->device, + s16, &par->init_sequence[i + 1], j, + "init: write(0x%02X)", par->init_sequence[i]); /* Write */ j = 0; diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h index 6869f3603b0e..2c2b5f1c1df3 100644 --- a/drivers/staging/fbtft/fbtft.h +++ b/drivers/staging/fbtft/fbtft.h @@ -240,7 +240,7 @@ struct fbtft_par { int fbtft_write_buf_dc(struct fbtft_par *par, void *buf, size_t len, int dc); __printf(5, 6) void fbtft_dbg_hex(const struct device *dev, int groupsize, - void *buf, size_t len, const char *fmt, ...); + const void *buf, size_t len, const char *fmt, ...); struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, struct device *dev, struct fbtft_platform_data *pdata); @@ -272,21 +272,39 @@ void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...); void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...); void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...); +#define FBTFT_DT_TABLE(_compatible) \ +static const struct of_device_id dt_ids[] = { \ + { .compatible = _compatible }, \ + {}, \ +}; \ +MODULE_DEVICE_TABLE(of, dt_ids); + +#define FBTFT_SPI_DRIVER(_name, _compatible, _display, _spi_ids) \ + \ +static int fbtft_driver_probe_spi(struct spi_device *spi) \ +{ \ + return fbtft_probe_common(_display, spi, NULL); \ +} \ + \ +static void fbtft_driver_remove_spi(struct spi_device *spi) \ +{ \ + struct fb_info *info = spi_get_drvdata(spi); \ + \ + fbtft_remove_common(&spi->dev, info); \ +} \ + \ +static struct spi_driver fbtft_driver_spi_driver = { \ + .driver = { \ + .name = _name, \ + .of_match_table = dt_ids, \ + }, \ + .id_table = _spi_ids, \ + .probe = fbtft_driver_probe_spi, \ + .remove = fbtft_driver_remove_spi, \ +}; + #define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \ \ -static int fbtft_driver_probe_spi(struct spi_device *spi) \ -{ \ - return fbtft_probe_common(_display, spi, NULL); \ -} \ - \ -static int fbtft_driver_remove_spi(struct spi_device *spi) \ -{ \ - struct fb_info *info = spi_get_drvdata(spi); \ - \ - fbtft_remove_common(&spi->dev, info); \ - return 0; \ -} \ - \ static int fbtft_driver_probe_pdev(struct platform_device *pdev) \ { \ return fbtft_probe_common(_display, NULL, pdev); \ @@ -300,22 +318,9 @@ static int fbtft_driver_remove_pdev(struct platform_device *pdev) \ return 0; \ } \ \ -static const struct of_device_id dt_ids[] = { \ - { .compatible = _compatible }, \ - {}, \ -}; \ - \ -MODULE_DEVICE_TABLE(of, dt_ids); \ - \ +FBTFT_DT_TABLE(_compatible) \ \ -static struct spi_driver fbtft_driver_spi_driver = { \ - .driver = { \ - .name = _name, \ - .of_match_table = dt_ids, \ - }, \ - .probe = fbtft_driver_probe_spi, \ - .remove = fbtft_driver_remove_spi, \ -}; \ +FBTFT_SPI_DRIVER(_name, _compatible, _display, NULL) \ \ static struct platform_driver fbtft_driver_platform_driver = { \ .driver = { \ @@ -334,7 +339,10 @@ static int __init fbtft_driver_module_init(void) \ ret = spi_register_driver(&fbtft_driver_spi_driver); \ if (ret < 0) \ return ret; \ - return platform_driver_register(&fbtft_driver_platform_driver); \ + ret = platform_driver_register(&fbtft_driver_platform_driver); \ + if (ret < 0) \ + spi_unregister_driver(&fbtft_driver_spi_driver); \ + return ret; \ } \ \ static void __exit fbtft_driver_module_exit(void) \ @@ -346,6 +354,20 @@ static void __exit fbtft_driver_module_exit(void) \ module_init(fbtft_driver_module_init); \ module_exit(fbtft_driver_module_exit); +#define FBTFT_REGISTER_SPI_DRIVER(_name, _comp_vend, _comp_dev, _display) \ + \ +FBTFT_DT_TABLE(_comp_vend "," _comp_dev) \ + \ +static const struct spi_device_id spi_ids[] = { \ + { .name = _comp_dev }, \ + {}, \ +}; \ +MODULE_DEVICE_TABLE(spi, spi_ids); \ + \ +FBTFT_SPI_DRIVER(_name, _comp_vend "," _comp_dev, _display, spi_ids) \ + \ +module_spi_driver(fbtft_driver_spi_driver); + /* Debug macros */ /* shorthand debug levels */ diff --git a/drivers/staging/fieldbus/anybuss/host.c b/drivers/staging/fieldbus/anybuss/host.c index a344410e48fe..cd86b9c9e345 100644 --- a/drivers/staging/fieldbus/anybuss/host.c +++ b/drivers/staging/fieldbus/anybuss/host.c @@ -1384,7 +1384,7 @@ anybuss_host_common_probe(struct device *dev, goto err_device; return cd; err_device: - device_unregister(&cd->client->dev); + put_device(&cd->client->dev); err_kthread: kthread_stop(cd->qthread); err_reset: diff --git a/drivers/staging/fwserial/Kconfig b/drivers/staging/fwserial/Kconfig deleted file mode 100644 index 6964aac2a7ed..000000000000 --- a/drivers/staging/fwserial/Kconfig +++ /dev/null @@ -1,32 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -config FIREWIRE_SERIAL - tristate "TTY over Firewire" - depends on FIREWIRE && TTY - help - This enables TTY over IEEE 1394, providing high-speed serial - connectivity to cabled peers. This driver implements a - ad-hoc transport protocol and is currently limited to - Linux-to-Linux communication. - - To compile this driver as a module, say M here: the module will - be called firewire-serial. - -if FIREWIRE_SERIAL - -config FWTTY_MAX_TOTAL_PORTS - int "Maximum number of serial ports supported" - default "64" - help - Set this to the maximum number of serial ports you want the - firewire-serial driver to support. - -config FWTTY_MAX_CARD_PORTS - int "Maximum number of serial ports supported per adapter" - range 0 FWTTY_MAX_TOTAL_PORTS - default "32" - help - Set this to the maximum number of serial ports each firewire - adapter supports. The actual number of serial ports registered - is set with the module parameter "ttys". - -endif diff --git a/drivers/staging/fwserial/Makefile b/drivers/staging/fwserial/Makefile deleted file mode 100644 index 1cd5c5c7e805..000000000000 --- a/drivers/staging/fwserial/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_FIREWIRE_SERIAL) += firewire-serial.o -firewire-serial-objs := fwserial.o dma_fifo.o diff --git a/drivers/staging/fwserial/TODO b/drivers/staging/fwserial/TODO deleted file mode 100644 index 382a7959407c..000000000000 --- a/drivers/staging/fwserial/TODO +++ /dev/null @@ -1,14 +0,0 @@ -TODOs prior to this driver moving out of staging ------------------------------------------------- -1. Implement retries for RCODE_BUSY, RCODE_NO_ACK and RCODE_SEND_ERROR - - I/O is handled asynchronously which presents some issues when error - conditions occur. -2. Implement _robust_ console on top of this. The existing prototype console - driver is not ready for the big leagues yet. -3. Expose means of controlling attach/detach of peers via sysfs. Include - GUID-to-port matching/whitelist/blacklist. - --- Issues with firewire stack -- -1. This driver uses the same unregistered vendor id that the firewire core does - (0xd00d1e). Perhaps this could be exposed as a define in - firewire.h? diff --git a/drivers/staging/fwserial/dma_fifo.c b/drivers/staging/fwserial/dma_fifo.c deleted file mode 100644 index 5dcbab6fd622..000000000000 --- a/drivers/staging/fwserial/dma_fifo.c +++ /dev/null @@ -1,294 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * DMA-able FIFO implementation - * - * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com> - */ - -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/list.h> -#include <linux/bug.h> - -#include "dma_fifo.h" - -#ifdef DEBUG_TRACING -#define df_trace(s, args...) pr_debug(s, ##args) -#else -#define df_trace(s, args...) -#endif - -#define FAIL(fifo, condition, format...) ({ \ - fifo->corrupt = !!(condition); \ - WARN(fifo->corrupt, format); \ -}) - -/* - * private helper fn to determine if check is in open interval (lo,hi) - */ -static bool addr_check(unsigned int check, unsigned int lo, unsigned int hi) -{ - return check - (lo + 1) < (hi - 1) - lo; -} - -/** - * dma_fifo_init: initialize the fifo to a valid but inoperative state - * @fifo: address of in-place "struct dma_fifo" object - */ -void dma_fifo_init(struct dma_fifo *fifo) -{ - memset(fifo, 0, sizeof(*fifo)); - INIT_LIST_HEAD(&fifo->pending); -} - -/** - * dma_fifo_alloc - initialize and allocate dma_fifo - * @fifo: address of in-place "struct dma_fifo" object - * @size: 'apparent' size, in bytes, of fifo - * @align: dma alignment to maintain (should be at least cpu cache alignment), - * must be power of 2 - * @tx_limit: maximum # of bytes transmissible per dma (rounded down to - * multiple of alignment, but at least align size) - * @open_limit: maximum # of outstanding dma transactions allowed - * @gfp_mask: get_free_pages mask, passed to kmalloc() - * - * The 'apparent' size will be rounded up to next greater aligned size. - * Returns 0 if no error, otherwise an error code - */ -int dma_fifo_alloc(struct dma_fifo *fifo, int size, unsigned int align, - int tx_limit, int open_limit, gfp_t gfp_mask) -{ - int capacity; - - if (!is_power_of_2(align) || size < 0) - return -EINVAL; - - size = round_up(size, align); - capacity = size + align * open_limit + align * DMA_FIFO_GUARD; - fifo->data = kmalloc(capacity, gfp_mask); - if (!fifo->data) - return -ENOMEM; - - fifo->in = 0; - fifo->out = 0; - fifo->done = 0; - fifo->size = size; - fifo->avail = size; - fifo->align = align; - fifo->tx_limit = max_t(int, round_down(tx_limit, align), align); - fifo->open = 0; - fifo->open_limit = open_limit; - fifo->guard = size + align * open_limit; - fifo->capacity = capacity; - fifo->corrupt = 0; - - return 0; -} - -/** - * dma_fifo_free - frees the fifo - * @fifo: address of in-place "struct dma_fifo" to free - * - * Also reinits the fifo to a valid but inoperative state. This - * allows the fifo to be reused with a different target requiring - * different fifo parameters. - */ -void dma_fifo_free(struct dma_fifo *fifo) -{ - struct dma_pending *pending, *next; - - if (!fifo->data) - return; - - list_for_each_entry_safe(pending, next, &fifo->pending, link) - list_del_init(&pending->link); - kfree(fifo->data); - fifo->data = NULL; -} - -/** - * dma_fifo_reset - dumps the fifo contents and reinits for reuse - * @fifo: address of in-place "struct dma_fifo" to reset - */ -void dma_fifo_reset(struct dma_fifo *fifo) -{ - struct dma_pending *pending, *next; - - if (!fifo->data) - return; - - list_for_each_entry_safe(pending, next, &fifo->pending, link) - list_del_init(&pending->link); - fifo->in = 0; - fifo->out = 0; - fifo->done = 0; - fifo->avail = fifo->size; - fifo->open = 0; - fifo->corrupt = 0; -} - -/** - * dma_fifo_in - copies data into the fifo - * @fifo: address of in-place "struct dma_fifo" to write to - * @src: buffer to copy from - * @n: # of bytes to copy - * - * Returns the # of bytes actually copied, which can be less than requested if - * the fifo becomes full. If < 0, return is error code. - */ -int dma_fifo_in(struct dma_fifo *fifo, const void *src, int n) -{ - int ofs, l; - - if (!fifo->data) - return -ENOENT; - if (fifo->corrupt) - return -ENXIO; - - if (n > fifo->avail) - n = fifo->avail; - if (n <= 0) - return 0; - - ofs = fifo->in % fifo->capacity; - l = min(n, fifo->capacity - ofs); - memcpy(fifo->data + ofs, src, l); - memcpy(fifo->data, src + l, n - l); - - if (FAIL(fifo, addr_check(fifo->done, fifo->in, fifo->in + n) || - fifo->avail < n, - "fifo corrupt: in:%u out:%u done:%u n:%d avail:%d", - fifo->in, fifo->out, fifo->done, n, fifo->avail)) - return -ENXIO; - - fifo->in += n; - fifo->avail -= n; - - df_trace("in:%u out:%u done:%u n:%d avail:%d", fifo->in, fifo->out, - fifo->done, n, fifo->avail); - - return n; -} - -/** - * dma_fifo_out_pend - gets address/len of next avail read and marks as pended - * @fifo: address of in-place "struct dma_fifo" to read from - * @pended: address of structure to fill with read address/len - * The data/len fields will be NULL/0 if no dma is pended. - * - * Returns the # of used bytes remaining in fifo (ie, if > 0, more data - * remains in the fifo that was not pended). If < 0, return is error code. - */ -int dma_fifo_out_pend(struct dma_fifo *fifo, struct dma_pending *pended) -{ - unsigned int len, n, ofs, l, limit; - - if (!fifo->data) - return -ENOENT; - if (fifo->corrupt) - return -ENXIO; - - pended->len = 0; - pended->data = NULL; - pended->out = fifo->out; - - len = fifo->in - fifo->out; - if (!len) - return -ENODATA; - if (fifo->open == fifo->open_limit) - return -EAGAIN; - - n = len; - ofs = fifo->out % fifo->capacity; - l = fifo->capacity - ofs; - limit = min_t(unsigned int, l, fifo->tx_limit); - if (n > limit) { - n = limit; - fifo->out += limit; - } else if (ofs + n > fifo->guard) { - fifo->out += l; - fifo->in = fifo->out; - } else { - fifo->out += round_up(n, fifo->align); - fifo->in = fifo->out; - } - - df_trace("in: %u out: %u done: %u n: %d len: %u avail: %d", fifo->in, - fifo->out, fifo->done, n, len, fifo->avail); - - pended->len = n; - pended->data = fifo->data + ofs; - pended->next = fifo->out; - list_add_tail(&pended->link, &fifo->pending); - ++fifo->open; - - if (FAIL(fifo, fifo->open > fifo->open_limit, - "past open limit:%d (limit:%d)", - fifo->open, fifo->open_limit)) - return -ENXIO; - if (FAIL(fifo, fifo->out & (fifo->align - 1), - "fifo out unaligned:%u (align:%u)", - fifo->out, fifo->align)) - return -ENXIO; - - return len - n; -} - -/** - * dma_fifo_out_complete - marks pended dma as completed - * @fifo: address of in-place "struct dma_fifo" which was read from - * @complete: address of structure for previously pended dma to mark completed - */ -int dma_fifo_out_complete(struct dma_fifo *fifo, struct dma_pending *complete) -{ - struct dma_pending *pending, *next, *tmp; - - if (!fifo->data) - return -ENOENT; - if (fifo->corrupt) - return -ENXIO; - if (list_empty(&fifo->pending) && fifo->open == 0) - return -EINVAL; - - if (FAIL(fifo, list_empty(&fifo->pending) != (fifo->open == 0), - "pending list disagrees with open count:%d", - fifo->open)) - return -ENXIO; - - tmp = complete->data; - *tmp = *complete; - list_replace(&complete->link, &tmp->link); - dp_mark_completed(tmp); - - /* Only update the fifo in the original pended order */ - list_for_each_entry_safe(pending, next, &fifo->pending, link) { - if (!dp_is_completed(pending)) { - df_trace("still pending: saved out: %u len: %d", - pending->out, pending->len); - break; - } - - if (FAIL(fifo, pending->out != fifo->done || - addr_check(fifo->in, fifo->done, pending->next), - "in:%u out:%u done:%u saved:%u next:%u", - fifo->in, fifo->out, fifo->done, pending->out, - pending->next)) - return -ENXIO; - - list_del_init(&pending->link); - fifo->done = pending->next; - fifo->avail += pending->len; - --fifo->open; - - df_trace("in: %u out: %u done: %u len: %u avail: %d", fifo->in, - fifo->out, fifo->done, pending->len, fifo->avail); - } - - if (FAIL(fifo, fifo->open < 0, "open dma:%d < 0", fifo->open)) - return -ENXIO; - if (FAIL(fifo, fifo->avail > fifo->size, "fifo avail:%d > size:%d", - fifo->avail, fifo->size)) - return -ENXIO; - - return 0; -} diff --git a/drivers/staging/fwserial/dma_fifo.h b/drivers/staging/fwserial/dma_fifo.h deleted file mode 100644 index c46a06336975..000000000000 --- a/drivers/staging/fwserial/dma_fifo.h +++ /dev/null @@ -1,117 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * DMA-able FIFO interface - * - * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com> - */ - -#ifndef _DMA_FIFO_H_ -#define _DMA_FIFO_H_ - -/** - * The design basis for the DMA FIFO is to provide an output side that - * complies with the streaming DMA API design that can be DMA'd from directly - * (without additional copying), coupled with an input side that maintains a - * logically consistent 'apparent' size (ie, bytes in + bytes avail is static - * for the lifetime of the FIFO). - * - * DMA output transactions originate on a cache line boundary and can be - * variably-sized. DMA output transactions can be retired out-of-order but - * the FIFO will only advance the output in the original input sequence. - * This means the FIFO will eventually stall if a transaction is never retired. - * - * Chunking the output side into cache line multiples means that some FIFO - * memory is unused. For example, if all the avail input has been pended out, - * then the in and out markers are re-aligned to the next cache line. - * The maximum possible waste is - * (cache line alignment - 1) * (max outstanding dma transactions) - * This potential waste requires additional hidden capacity within the FIFO - * to be able to accept input while the 'apparent' size has not been reached. - * - * Additional cache lines (ie, guard area) are used to minimize DMA - * fragmentation when wrapping at the end of the FIFO. Input is allowed into the - * guard area, but the in and out FIFO markers are wrapped when DMA is pended. - */ - -#define DMA_FIFO_GUARD 3 /* # of cache lines to reserve for the guard area */ - -struct dma_fifo { - unsigned int in; - unsigned int out; /* updated when dma is pended */ - unsigned int done; /* updated upon dma completion */ - struct { - unsigned corrupt:1; - }; - int size; /* 'apparent' size of fifo */ - int guard; /* ofs of guard area */ - int capacity; /* size + reserved */ - int avail; /* # of unused bytes in fifo */ - unsigned int align; /* must be power of 2 */ - int tx_limit; /* max # of bytes per dma transaction */ - int open_limit; /* max # of outstanding allowed */ - int open; /* # of outstanding dma transactions */ - struct list_head pending; /* fifo markers for outstanding dma */ - void *data; -}; - -struct dma_pending { - struct list_head link; - void *data; - unsigned int len; - unsigned int next; - unsigned int out; -}; - -static inline void dp_mark_completed(struct dma_pending *dp) -{ - dp->data += 1; -} - -static inline bool dp_is_completed(struct dma_pending *dp) -{ - return (unsigned long)dp->data & 1UL; -} - -void dma_fifo_init(struct dma_fifo *fifo); -int dma_fifo_alloc(struct dma_fifo *fifo, int size, unsigned int align, - int tx_limit, int open_limit, gfp_t gfp_mask); -void dma_fifo_free(struct dma_fifo *fifo); -void dma_fifo_reset(struct dma_fifo *fifo); -int dma_fifo_in(struct dma_fifo *fifo, const void *src, int n); -int dma_fifo_out_pend(struct dma_fifo *fifo, struct dma_pending *pended); -int dma_fifo_out_complete(struct dma_fifo *fifo, - struct dma_pending *complete); - -/* returns the # of used bytes in the fifo */ -static inline int dma_fifo_level(struct dma_fifo *fifo) -{ - return fifo->size - fifo->avail; -} - -/* returns the # of bytes ready for output in the fifo */ -static inline int dma_fifo_out_level(struct dma_fifo *fifo) -{ - return fifo->in - fifo->out; -} - -/* returns the # of unused bytes in the fifo */ -static inline int dma_fifo_avail(struct dma_fifo *fifo) -{ - return fifo->avail; -} - -/* returns true if fifo has max # of outstanding dmas */ -static inline bool dma_fifo_busy(struct dma_fifo *fifo) -{ - return fifo->open == fifo->open_limit; -} - -/* changes the max size of dma returned from dma_fifo_out_pend() */ -static inline int dma_fifo_change_tx_limit(struct dma_fifo *fifo, int tx_limit) -{ - tx_limit = round_down(tx_limit, fifo->align); - fifo->tx_limit = max_t(int, tx_limit, fifo->align); - return 0; -} - -#endif /* _DMA_FIFO_H_ */ diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c deleted file mode 100644 index e8fa7f53cd5e..000000000000 --- a/drivers/staging/fwserial/fwserial.c +++ /dev/null @@ -1,2890 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * FireWire Serial driver - * - * Copyright (C) 2012 Peter Hurley <peter@hurleysoftware.com> - */ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include <linux/sched.h> -#include <linux/slab.h> -#include <linux/device.h> -#include <linux/mod_devicetable.h> -#include <linux/rculist.h> -#include <linux/workqueue.h> -#include <linux/ratelimit.h> -#include <linux/bug.h> -#include <linux/uaccess.h> - -#include "fwserial.h" - -inline u64 be32_to_u64(__be32 hi, __be32 lo) -{ - return ((u64)be32_to_cpu(hi) << 32 | be32_to_cpu(lo)); -} - -#define LINUX_VENDOR_ID 0xd00d1eU /* same id used in card root directory */ -#define FWSERIAL_VERSION 0x00e81cU /* must be unique within LINUX_VENDOR_ID */ - -/* configurable options */ -static int num_ttys = 4; /* # of std ttys to create per fw_card */ - /* - doubles as loopback port index */ -static bool auto_connect = true; /* try to VIRT_CABLE to every peer */ -static bool create_loop_dev = true; /* create a loopback device for each card */ - -module_param_named(ttys, num_ttys, int, 0644); -module_param_named(auto, auto_connect, bool, 0644); -module_param_named(loop, create_loop_dev, bool, 0644); - -/* - * Threshold below which the tty is woken for writing - * - should be equal to WAKEUP_CHARS in drivers/tty/n_tty.c because - * even if the writer is woken, n_tty_poll() won't set EPOLLOUT until - * our fifo is below this level - */ -#define WAKEUP_CHARS 256 - -/* - * fwserial_list: list of every fw_serial created for each fw_card - * See discussion in fwserial_probe. - */ -static LIST_HEAD(fwserial_list); -static DEFINE_MUTEX(fwserial_list_mutex); - -/* - * port_table: array of tty ports allocated to each fw_card - * - * tty ports are allocated during probe when an fw_serial is first - * created for a given fw_card. Ports are allocated in a contiguous block, - * each block consisting of 'num_ports' ports. - */ -static struct fwtty_port *port_table[MAX_TOTAL_PORTS]; -static DEFINE_MUTEX(port_table_lock); -static bool port_table_corrupt; -#define FWTTY_INVALID_INDEX MAX_TOTAL_PORTS - -#define loop_idx(port) (((port)->index) / num_ports) -#define table_idx(loop) ((loop) * num_ports + num_ttys) - -/* total # of tty ports created per fw_card */ -static int num_ports; - -/* slab used as pool for struct fwtty_transactions */ -static struct kmem_cache *fwtty_txn_cache; - -struct tty_driver *fwtty_driver; -static struct tty_driver *fwloop_driver; - -static struct dentry *fwserial_debugfs; - -struct fwtty_transaction; -typedef void (*fwtty_transaction_cb)(struct fw_card *card, int rcode, - void *data, size_t length, - struct fwtty_transaction *txn); - -struct fwtty_transaction { - struct fw_transaction fw_txn; - fwtty_transaction_cb callback; - struct fwtty_port *port; - union { - struct dma_pending dma_pended; - }; -}; - -#define to_device(a, b) (a->b) -#define fwtty_err(p, fmt, ...) \ - dev_err(to_device(p, device), fmt, ##__VA_ARGS__) -#define fwtty_info(p, fmt, ...) \ - dev_info(to_device(p, device), fmt, ##__VA_ARGS__) -#define fwtty_notice(p, fmt, ...) \ - dev_notice(to_device(p, device), fmt, ##__VA_ARGS__) -#define fwtty_dbg(p, fmt, ...) \ - dev_dbg(to_device(p, device), "%s: " fmt, __func__, ##__VA_ARGS__) -#define fwtty_err_ratelimited(p, fmt, ...) \ - dev_err_ratelimited(to_device(p, device), fmt, ##__VA_ARGS__) - -#ifdef DEBUG -static inline void debug_short_write(struct fwtty_port *port, int c, int n) -{ - int avail; - - if (n < c) { - spin_lock_bh(&port->lock); - avail = dma_fifo_avail(&port->tx_fifo); - spin_unlock_bh(&port->lock); - fwtty_dbg(port, "short write: avail:%d req:%d wrote:%d\n", - avail, c, n); - } -} -#else -#define debug_short_write(port, c, n) -#endif - -static struct fwtty_peer *__fwserial_peer_by_node_id(struct fw_card *card, - int generation, int id); - -#ifdef FWTTY_PROFILING - -static void fwtty_profile_fifo(struct fwtty_port *port, unsigned int *stat) -{ - spin_lock_bh(&port->lock); - fwtty_profile_data(stat, dma_fifo_avail(&port->tx_fifo)); - spin_unlock_bh(&port->lock); -} - -static void fwtty_dump_profile(struct seq_file *m, struct stats *stats) -{ - /* for each stat, print sum of 0 to 2^k, then individually */ - int k = 4; - unsigned int sum; - int j; - char t[10]; - - snprintf(t, 10, "< %d", 1 << k); - seq_printf(m, "\n%14s %6s", " ", t); - for (j = k + 1; j < DISTRIBUTION_MAX_INDEX; ++j) - seq_printf(m, "%6d", 1 << j); - - ++k; - for (j = 0, sum = 0; j <= k; ++j) - sum += stats->reads[j]; - seq_printf(m, "\n%14s: %6d", "reads", sum); - for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j) - seq_printf(m, "%6d", stats->reads[j]); - - for (j = 0, sum = 0; j <= k; ++j) - sum += stats->writes[j]; - seq_printf(m, "\n%14s: %6d", "writes", sum); - for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j) - seq_printf(m, "%6d", stats->writes[j]); - - for (j = 0, sum = 0; j <= k; ++j) - sum += stats->txns[j]; - seq_printf(m, "\n%14s: %6d", "txns", sum); - for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j) - seq_printf(m, "%6d", stats->txns[j]); - - for (j = 0, sum = 0; j <= k; ++j) - sum += stats->unthrottle[j]; - seq_printf(m, "\n%14s: %6d", "avail @ unthr", sum); - for (j = k + 1; j <= DISTRIBUTION_MAX_INDEX; ++j) - seq_printf(m, "%6d", stats->unthrottle[j]); -} - -#else -#define fwtty_profile_fifo(port, stat) -#define fwtty_dump_profile(m, stats) -#endif - -/* - * Returns the max receive packet size for the given node - * Devices which are OHCI v1.0/ v1.1/ v1.2-draft or RFC 2734 compliant - * are required by specification to support max_rec of 8 (512 bytes) or more. - */ -static inline int device_max_receive(struct fw_device *fw_device) -{ - /* see IEEE 1394-2008 table 8-8 */ - return min(2 << fw_device->max_rec, 4096); -} - -static void fwtty_log_tx_error(struct fwtty_port *port, int rcode) -{ - switch (rcode) { - case RCODE_SEND_ERROR: - fwtty_err_ratelimited(port, "card busy\n"); - break; - case RCODE_ADDRESS_ERROR: - fwtty_err_ratelimited(port, "bad unit addr or write length\n"); - break; - case RCODE_DATA_ERROR: - fwtty_err_ratelimited(port, "failed rx\n"); - break; - case RCODE_NO_ACK: - fwtty_err_ratelimited(port, "missing ack\n"); - break; - case RCODE_BUSY: - fwtty_err_ratelimited(port, "remote busy\n"); - break; - default: - fwtty_err_ratelimited(port, "failed tx: %d\n", rcode); - } -} - -static void fwtty_common_callback(struct fw_card *card, int rcode, - void *payload, size_t len, void *cb_data) -{ - struct fwtty_transaction *txn = cb_data; - struct fwtty_port *port = txn->port; - - if (port && rcode != RCODE_COMPLETE) - fwtty_log_tx_error(port, rcode); - if (txn->callback) - txn->callback(card, rcode, payload, len, txn); - kmem_cache_free(fwtty_txn_cache, txn); -} - -static int fwtty_send_data_async(struct fwtty_peer *peer, int tcode, - unsigned long long addr, void *payload, - size_t len, fwtty_transaction_cb callback, - struct fwtty_port *port) -{ - struct fwtty_transaction *txn; - int generation; - - txn = kmem_cache_alloc(fwtty_txn_cache, GFP_ATOMIC); - if (!txn) - return -ENOMEM; - - txn->callback = callback; - txn->port = port; - - generation = peer->generation; - smp_rmb(); - fw_send_request(peer->serial->card, &txn->fw_txn, tcode, - peer->node_id, generation, peer->speed, addr, payload, - len, fwtty_common_callback, txn); - return 0; -} - -static void fwtty_send_txn_async(struct fwtty_peer *peer, - struct fwtty_transaction *txn, int tcode, - unsigned long long addr, void *payload, - size_t len, fwtty_transaction_cb callback, - struct fwtty_port *port) -{ - int generation; - - txn->callback = callback; - txn->port = port; - - generation = peer->generation; - smp_rmb(); - fw_send_request(peer->serial->card, &txn->fw_txn, tcode, - peer->node_id, generation, peer->speed, addr, payload, - len, fwtty_common_callback, txn); -} - -static void __fwtty_restart_tx(struct fwtty_port *port) -{ - int len, avail; - - len = dma_fifo_out_level(&port->tx_fifo); - if (len) - schedule_delayed_work(&port->drain, 0); - avail = dma_fifo_avail(&port->tx_fifo); - - fwtty_dbg(port, "fifo len: %d avail: %d\n", len, avail); -} - -static void fwtty_restart_tx(struct fwtty_port *port) -{ - spin_lock_bh(&port->lock); - __fwtty_restart_tx(port); - spin_unlock_bh(&port->lock); -} - -/* - * fwtty_update_port_status - decodes & dispatches line status changes - * - * Note: in loopback, the port->lock is being held. Only use functions that - * don't attempt to reclaim the port->lock. - */ -static void fwtty_update_port_status(struct fwtty_port *port, - unsigned int status) -{ - unsigned int delta; - struct tty_struct *tty; - - /* simulated LSR/MSR status from remote */ - status &= ~MCTRL_MASK; - delta = (port->mstatus ^ status) & ~MCTRL_MASK; - delta &= ~(status & TIOCM_RNG); - port->mstatus = status; - - if (delta & TIOCM_RNG) - ++port->icount.rng; - if (delta & TIOCM_DSR) - ++port->icount.dsr; - if (delta & TIOCM_CAR) - ++port->icount.dcd; - if (delta & TIOCM_CTS) - ++port->icount.cts; - - fwtty_dbg(port, "status: %x delta: %x\n", status, delta); - - if (delta & TIOCM_CAR) { - tty = tty_port_tty_get(&port->port); - if (tty && !C_CLOCAL(tty)) { - if (status & TIOCM_CAR) - wake_up_interruptible(&port->port.open_wait); - else - schedule_work(&port->hangup); - } - tty_kref_put(tty); - } - - if (delta & TIOCM_CTS) { - tty = tty_port_tty_get(&port->port); - if (tty && C_CRTSCTS(tty)) { - if (tty->hw_stopped) { - if (status & TIOCM_CTS) { - tty->hw_stopped = 0; - if (port->loopback) - __fwtty_restart_tx(port); - else - fwtty_restart_tx(port); - } - } else { - if (~status & TIOCM_CTS) - tty->hw_stopped = 1; - } - } - tty_kref_put(tty); - - } else if (delta & OOB_TX_THROTTLE) { - tty = tty_port_tty_get(&port->port); - if (tty) { - if (tty->hw_stopped) { - if (~status & OOB_TX_THROTTLE) { - tty->hw_stopped = 0; - if (port->loopback) - __fwtty_restart_tx(port); - else - fwtty_restart_tx(port); - } - } else { - if (status & OOB_TX_THROTTLE) - tty->hw_stopped = 1; - } - } - tty_kref_put(tty); - } - - if (delta & (UART_LSR_BI << 24)) { - if (status & (UART_LSR_BI << 24)) { - port->break_last = jiffies; - schedule_delayed_work(&port->emit_breaks, 0); - } else { - /* run emit_breaks one last time (if pending) */ - mod_delayed_work(system_wq, &port->emit_breaks, 0); - } - } - - if (delta & (TIOCM_DSR | TIOCM_CAR | TIOCM_CTS | TIOCM_RNG)) - wake_up_interruptible(&port->port.delta_msr_wait); -} - -/* - * __fwtty_port_line_status - generate 'line status' for indicated port - * - * This function returns a remote 'MSR' state based on the local 'MCR' state, - * as if a null modem cable was attached. The actual status is a mangling - * of TIOCM_* bits suitable for sending to a peer's status_addr. - * - * Note: caller must be holding port lock - */ -static unsigned int __fwtty_port_line_status(struct fwtty_port *port) -{ - unsigned int status = 0; - - /* TODO: add module param to tie RNG to DTR as well */ - - if (port->mctrl & TIOCM_DTR) - status |= TIOCM_DSR | TIOCM_CAR; - if (port->mctrl & TIOCM_RTS) - status |= TIOCM_CTS; - if (port->mctrl & OOB_RX_THROTTLE) - status |= OOB_TX_THROTTLE; - /* emulate BRK as add'l line status */ - if (port->break_ctl) - status |= UART_LSR_BI << 24; - - return status; -} - -/* - * __fwtty_write_port_status - send the port line status to peer - * - * Note: caller must be holding the port lock. - */ -static int __fwtty_write_port_status(struct fwtty_port *port) -{ - struct fwtty_peer *peer; - int err = -ENOENT; - unsigned int status = __fwtty_port_line_status(port); - - rcu_read_lock(); - peer = rcu_dereference(port->peer); - if (peer) { - err = fwtty_send_data_async(peer, TCODE_WRITE_QUADLET_REQUEST, - peer->status_addr, &status, - sizeof(status), NULL, port); - } - rcu_read_unlock(); - - return err; -} - -/* - * fwtty_write_port_status - same as above but locked by port lock - */ -static int fwtty_write_port_status(struct fwtty_port *port) -{ - int err; - - spin_lock_bh(&port->lock); - err = __fwtty_write_port_status(port); - spin_unlock_bh(&port->lock); - return err; -} - -static void fwtty_throttle_port(struct fwtty_port *port) -{ - struct tty_struct *tty; - unsigned int old; - - tty = tty_port_tty_get(&port->port); - if (!tty) - return; - - spin_lock_bh(&port->lock); - - old = port->mctrl; - port->mctrl |= OOB_RX_THROTTLE; - if (C_CRTSCTS(tty)) - port->mctrl &= ~TIOCM_RTS; - if (~old & OOB_RX_THROTTLE) - __fwtty_write_port_status(port); - - spin_unlock_bh(&port->lock); - - tty_kref_put(tty); -} - -/* - * fwtty_do_hangup - wait for ldisc to deliver all pending rx; only then hangup - * - * When the remote has finished tx, and all in-flight rx has been received and - * pushed to the flip buffer, the remote may close its device. This will - * drop DTR on the remote which will drop carrier here. Typically, the tty is - * hung up when carrier is dropped or lost. - * - * However, there is a race between the hang up and the line discipline - * delivering its data to the reader. A hangup will cause the ldisc to flush - * (ie., clear) the read buffer and flip buffer. Because of firewire's - * relatively high throughput, the ldisc frequently lags well behind the driver, - * resulting in lost data (which has already been received and written to - * the flip buffer) when the remote closes its end. - * - * Unfortunately, since the flip buffer offers no direct method for determining - * if it holds data, ensuring the ldisc has delivered all data is problematic. - */ - -/* FIXME: drop this workaround when __tty_hangup waits for ldisc completion */ -static void fwtty_do_hangup(struct work_struct *work) -{ - struct fwtty_port *port = to_port(work, hangup); - struct tty_struct *tty; - - schedule_timeout_uninterruptible(msecs_to_jiffies(50)); - - tty = tty_port_tty_get(&port->port); - if (tty) - tty_vhangup(tty); - tty_kref_put(tty); -} - -static void fwtty_emit_breaks(struct work_struct *work) -{ - struct fwtty_port *port = to_port(to_delayed_work(work), emit_breaks); - static const char buf[16]; - unsigned long now = jiffies; - unsigned long elapsed = now - port->break_last; - int n, t, c, brk = 0; - - /* generate breaks at the line rate (but at least 1) */ - n = (elapsed * port->cps) / HZ + 1; - port->break_last = now; - - fwtty_dbg(port, "sending %d brks\n", n); - - while (n) { - t = min(n, 16); - c = tty_insert_flip_string_fixed_flag(&port->port, buf, - TTY_BREAK, t); - n -= c; - brk += c; - if (c < t) - break; - } - tty_flip_buffer_push(&port->port); - - if (port->mstatus & (UART_LSR_BI << 24)) - schedule_delayed_work(&port->emit_breaks, FREQ_BREAKS); - port->icount.brk += brk; -} - -static int fwtty_rx(struct fwtty_port *port, unsigned char *data, size_t len) -{ - int c, n = len; - unsigned int lsr; - int err = 0; - - fwtty_dbg(port, "%d\n", n); - fwtty_profile_data(port->stats.reads, n); - - if (port->write_only) { - n = 0; - goto out; - } - - /* disregard break status; breaks are generated by emit_breaks work */ - lsr = (port->mstatus >> 24) & ~UART_LSR_BI; - - if (port->overrun) - lsr |= UART_LSR_OE; - - if (lsr & UART_LSR_OE) - ++port->icount.overrun; - - lsr &= port->status_mask; - if (lsr & ~port->ignore_mask & UART_LSR_OE) { - if (!tty_insert_flip_char(&port->port, 0, TTY_OVERRUN)) { - err = -EIO; - goto out; - } - } - port->overrun = false; - - if (lsr & port->ignore_mask & ~UART_LSR_OE) { - /* TODO: don't drop SAK and Magic SysRq here */ - n = 0; - goto out; - } - - c = tty_insert_flip_string_fixed_flag(&port->port, data, TTY_NORMAL, n); - if (c > 0) - tty_flip_buffer_push(&port->port); - n -= c; - - if (n) { - port->overrun = true; - err = -EIO; - fwtty_err_ratelimited(port, "flip buffer overrun\n"); - - } else { - /* throttle the sender if remaining flip buffer space has - * reached high watermark to avoid losing data which may be - * in-flight. Since the AR request context is 32k, that much - * data may have _already_ been acked. - */ - if (tty_buffer_space_avail(&port->port) < HIGH_WATERMARK) - fwtty_throttle_port(port); - } - -out: - port->icount.rx += len; - port->stats.lost += n; - return err; -} - -/* - * fwtty_port_handler - bus address handler for port reads/writes - * - * This handler is responsible for handling inbound read/write dma from remotes. - */ -static void fwtty_port_handler(struct fw_card *card, - struct fw_request *request, - int tcode, int destination, int source, - int generation, - unsigned long long addr, - void *data, size_t len, - void *callback_data) -{ - struct fwtty_port *port = callback_data; - struct fwtty_peer *peer; - int err; - int rcode; - - /* Only accept rx from the peer virtual-cabled to this port */ - rcu_read_lock(); - peer = __fwserial_peer_by_node_id(card, generation, source); - rcu_read_unlock(); - if (!peer || peer != rcu_access_pointer(port->peer)) { - rcode = RCODE_ADDRESS_ERROR; - fwtty_err_ratelimited(port, "ignoring unauthenticated data\n"); - goto respond; - } - - switch (tcode) { - case TCODE_WRITE_QUADLET_REQUEST: - if (addr != port->rx_handler.offset || len != 4) { - rcode = RCODE_ADDRESS_ERROR; - } else { - fwtty_update_port_status(port, *(unsigned int *)data); - rcode = RCODE_COMPLETE; - } - break; - - case TCODE_WRITE_BLOCK_REQUEST: - if (addr != port->rx_handler.offset + 4 || - len > port->rx_handler.length - 4) { - rcode = RCODE_ADDRESS_ERROR; - } else { - err = fwtty_rx(port, data, len); - switch (err) { - case 0: - rcode = RCODE_COMPLETE; - break; - case -EIO: - rcode = RCODE_DATA_ERROR; - break; - default: - rcode = RCODE_CONFLICT_ERROR; - break; - } - } - break; - - default: - rcode = RCODE_TYPE_ERROR; - } - -respond: - fw_send_response(card, request, rcode); -} - -/* - * fwtty_tx_complete - callback for tx dma - * @data: ignored, has no meaning for write txns - * @length: ignored, has no meaning for write txns - * - * The writer must be woken here if the fifo has been emptied because it - * may have slept if chars_in_buffer was != 0 - */ -static void fwtty_tx_complete(struct fw_card *card, int rcode, - void *data, size_t length, - struct fwtty_transaction *txn) -{ - struct fwtty_port *port = txn->port; - int len; - - fwtty_dbg(port, "rcode: %d\n", rcode); - - switch (rcode) { - case RCODE_COMPLETE: - spin_lock_bh(&port->lock); - dma_fifo_out_complete(&port->tx_fifo, &txn->dma_pended); - len = dma_fifo_level(&port->tx_fifo); - spin_unlock_bh(&port->lock); - - port->icount.tx += txn->dma_pended.len; - break; - - default: - /* TODO: implement retries */ - spin_lock_bh(&port->lock); - dma_fifo_out_complete(&port->tx_fifo, &txn->dma_pended); - len = dma_fifo_level(&port->tx_fifo); - spin_unlock_bh(&port->lock); - - port->stats.dropped += txn->dma_pended.len; - } - - if (len < WAKEUP_CHARS) - tty_port_tty_wakeup(&port->port); -} - -static int fwtty_tx(struct fwtty_port *port, bool drain) -{ - struct fwtty_peer *peer; - struct fwtty_transaction *txn; - struct tty_struct *tty; - int n, len; - - tty = tty_port_tty_get(&port->port); - if (!tty) - return -ENOENT; - - rcu_read_lock(); - peer = rcu_dereference(port->peer); - if (!peer) { - n = -EIO; - goto out; - } - - if (test_and_set_bit(IN_TX, &port->flags)) { - n = -EALREADY; - goto out; - } - - /* try to write as many dma transactions out as possible */ - n = -EAGAIN; - while (!tty->flow.stopped && !tty->hw_stopped && - !test_bit(STOP_TX, &port->flags)) { - txn = kmem_cache_alloc(fwtty_txn_cache, GFP_ATOMIC); - if (!txn) { - n = -ENOMEM; - break; - } - - spin_lock_bh(&port->lock); - n = dma_fifo_out_pend(&port->tx_fifo, &txn->dma_pended); - spin_unlock_bh(&port->lock); - - fwtty_dbg(port, "out: %u rem: %d\n", txn->dma_pended.len, n); - - if (n < 0) { - kmem_cache_free(fwtty_txn_cache, txn); - if (n == -EAGAIN) { - ++port->stats.tx_stall; - } else if (n == -ENODATA) { - fwtty_profile_data(port->stats.txns, 0); - } else { - ++port->stats.fifo_errs; - fwtty_err_ratelimited(port, "fifo err: %d\n", - n); - } - break; - } - - fwtty_profile_data(port->stats.txns, txn->dma_pended.len); - - fwtty_send_txn_async(peer, txn, TCODE_WRITE_BLOCK_REQUEST, - peer->fifo_addr, txn->dma_pended.data, - txn->dma_pended.len, fwtty_tx_complete, - port); - ++port->stats.sent; - - /* - * Stop tx if the 'last view' of the fifo is empty or if - * this is the writer and there's not enough data to bother - */ - if (n == 0 || (!drain && n < WRITER_MINIMUM)) - break; - } - - if (n >= 0 || n == -EAGAIN || n == -ENOMEM || n == -ENODATA) { - spin_lock_bh(&port->lock); - len = dma_fifo_out_level(&port->tx_fifo); - if (len) { - unsigned long delay = (n == -ENOMEM) ? HZ : 1; - - schedule_delayed_work(&port->drain, delay); - } - len = dma_fifo_level(&port->tx_fifo); - spin_unlock_bh(&port->lock); - - /* wakeup the writer */ - if (drain && len < WAKEUP_CHARS) - tty_wakeup(tty); - } - - clear_bit(IN_TX, &port->flags); - wake_up_interruptible(&port->wait_tx); - -out: - rcu_read_unlock(); - tty_kref_put(tty); - return n; -} - -static void fwtty_drain_tx(struct work_struct *work) -{ - struct fwtty_port *port = to_port(to_delayed_work(work), drain); - - fwtty_tx(port, true); -} - -static void fwtty_write_xchar(struct fwtty_port *port, char ch) -{ - struct fwtty_peer *peer; - - ++port->stats.xchars; - - fwtty_dbg(port, "%02x\n", ch); - - rcu_read_lock(); - peer = rcu_dereference(port->peer); - if (peer) { - fwtty_send_data_async(peer, TCODE_WRITE_BLOCK_REQUEST, - peer->fifo_addr, &ch, sizeof(ch), - NULL, port); - } - rcu_read_unlock(); -} - -static struct fwtty_port *fwtty_port_get(unsigned int index) -{ - struct fwtty_port *port; - - if (index >= MAX_TOTAL_PORTS) - return NULL; - - mutex_lock(&port_table_lock); - port = port_table[index]; - if (port) - kref_get(&port->serial->kref); - mutex_unlock(&port_table_lock); - return port; -} - -static int fwtty_ports_add(struct fw_serial *serial) -{ - int err = -EBUSY; - int i, j; - - if (port_table_corrupt) - return err; - - mutex_lock(&port_table_lock); - for (i = 0; i + num_ports <= MAX_TOTAL_PORTS; i += num_ports) { - if (!port_table[i]) { - for (j = 0; j < num_ports; ++i, ++j) { - serial->ports[j]->index = i; - port_table[i] = serial->ports[j]; - } - err = 0; - break; - } - } - mutex_unlock(&port_table_lock); - return err; -} - -static void fwserial_destroy(struct kref *kref) -{ - struct fw_serial *serial = to_serial(kref, kref); - struct fwtty_port **ports = serial->ports; - int j, i = ports[0]->index; - - synchronize_rcu(); - - mutex_lock(&port_table_lock); - for (j = 0; j < num_ports; ++i, ++j) { - port_table_corrupt |= port_table[i] != ports[j]; - WARN_ONCE(port_table_corrupt, "port_table[%d]: %p != ports[%d]: %p", - i, port_table[i], j, ports[j]); - - port_table[i] = NULL; - } - mutex_unlock(&port_table_lock); - - for (j = 0; j < num_ports; ++j) { - fw_core_remove_address_handler(&ports[j]->rx_handler); - tty_port_destroy(&ports[j]->port); - kfree(ports[j]); - } - kfree(serial); -} - -static void fwtty_port_put(struct fwtty_port *port) -{ - kref_put(&port->serial->kref, fwserial_destroy); -} - -static void fwtty_port_dtr_rts(struct tty_port *tty_port, int on) -{ - struct fwtty_port *port = to_port(tty_port, port); - - fwtty_dbg(port, "on/off: %d\n", on); - - spin_lock_bh(&port->lock); - /* Don't change carrier state if this is a console */ - if (!port->port.console) { - if (on) - port->mctrl |= TIOCM_DTR | TIOCM_RTS; - else - port->mctrl &= ~(TIOCM_DTR | TIOCM_RTS); - } - - __fwtty_write_port_status(port); - spin_unlock_bh(&port->lock); -} - -/* - * fwtty_port_carrier_raised: required tty_port operation - * - * This port operation is polled after a tty has been opened and is waiting for - * carrier detect -- see drivers/tty/tty_port:tty_port_block_til_ready(). - */ -static int fwtty_port_carrier_raised(struct tty_port *tty_port) -{ - struct fwtty_port *port = to_port(tty_port, port); - int rc; - - rc = (port->mstatus & TIOCM_CAR); - - fwtty_dbg(port, "%d\n", rc); - - return rc; -} - -static unsigned int set_termios(struct fwtty_port *port, struct tty_struct *tty) -{ - unsigned int baud, frame; - - baud = tty_termios_baud_rate(&tty->termios); - tty_termios_encode_baud_rate(&tty->termios, baud, baud); - - /* compute bit count of 2 frames */ - frame = 12 + ((C_CSTOPB(tty)) ? 4 : 2) + ((C_PARENB(tty)) ? 2 : 0); - - switch (C_CSIZE(tty)) { - case CS5: - frame -= (C_CSTOPB(tty)) ? 1 : 0; - break; - case CS6: - frame += 2; - break; - case CS7: - frame += 4; - break; - case CS8: - frame += 6; - break; - } - - port->cps = (baud << 1) / frame; - - port->status_mask = UART_LSR_OE; - if (_I_FLAG(tty, BRKINT | PARMRK)) - port->status_mask |= UART_LSR_BI; - - port->ignore_mask = 0; - if (I_IGNBRK(tty)) { - port->ignore_mask |= UART_LSR_BI; - if (I_IGNPAR(tty)) - port->ignore_mask |= UART_LSR_OE; - } - - port->write_only = !C_CREAD(tty); - - /* turn off echo and newline xlat if loopback */ - if (port->loopback) { - tty->termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHOKE | - ECHONL | ECHOPRT | ECHOCTL); - tty->termios.c_oflag &= ~ONLCR; - } - - return baud; -} - -static int fwtty_port_activate(struct tty_port *tty_port, - struct tty_struct *tty) -{ - struct fwtty_port *port = to_port(tty_port, port); - unsigned int baud; - int err; - - set_bit(TTY_IO_ERROR, &tty->flags); - - err = dma_fifo_alloc(&port->tx_fifo, FWTTY_PORT_TXFIFO_LEN, - cache_line_size(), - port->max_payload, - FWTTY_PORT_MAX_PEND_DMA, - GFP_KERNEL); - if (err) - return err; - - spin_lock_bh(&port->lock); - - baud = set_termios(port, tty); - - /* if console, don't change carrier state */ - if (!port->port.console) { - port->mctrl = 0; - if (baud != 0) - port->mctrl = TIOCM_DTR | TIOCM_RTS; - } - - if (C_CRTSCTS(tty) && ~port->mstatus & TIOCM_CTS) - tty->hw_stopped = 1; - - __fwtty_write_port_status(port); - spin_unlock_bh(&port->lock); - - clear_bit(TTY_IO_ERROR, &tty->flags); - - return 0; -} - -/* - * fwtty_port_shutdown - * - * Note: the tty port core ensures this is not the console and - * manages TTY_IO_ERROR properly - */ -static void fwtty_port_shutdown(struct tty_port *tty_port) -{ - struct fwtty_port *port = to_port(tty_port, port); - - /* TODO: cancel outstanding transactions */ - - cancel_delayed_work_sync(&port->emit_breaks); - cancel_delayed_work_sync(&port->drain); - - spin_lock_bh(&port->lock); - port->flags = 0; - port->break_ctl = 0; - port->overrun = 0; - __fwtty_write_port_status(port); - dma_fifo_free(&port->tx_fifo); - spin_unlock_bh(&port->lock); -} - -static int fwtty_open(struct tty_struct *tty, struct file *fp) -{ - struct fwtty_port *port = tty->driver_data; - - return tty_port_open(&port->port, tty, fp); -} - -static void fwtty_close(struct tty_struct *tty, struct file *fp) -{ - struct fwtty_port *port = tty->driver_data; - - tty_port_close(&port->port, tty, fp); -} - -static void fwtty_hangup(struct tty_struct *tty) -{ - struct fwtty_port *port = tty->driver_data; - - tty_port_hangup(&port->port); -} - -static void fwtty_cleanup(struct tty_struct *tty) -{ - struct fwtty_port *port = tty->driver_data; - - tty->driver_data = NULL; - fwtty_port_put(port); -} - -static int fwtty_install(struct tty_driver *driver, struct tty_struct *tty) -{ - struct fwtty_port *port = fwtty_port_get(tty->index); - int err; - - err = tty_standard_install(driver, tty); - if (!err) - tty->driver_data = port; - else - fwtty_port_put(port); - return err; -} - -static int fwloop_install(struct tty_driver *driver, struct tty_struct *tty) -{ - struct fwtty_port *port = fwtty_port_get(table_idx(tty->index)); - int err; - - err = tty_standard_install(driver, tty); - if (!err) - tty->driver_data = port; - else - fwtty_port_put(port); - return err; -} - -static int fwtty_write(struct tty_struct *tty, const unsigned char *buf, int c) -{ - struct fwtty_port *port = tty->driver_data; - int n, len; - - fwtty_dbg(port, "%d\n", c); - fwtty_profile_data(port->stats.writes, c); - - spin_lock_bh(&port->lock); - n = dma_fifo_in(&port->tx_fifo, buf, c); - len = dma_fifo_out_level(&port->tx_fifo); - if (len < DRAIN_THRESHOLD) - schedule_delayed_work(&port->drain, 1); - spin_unlock_bh(&port->lock); - - if (len >= DRAIN_THRESHOLD) - fwtty_tx(port, false); - - debug_short_write(port, c, n); - - return (n < 0) ? 0 : n; -} - -static unsigned int fwtty_write_room(struct tty_struct *tty) -{ - struct fwtty_port *port = tty->driver_data; - unsigned int n; - - spin_lock_bh(&port->lock); - n = dma_fifo_avail(&port->tx_fifo); - spin_unlock_bh(&port->lock); - - fwtty_dbg(port, "%u\n", n); - - return n; -} - -static unsigned int fwtty_chars_in_buffer(struct tty_struct *tty) -{ - struct fwtty_port *port = tty->driver_data; - unsigned int n; - - spin_lock_bh(&port->lock); - n = dma_fifo_level(&port->tx_fifo); - spin_unlock_bh(&port->lock); - - fwtty_dbg(port, "%u\n", n); - - return n; -} - -static void fwtty_send_xchar(struct tty_struct *tty, char ch) -{ - struct fwtty_port *port = tty->driver_data; - - fwtty_dbg(port, "%02x\n", ch); - - fwtty_write_xchar(port, ch); -} - -static void fwtty_throttle(struct tty_struct *tty) -{ - struct fwtty_port *port = tty->driver_data; - - /* - * Ignore throttling (but not unthrottling). - * It only makes sense to throttle when data will no longer be - * accepted by the tty flip buffer. For example, it is - * possible for received data to overflow the tty buffer long - * before the line discipline ever has a chance to throttle the driver. - * Additionally, the driver may have already completed the I/O - * but the tty buffer is still emptying, so the line discipline is - * throttling and unthrottling nothing. - */ - - ++port->stats.throttled; -} - -static void fwtty_unthrottle(struct tty_struct *tty) -{ - struct fwtty_port *port = tty->driver_data; - - fwtty_dbg(port, "CRTSCTS: %d\n", C_CRTSCTS(tty) != 0); - - fwtty_profile_fifo(port, port->stats.unthrottle); - - spin_lock_bh(&port->lock); - port->mctrl &= ~OOB_RX_THROTTLE; - if (C_CRTSCTS(tty)) - port->mctrl |= TIOCM_RTS; - __fwtty_write_port_status(port); - spin_unlock_bh(&port->lock); -} - -static int check_msr_delta(struct fwtty_port *port, unsigned long mask, - struct async_icount *prev) -{ - struct async_icount now; - int delta; - - now = port->icount; - - delta = ((mask & TIOCM_RNG && prev->rng != now.rng) || - (mask & TIOCM_DSR && prev->dsr != now.dsr) || - (mask & TIOCM_CAR && prev->dcd != now.dcd) || - (mask & TIOCM_CTS && prev->cts != now.cts)); - - *prev = now; - - return delta; -} - -static int wait_msr_change(struct fwtty_port *port, unsigned long mask) -{ - struct async_icount prev; - - prev = port->icount; - - return wait_event_interruptible(port->port.delta_msr_wait, - check_msr_delta(port, mask, &prev)); -} - -static int get_serial_info(struct tty_struct *tty, - struct serial_struct *ss) -{ - struct fwtty_port *port = tty->driver_data; - - mutex_lock(&port->port.mutex); - ss->line = port->index; - ss->baud_base = 400000000; - ss->close_delay = jiffies_to_msecs(port->port.close_delay) / 10; - ss->closing_wait = 3000; - mutex_unlock(&port->port.mutex); - - return 0; -} - -static int set_serial_info(struct tty_struct *tty, - struct serial_struct *ss) -{ - struct fwtty_port *port = tty->driver_data; - unsigned int cdelay; - - cdelay = msecs_to_jiffies(ss->close_delay * 10); - - mutex_lock(&port->port.mutex); - if (!capable(CAP_SYS_ADMIN)) { - if (cdelay != port->port.close_delay || - ((ss->flags & ~ASYNC_USR_MASK) != - (port->port.flags & ~ASYNC_USR_MASK))) { - mutex_unlock(&port->port.mutex); - return -EPERM; - } - } - port->port.close_delay = cdelay; - mutex_unlock(&port->port.mutex); - - return 0; -} - -static int fwtty_ioctl(struct tty_struct *tty, unsigned int cmd, - unsigned long arg) -{ - struct fwtty_port *port = tty->driver_data; - int err; - - switch (cmd) { - case TIOCMIWAIT: - err = wait_msr_change(port, arg); - break; - - default: - err = -ENOIOCTLCMD; - } - - return err; -} - -static void fwtty_set_termios(struct tty_struct *tty, struct ktermios *old) -{ - struct fwtty_port *port = tty->driver_data; - unsigned int baud; - - spin_lock_bh(&port->lock); - baud = set_termios(port, tty); - - if ((baud == 0) && (old->c_cflag & CBAUD)) { - port->mctrl &= ~(TIOCM_DTR | TIOCM_RTS); - } else if ((baud != 0) && !(old->c_cflag & CBAUD)) { - if (C_CRTSCTS(tty) || !tty_throttled(tty)) - port->mctrl |= TIOCM_DTR | TIOCM_RTS; - else - port->mctrl |= TIOCM_DTR; - } - __fwtty_write_port_status(port); - spin_unlock_bh(&port->lock); - - if (old->c_cflag & CRTSCTS) { - if (!C_CRTSCTS(tty)) { - tty->hw_stopped = 0; - fwtty_restart_tx(port); - } - } else if (C_CRTSCTS(tty) && ~port->mstatus & TIOCM_CTS) { - tty->hw_stopped = 1; - } -} - -/* - * fwtty_break_ctl - start/stop sending breaks - * - * Signals the remote to start or stop generating simulated breaks. - * First, stop dequeueing from the fifo and wait for writer/drain to leave tx - * before signalling the break line status. This guarantees any pending rx will - * be queued to the line discipline before break is simulated on the remote. - * Conversely, turning off break_ctl requires signalling the line status change, - * then enabling tx. - */ -static int fwtty_break_ctl(struct tty_struct *tty, int state) -{ - struct fwtty_port *port = tty->driver_data; - long ret; - - fwtty_dbg(port, "%d\n", state); - - if (state == -1) { - set_bit(STOP_TX, &port->flags); - ret = wait_event_interruptible_timeout(port->wait_tx, - !test_bit(IN_TX, &port->flags), - 10); - if (ret == 0 || ret == -ERESTARTSYS) { - clear_bit(STOP_TX, &port->flags); - fwtty_restart_tx(port); - return -EINTR; - } - } - - spin_lock_bh(&port->lock); - port->break_ctl = (state == -1); - __fwtty_write_port_status(port); - spin_unlock_bh(&port->lock); - - if (state == 0) { - spin_lock_bh(&port->lock); - dma_fifo_reset(&port->tx_fifo); - clear_bit(STOP_TX, &port->flags); - spin_unlock_bh(&port->lock); - } - return 0; -} - -static int fwtty_tiocmget(struct tty_struct *tty) -{ - struct fwtty_port *port = tty->driver_data; - unsigned int tiocm; - - spin_lock_bh(&port->lock); - tiocm = (port->mctrl & MCTRL_MASK) | (port->mstatus & ~MCTRL_MASK); - spin_unlock_bh(&port->lock); - - fwtty_dbg(port, "%x\n", tiocm); - - return tiocm; -} - -static int fwtty_tiocmset(struct tty_struct *tty, - unsigned int set, unsigned int clear) -{ - struct fwtty_port *port = tty->driver_data; - - fwtty_dbg(port, "set: %x clear: %x\n", set, clear); - - /* TODO: simulate loopback if TIOCM_LOOP set */ - - spin_lock_bh(&port->lock); - port->mctrl &= ~(clear & MCTRL_MASK & 0xffff); - port->mctrl |= set & MCTRL_MASK & 0xffff; - __fwtty_write_port_status(port); - spin_unlock_bh(&port->lock); - return 0; -} - -static int fwtty_get_icount(struct tty_struct *tty, - struct serial_icounter_struct *icount) -{ - struct fwtty_port *port = tty->driver_data; - struct stats stats; - - memcpy(&stats, &port->stats, sizeof(stats)); - if (port->port.console) - (*port->fwcon_ops->stats)(&stats, port->con_data); - - icount->cts = port->icount.cts; - icount->dsr = port->icount.dsr; - icount->rng = port->icount.rng; - icount->dcd = port->icount.dcd; - icount->rx = port->icount.rx; - icount->tx = port->icount.tx + stats.xchars; - icount->frame = port->icount.frame; - icount->overrun = port->icount.overrun; - icount->parity = port->icount.parity; - icount->brk = port->icount.brk; - icount->buf_overrun = port->icount.overrun; - return 0; -} - -static void fwtty_proc_show_port(struct seq_file *m, struct fwtty_port *port) -{ - struct stats stats; - - memcpy(&stats, &port->stats, sizeof(stats)); - if (port->port.console) - (*port->fwcon_ops->stats)(&stats, port->con_data); - - seq_printf(m, " addr:%012llx tx:%d rx:%d", port->rx_handler.offset, - port->icount.tx + stats.xchars, port->icount.rx); - seq_printf(m, " cts:%d dsr:%d rng:%d dcd:%d", port->icount.cts, - port->icount.dsr, port->icount.rng, port->icount.dcd); - seq_printf(m, " fe:%d oe:%d pe:%d brk:%d", port->icount.frame, - port->icount.overrun, port->icount.parity, port->icount.brk); -} - -static void fwtty_debugfs_show_port(struct seq_file *m, struct fwtty_port *port) -{ - struct stats stats; - - memcpy(&stats, &port->stats, sizeof(stats)); - if (port->port.console) - (*port->fwcon_ops->stats)(&stats, port->con_data); - - seq_printf(m, " dr:%d st:%d err:%d lost:%d", stats.dropped, - stats.tx_stall, stats.fifo_errs, stats.lost); - seq_printf(m, " pkts:%d thr:%d", stats.sent, stats.throttled); - - if (port->port.console) { - seq_puts(m, "\n "); - (*port->fwcon_ops->proc_show)(m, port->con_data); - } - - fwtty_dump_profile(m, &port->stats); -} - -static void fwtty_debugfs_show_peer(struct seq_file *m, struct fwtty_peer *peer) -{ - int generation = peer->generation; - - smp_rmb(); - seq_printf(m, " %s:", dev_name(&peer->unit->device)); - seq_printf(m, " node:%04x gen:%d", peer->node_id, generation); - seq_printf(m, " sp:%d max:%d guid:%016llx", peer->speed, - peer->max_payload, (unsigned long long)peer->guid); - seq_printf(m, " mgmt:%012llx", (unsigned long long)peer->mgmt_addr); - seq_printf(m, " addr:%012llx", (unsigned long long)peer->status_addr); - seq_putc(m, '\n'); -} - -static int fwtty_proc_show(struct seq_file *m, void *v) -{ - struct fwtty_port *port; - int i; - - seq_puts(m, "fwserinfo: 1.0 driver: 1.0\n"); - for (i = 0; i < MAX_TOTAL_PORTS && (port = fwtty_port_get(i)); ++i) { - seq_printf(m, "%2d:", i); - if (capable(CAP_SYS_ADMIN)) - fwtty_proc_show_port(m, port); - fwtty_port_put(port); - seq_puts(m, "\n"); - } - return 0; -} - -static int fwtty_stats_show(struct seq_file *m, void *v) -{ - struct fw_serial *serial = m->private; - struct fwtty_port *port; - int i; - - for (i = 0; i < num_ports; ++i) { - port = fwtty_port_get(serial->ports[i]->index); - if (port) { - seq_printf(m, "%2d:", port->index); - fwtty_proc_show_port(m, port); - fwtty_debugfs_show_port(m, port); - fwtty_port_put(port); - seq_puts(m, "\n"); - } - } - return 0; -} -DEFINE_SHOW_ATTRIBUTE(fwtty_stats); - -static int fwtty_peers_show(struct seq_file *m, void *v) -{ - struct fw_serial *serial = m->private; - struct fwtty_peer *peer; - - rcu_read_lock(); - seq_printf(m, "card: %s guid: %016llx\n", - dev_name(serial->card->device), - (unsigned long long)serial->card->guid); - list_for_each_entry_rcu(peer, &serial->peer_list, list) - fwtty_debugfs_show_peer(m, peer); - rcu_read_unlock(); - return 0; -} -DEFINE_SHOW_ATTRIBUTE(fwtty_peers); - -static const struct tty_port_operations fwtty_port_ops = { - .dtr_rts = fwtty_port_dtr_rts, - .carrier_raised = fwtty_port_carrier_raised, - .shutdown = fwtty_port_shutdown, - .activate = fwtty_port_activate, -}; - -static const struct tty_operations fwtty_ops = { - .open = fwtty_open, - .close = fwtty_close, - .hangup = fwtty_hangup, - .cleanup = fwtty_cleanup, - .install = fwtty_install, - .write = fwtty_write, - .write_room = fwtty_write_room, - .chars_in_buffer = fwtty_chars_in_buffer, - .send_xchar = fwtty_send_xchar, - .throttle = fwtty_throttle, - .unthrottle = fwtty_unthrottle, - .ioctl = fwtty_ioctl, - .set_termios = fwtty_set_termios, - .break_ctl = fwtty_break_ctl, - .tiocmget = fwtty_tiocmget, - .tiocmset = fwtty_tiocmset, - .get_icount = fwtty_get_icount, - .set_serial = set_serial_info, - .get_serial = get_serial_info, - .proc_show = fwtty_proc_show, -}; - -static const struct tty_operations fwloop_ops = { - .open = fwtty_open, - .close = fwtty_close, - .hangup = fwtty_hangup, - .cleanup = fwtty_cleanup, - .install = fwloop_install, - .write = fwtty_write, - .write_room = fwtty_write_room, - .chars_in_buffer = fwtty_chars_in_buffer, - .send_xchar = fwtty_send_xchar, - .throttle = fwtty_throttle, - .unthrottle = fwtty_unthrottle, - .ioctl = fwtty_ioctl, - .set_termios = fwtty_set_termios, - .break_ctl = fwtty_break_ctl, - .tiocmget = fwtty_tiocmget, - .tiocmset = fwtty_tiocmset, - .get_icount = fwtty_get_icount, - .set_serial = set_serial_info, - .get_serial = get_serial_info, -}; - -static inline int mgmt_pkt_expected_len(__be16 code) -{ - static const struct fwserial_mgmt_pkt pkt; - - switch (be16_to_cpu(code)) { - case FWSC_VIRT_CABLE_PLUG: - return sizeof(pkt.hdr) + sizeof(pkt.plug_req); - - case FWSC_VIRT_CABLE_PLUG_RSP: /* | FWSC_RSP_OK */ - return sizeof(pkt.hdr) + sizeof(pkt.plug_rsp); - - case FWSC_VIRT_CABLE_UNPLUG: - case FWSC_VIRT_CABLE_UNPLUG_RSP: - case FWSC_VIRT_CABLE_PLUG_RSP | FWSC_RSP_NACK: - case FWSC_VIRT_CABLE_UNPLUG_RSP | FWSC_RSP_NACK: - return sizeof(pkt.hdr); - - default: - return -1; - } -} - -static inline void fill_plug_params(struct virt_plug_params *params, - struct fwtty_port *port) -{ - u64 status_addr = port->rx_handler.offset; - u64 fifo_addr = port->rx_handler.offset + 4; - size_t fifo_len = port->rx_handler.length - 4; - - params->status_hi = cpu_to_be32(status_addr >> 32); - params->status_lo = cpu_to_be32(status_addr); - params->fifo_hi = cpu_to_be32(fifo_addr >> 32); - params->fifo_lo = cpu_to_be32(fifo_addr); - params->fifo_len = cpu_to_be32(fifo_len); -} - -static inline void fill_plug_req(struct fwserial_mgmt_pkt *pkt, - struct fwtty_port *port) -{ - pkt->hdr.code = cpu_to_be16(FWSC_VIRT_CABLE_PLUG); - pkt->hdr.len = cpu_to_be16(mgmt_pkt_expected_len(pkt->hdr.code)); - fill_plug_params(&pkt->plug_req, port); -} - -static inline void fill_plug_rsp_ok(struct fwserial_mgmt_pkt *pkt, - struct fwtty_port *port) -{ - pkt->hdr.code = cpu_to_be16(FWSC_VIRT_CABLE_PLUG_RSP); - pkt->hdr.len = cpu_to_be16(mgmt_pkt_expected_len(pkt->hdr.code)); - fill_plug_params(&pkt->plug_rsp, port); -} - -static inline void fill_plug_rsp_nack(struct fwserial_mgmt_pkt *pkt) -{ - pkt->hdr.code = cpu_to_be16(FWSC_VIRT_CABLE_PLUG_RSP | FWSC_RSP_NACK); - pkt->hdr.len = cpu_to_be16(mgmt_pkt_expected_len(pkt->hdr.code)); -} - -static inline void fill_unplug_rsp_nack(struct fwserial_mgmt_pkt *pkt) -{ - pkt->hdr.code = cpu_to_be16(FWSC_VIRT_CABLE_UNPLUG_RSP | FWSC_RSP_NACK); - pkt->hdr.len = cpu_to_be16(mgmt_pkt_expected_len(pkt->hdr.code)); -} - -static inline void fill_unplug_rsp_ok(struct fwserial_mgmt_pkt *pkt) -{ - pkt->hdr.code = cpu_to_be16(FWSC_VIRT_CABLE_UNPLUG_RSP); - pkt->hdr.len = cpu_to_be16(mgmt_pkt_expected_len(pkt->hdr.code)); -} - -static void fwserial_virt_plug_complete(struct fwtty_peer *peer, - struct virt_plug_params *params) -{ - struct fwtty_port *port = peer->port; - - peer->status_addr = be32_to_u64(params->status_hi, params->status_lo); - peer->fifo_addr = be32_to_u64(params->fifo_hi, params->fifo_lo); - peer->fifo_len = be32_to_cpu(params->fifo_len); - peer_set_state(peer, FWPS_ATTACHED); - - /* reconfigure tx_fifo optimally for this peer */ - spin_lock_bh(&port->lock); - port->max_payload = min(peer->max_payload, peer->fifo_len); - dma_fifo_change_tx_limit(&port->tx_fifo, port->max_payload); - spin_unlock_bh(&peer->port->lock); - - if (port->port.console && port->fwcon_ops->notify) - (*port->fwcon_ops->notify)(FWCON_NOTIFY_ATTACH, port->con_data); - - fwtty_info(&peer->unit, "peer (guid:%016llx) connected on %s\n", - (unsigned long long)peer->guid, dev_name(port->device)); -} - -static inline int fwserial_send_mgmt_sync(struct fwtty_peer *peer, - struct fwserial_mgmt_pkt *pkt) -{ - int generation; - int rcode, tries = 5; - - do { - generation = peer->generation; - smp_rmb(); - - rcode = fw_run_transaction(peer->serial->card, - TCODE_WRITE_BLOCK_REQUEST, - peer->node_id, - generation, peer->speed, - peer->mgmt_addr, - pkt, be16_to_cpu(pkt->hdr.len)); - if (rcode == RCODE_BUSY || rcode == RCODE_SEND_ERROR || - rcode == RCODE_GENERATION) { - fwtty_dbg(&peer->unit, "mgmt write error: %d\n", rcode); - continue; - } else { - break; - } - } while (--tries > 0); - return rcode; -} - -/* - * fwserial_claim_port - attempt to claim port @ index for peer - * - * Returns ptr to claimed port or error code (as ERR_PTR()) - * Can sleep - must be called from process context - */ -static struct fwtty_port *fwserial_claim_port(struct fwtty_peer *peer, - int index) -{ - struct fwtty_port *port; - - if (index < 0 || index >= num_ports) - return ERR_PTR(-EINVAL); - - /* must guarantee that previous port releases have completed */ - synchronize_rcu(); - - port = peer->serial->ports[index]; - spin_lock_bh(&port->lock); - if (!rcu_access_pointer(port->peer)) - rcu_assign_pointer(port->peer, peer); - else - port = ERR_PTR(-EBUSY); - spin_unlock_bh(&port->lock); - - return port; -} - -/* - * fwserial_find_port - find avail port and claim for peer - * - * Returns ptr to claimed port or NULL if none avail - * Can sleep - must be called from process context - */ -static struct fwtty_port *fwserial_find_port(struct fwtty_peer *peer) -{ - struct fwtty_port **ports = peer->serial->ports; - int i; - - /* must guarantee that previous port releases have completed */ - synchronize_rcu(); - - /* TODO: implement optional GUID-to-specific port # matching */ - - /* find an unattached port (but not the loopback port, if present) */ - for (i = 0; i < num_ttys; ++i) { - spin_lock_bh(&ports[i]->lock); - if (!ports[i]->peer) { - /* claim port */ - rcu_assign_pointer(ports[i]->peer, peer); - spin_unlock_bh(&ports[i]->lock); - return ports[i]; - } - spin_unlock_bh(&ports[i]->lock); - } - return NULL; -} - -static void fwserial_release_port(struct fwtty_port *port, bool reset) -{ - /* drop carrier (and all other line status) */ - if (reset) - fwtty_update_port_status(port, 0); - - spin_lock_bh(&port->lock); - - /* reset dma fifo max transmission size back to S100 */ - port->max_payload = link_speed_to_max_payload(SCODE_100); - dma_fifo_change_tx_limit(&port->tx_fifo, port->max_payload); - - RCU_INIT_POINTER(port->peer, NULL); - spin_unlock_bh(&port->lock); - - if (port->port.console && port->fwcon_ops->notify) - (*port->fwcon_ops->notify)(FWCON_NOTIFY_DETACH, port->con_data); -} - -static void fwserial_plug_timeout(struct timer_list *t) -{ - struct fwtty_peer *peer = from_timer(peer, t, timer); - struct fwtty_port *port; - - spin_lock_bh(&peer->lock); - if (peer->state != FWPS_PLUG_PENDING) { - spin_unlock_bh(&peer->lock); - return; - } - - port = peer_revert_state(peer); - spin_unlock_bh(&peer->lock); - - if (port) - fwserial_release_port(port, false); -} - -/* - * fwserial_connect_peer - initiate virtual cable with peer - * - * Returns 0 if VIRT_CABLE_PLUG request was successfully sent, - * otherwise error code. Must be called from process context. - */ -static int fwserial_connect_peer(struct fwtty_peer *peer) -{ - struct fwtty_port *port; - struct fwserial_mgmt_pkt *pkt; - int err, rcode; - - pkt = kmalloc(sizeof(*pkt), GFP_KERNEL); - if (!pkt) - return -ENOMEM; - - port = fwserial_find_port(peer); - if (!port) { - fwtty_err(&peer->unit, "avail ports in use\n"); - err = -EBUSY; - goto free_pkt; - } - - spin_lock_bh(&peer->lock); - - /* only initiate VIRT_CABLE_PLUG if peer is currently not attached */ - if (peer->state != FWPS_NOT_ATTACHED) { - err = -EBUSY; - goto release_port; - } - - peer->port = port; - peer_set_state(peer, FWPS_PLUG_PENDING); - - fill_plug_req(pkt, peer->port); - - mod_timer(&peer->timer, jiffies + VIRT_CABLE_PLUG_TIMEOUT); - spin_unlock_bh(&peer->lock); - - rcode = fwserial_send_mgmt_sync(peer, pkt); - - spin_lock_bh(&peer->lock); - if (peer->state == FWPS_PLUG_PENDING && rcode != RCODE_COMPLETE) { - if (rcode == RCODE_CONFLICT_ERROR) - err = -EAGAIN; - else - err = -EIO; - goto cancel_timer; - } - spin_unlock_bh(&peer->lock); - - kfree(pkt); - return 0; - -cancel_timer: - del_timer(&peer->timer); - peer_revert_state(peer); -release_port: - spin_unlock_bh(&peer->lock); - fwserial_release_port(port, false); -free_pkt: - kfree(pkt); - return err; -} - -/* - * fwserial_close_port - - * HUP the tty (if the tty exists) and unregister the tty device. - * Only used by the unit driver upon unit removal to disconnect and - * cleanup all attached ports - * - * The port reference is put by fwtty_cleanup (if a reference was - * ever taken). - */ -static void fwserial_close_port(struct tty_driver *driver, - struct fwtty_port *port) -{ - struct tty_struct *tty; - - mutex_lock(&port->port.mutex); - tty = tty_port_tty_get(&port->port); - if (tty) { - tty_vhangup(tty); - tty_kref_put(tty); - } - mutex_unlock(&port->port.mutex); - - if (driver == fwloop_driver) - tty_unregister_device(driver, loop_idx(port)); - else - tty_unregister_device(driver, port->index); -} - -/** - * fwserial_lookup - finds first fw_serial associated with card - * @card: fw_card to match - * - * NB: caller must be holding fwserial_list_mutex - */ -static struct fw_serial *fwserial_lookup(struct fw_card *card) -{ - struct fw_serial *serial; - - list_for_each_entry(serial, &fwserial_list, list) { - if (card == serial->card) - return serial; - } - - return NULL; -} - -/** - * __fwserial_lookup_rcu - finds first fw_serial associated with card - * @card: fw_card to match - * - * NB: caller must be inside rcu_read_lock() section - */ -static struct fw_serial *__fwserial_lookup_rcu(struct fw_card *card) -{ - struct fw_serial *serial; - - list_for_each_entry_rcu(serial, &fwserial_list, list) { - if (card == serial->card) - return serial; - } - - return NULL; -} - -/* - * __fwserial_peer_by_node_id - finds a peer matching the given generation + id - * - * If a matching peer could not be found for the specified generation/node id, - * this could be because: - * a) the generation has changed and one of the nodes hasn't updated yet - * b) the remote node has created its remote unit device before this - * local node has created its corresponding remote unit device - * In either case, the remote node should retry - * - * Note: caller must be in rcu_read_lock() section - */ -static struct fwtty_peer *__fwserial_peer_by_node_id(struct fw_card *card, - int generation, int id) -{ - struct fw_serial *serial; - struct fwtty_peer *peer; - - serial = __fwserial_lookup_rcu(card); - if (!serial) { - /* - * Something is very wrong - there should be a matching - * fw_serial structure for every fw_card. Maybe the remote node - * has created its remote unit device before this driver has - * been probed for any unit devices... - */ - fwtty_err(card, "unknown card (guid %016llx)\n", - (unsigned long long)card->guid); - return NULL; - } - - list_for_each_entry_rcu(peer, &serial->peer_list, list) { - int g = peer->generation; - - smp_rmb(); - if (generation == g && id == peer->node_id) - return peer; - } - - return NULL; -} - -#ifdef DEBUG -static void __dump_peer_list(struct fw_card *card) -{ - struct fw_serial *serial; - struct fwtty_peer *peer; - - serial = __fwserial_lookup_rcu(card); - if (!serial) - return; - - list_for_each_entry_rcu(peer, &serial->peer_list, list) { - int g = peer->generation; - - smp_rmb(); - fwtty_dbg(card, "peer(%d:%x) guid: %016llx\n", - g, peer->node_id, (unsigned long long)peer->guid); - } -} -#else -#define __dump_peer_list(s) -#endif - -static void fwserial_auto_connect(struct work_struct *work) -{ - struct fwtty_peer *peer = to_peer(to_delayed_work(work), connect); - int err; - - err = fwserial_connect_peer(peer); - if (err == -EAGAIN && ++peer->connect_retries < MAX_CONNECT_RETRIES) - schedule_delayed_work(&peer->connect, CONNECT_RETRY_DELAY); -} - -static void fwserial_peer_workfn(struct work_struct *work) -{ - struct fwtty_peer *peer = to_peer(work, work); - - peer->workfn(work); -} - -/** - * fwserial_add_peer - add a newly probed 'serial' unit device as a 'peer' - * @serial: aggregate representing the specific fw_card to add the peer to - * @unit: 'peer' to create and add to peer_list of serial - * - * Adds a 'peer' (ie, a local or remote 'serial' unit device) to the list of - * peers for a specific fw_card. Optionally, auto-attach this peer to an - * available tty port. This function is called either directly or indirectly - * as a result of a 'serial' unit device being created & probed. - * - * Note: this function is serialized with fwserial_remove_peer() by the - * fwserial_list_mutex held in fwserial_probe(). - * - * A 1:1 correspondence between an fw_unit and an fwtty_peer is maintained - * via the dev_set_drvdata() for the device of the fw_unit. - */ -static int fwserial_add_peer(struct fw_serial *serial, struct fw_unit *unit) -{ - struct device *dev = &unit->device; - struct fw_device *parent = fw_parent_device(unit); - struct fwtty_peer *peer; - struct fw_csr_iterator ci; - int key, val; - int generation; - - peer = kzalloc(sizeof(*peer), GFP_KERNEL); - if (!peer) - return -ENOMEM; - - peer_set_state(peer, FWPS_NOT_ATTACHED); - - dev_set_drvdata(dev, peer); - peer->unit = unit; - peer->guid = (u64)parent->config_rom[3] << 32 | parent->config_rom[4]; - peer->speed = parent->max_speed; - peer->max_payload = min(device_max_receive(parent), - link_speed_to_max_payload(peer->speed)); - - generation = parent->generation; - smp_rmb(); - peer->node_id = parent->node_id; - smp_wmb(); - peer->generation = generation; - - /* retrieve the mgmt bus addr from the unit directory */ - fw_csr_iterator_init(&ci, unit->directory); - while (fw_csr_iterator_next(&ci, &key, &val)) { - if (key == (CSR_OFFSET | CSR_DEPENDENT_INFO)) { - peer->mgmt_addr = CSR_REGISTER_BASE + 4 * val; - break; - } - } - if (peer->mgmt_addr == 0ULL) { - /* - * No mgmt address effectively disables VIRT_CABLE_PLUG - - * this peer will not be able to attach to a remote - */ - peer_set_state(peer, FWPS_NO_MGMT_ADDR); - } - - spin_lock_init(&peer->lock); - peer->port = NULL; - - timer_setup(&peer->timer, fwserial_plug_timeout, 0); - INIT_WORK(&peer->work, fwserial_peer_workfn); - INIT_DELAYED_WORK(&peer->connect, fwserial_auto_connect); - - /* associate peer with specific fw_card */ - peer->serial = serial; - list_add_rcu(&peer->list, &serial->peer_list); - - fwtty_info(&peer->unit, "peer added (guid:%016llx)\n", - (unsigned long long)peer->guid); - - /* identify the local unit & virt cable to loopback port */ - if (parent->is_local) { - serial->self = peer; - if (create_loop_dev) { - struct fwtty_port *port; - - port = fwserial_claim_port(peer, num_ttys); - if (!IS_ERR(port)) { - struct virt_plug_params params; - - spin_lock_bh(&peer->lock); - peer->port = port; - fill_plug_params(¶ms, port); - fwserial_virt_plug_complete(peer, ¶ms); - spin_unlock_bh(&peer->lock); - - fwtty_write_port_status(port); - } - } - - } else if (auto_connect) { - /* auto-attach to remote units only (if policy allows) */ - schedule_delayed_work(&peer->connect, 1); - } - - return 0; -} - -/* - * fwserial_remove_peer - remove a 'serial' unit device as a 'peer' - * - * Remove a 'peer' from its list of peers. This function is only - * called by fwserial_remove() on bus removal of the unit device. - * - * Note: this function is serialized with fwserial_add_peer() by the - * fwserial_list_mutex held in fwserial_remove(). - */ -static void fwserial_remove_peer(struct fwtty_peer *peer) -{ - struct fwtty_port *port; - - spin_lock_bh(&peer->lock); - peer_set_state(peer, FWPS_GONE); - spin_unlock_bh(&peer->lock); - - cancel_delayed_work_sync(&peer->connect); - cancel_work_sync(&peer->work); - - spin_lock_bh(&peer->lock); - /* if this unit is the local unit, clear link */ - if (peer == peer->serial->self) - peer->serial->self = NULL; - - /* cancel the request timeout timer (if running) */ - del_timer(&peer->timer); - - port = peer->port; - peer->port = NULL; - - list_del_rcu(&peer->list); - - fwtty_info(&peer->unit, "peer removed (guid:%016llx)\n", - (unsigned long long)peer->guid); - - spin_unlock_bh(&peer->lock); - - if (port) - fwserial_release_port(port, true); - - synchronize_rcu(); - kfree(peer); -} - -/** - * fwserial_create - init everything to create TTYs for a specific fw_card - * @unit: fw_unit for first 'serial' unit device probed for this fw_card - * - * This function inits the aggregate structure (an fw_serial instance) - * used to manage the TTY ports registered by a specific fw_card. Also, the - * unit device is added as the first 'peer'. - * - * This unit device may represent a local unit device (as specified by the - * config ROM unit directory) or it may represent a remote unit device - * (as specified by the reading of the remote node's config ROM). - * - * Returns 0 to indicate "ownership" of the unit device, or a negative errno - * value to indicate which error. - */ -static int fwserial_create(struct fw_unit *unit) -{ - struct fw_device *parent = fw_parent_device(unit); - struct fw_card *card = parent->card; - struct fw_serial *serial; - struct fwtty_port *port; - struct device *tty_dev; - int i, j; - int err; - - serial = kzalloc(sizeof(*serial), GFP_KERNEL); - if (!serial) - return -ENOMEM; - - kref_init(&serial->kref); - serial->card = card; - INIT_LIST_HEAD(&serial->peer_list); - - for (i = 0; i < num_ports; ++i) { - port = kzalloc(sizeof(*port), GFP_KERNEL); - if (!port) { - err = -ENOMEM; - goto free_ports; - } - tty_port_init(&port->port); - port->index = FWTTY_INVALID_INDEX; - port->port.ops = &fwtty_port_ops; - port->serial = serial; - tty_buffer_set_limit(&port->port, 128 * 1024); - - spin_lock_init(&port->lock); - INIT_DELAYED_WORK(&port->drain, fwtty_drain_tx); - INIT_DELAYED_WORK(&port->emit_breaks, fwtty_emit_breaks); - INIT_WORK(&port->hangup, fwtty_do_hangup); - init_waitqueue_head(&port->wait_tx); - port->max_payload = link_speed_to_max_payload(SCODE_100); - dma_fifo_init(&port->tx_fifo); - - RCU_INIT_POINTER(port->peer, NULL); - serial->ports[i] = port; - - /* get unique bus addr region for port's status & recv fifo */ - port->rx_handler.length = FWTTY_PORT_RXFIFO_LEN + 4; - port->rx_handler.address_callback = fwtty_port_handler; - port->rx_handler.callback_data = port; - /* - * XXX: use custom memory region above cpu physical memory addrs - * this will ease porting to 64-bit firewire adapters - */ - err = fw_core_add_address_handler(&port->rx_handler, - &fw_high_memory_region); - if (err) { - tty_port_destroy(&port->port); - kfree(port); - goto free_ports; - } - } - /* preserve i for error cleanup */ - - err = fwtty_ports_add(serial); - if (err) { - fwtty_err(&unit, "no space in port table\n"); - goto free_ports; - } - - for (j = 0; j < num_ttys; ++j) { - tty_dev = tty_port_register_device(&serial->ports[j]->port, - fwtty_driver, - serial->ports[j]->index, - card->device); - if (IS_ERR(tty_dev)) { - err = PTR_ERR(tty_dev); - fwtty_err(&unit, "register tty device error (%d)\n", - err); - goto unregister_ttys; - } - - serial->ports[j]->device = tty_dev; - } - /* preserve j for error cleanup */ - - if (create_loop_dev) { - struct device *loop_dev; - - loop_dev = tty_port_register_device(&serial->ports[j]->port, - fwloop_driver, - loop_idx(serial->ports[j]), - card->device); - if (IS_ERR(loop_dev)) { - err = PTR_ERR(loop_dev); - fwtty_err(&unit, "create loop device failed (%d)\n", - err); - goto unregister_ttys; - } - serial->ports[j]->device = loop_dev; - serial->ports[j]->loopback = true; - } - - if (!IS_ERR_OR_NULL(fwserial_debugfs)) { - serial->debugfs = debugfs_create_dir(dev_name(&unit->device), - fwserial_debugfs); - if (!IS_ERR_OR_NULL(serial->debugfs)) { - debugfs_create_file("peers", 0444, serial->debugfs, - serial, &fwtty_peers_fops); - debugfs_create_file("stats", 0444, serial->debugfs, - serial, &fwtty_stats_fops); - } - } - - list_add_rcu(&serial->list, &fwserial_list); - - fwtty_notice(&unit, "TTY over FireWire on device %s (guid %016llx)\n", - dev_name(card->device), (unsigned long long)card->guid); - - err = fwserial_add_peer(serial, unit); - if (!err) - return 0; - - fwtty_err(&unit, "unable to add peer unit device (%d)\n", err); - - /* fall-through to error processing */ - debugfs_remove_recursive(serial->debugfs); - - list_del_rcu(&serial->list); - if (create_loop_dev) - tty_unregister_device(fwloop_driver, - loop_idx(serial->ports[j])); -unregister_ttys: - for (--j; j >= 0; --j) - tty_unregister_device(fwtty_driver, serial->ports[j]->index); - kref_put(&serial->kref, fwserial_destroy); - return err; - -free_ports: - for (--i; i >= 0; --i) { - fw_core_remove_address_handler(&serial->ports[i]->rx_handler); - tty_port_destroy(&serial->ports[i]->port); - kfree(serial->ports[i]); - } - kfree(serial); - return err; -} - -/* - * fwserial_probe: bus probe function for firewire 'serial' unit devices - * - * A 'serial' unit device is created and probed as a result of: - * - declaring a ieee1394 bus id table for 'devices' matching a fabricated - * 'serial' unit specifier id - * - adding a unit directory to the config ROM(s) for a 'serial' unit - * - * The firewire core registers unit devices by enumerating unit directories - * of a node's config ROM after reading the config ROM when a new node is - * added to the bus topology after a bus reset. - * - * The practical implications of this are: - * - this probe is called for both local and remote nodes that have a 'serial' - * unit directory in their config ROM (that matches the specifiers in - * fwserial_id_table). - * - no specific order is enforced for local vs. remote unit devices - * - * This unit driver copes with the lack of specific order in the same way the - * firewire net driver does -- each probe, for either a local or remote unit - * device, is treated as a 'peer' (has a struct fwtty_peer instance) and the - * first peer created for a given fw_card (tracked by the global fwserial_list) - * creates the underlying TTYs (aggregated in a fw_serial instance). - * - * NB: an early attempt to differentiate local & remote unit devices by creating - * peers only for remote units and fw_serial instances (with their - * associated TTY devices) only for local units was discarded. Managing - * the peer lifetimes on device removal proved too complicated. - * - * fwserial_probe/fwserial_remove are effectively serialized by the - * fwserial_list_mutex. This is necessary because the addition of the first peer - * for a given fw_card will trigger the creation of the fw_serial for that - * fw_card, which must not simultaneously contend with the removal of the - * last peer for a given fw_card triggering the destruction of the same - * fw_serial for the same fw_card. - */ -static int fwserial_probe(struct fw_unit *unit, - const struct ieee1394_device_id *id) -{ - struct fw_serial *serial; - int err; - - mutex_lock(&fwserial_list_mutex); - serial = fwserial_lookup(fw_parent_device(unit)->card); - if (!serial) - err = fwserial_create(unit); - else - err = fwserial_add_peer(serial, unit); - mutex_unlock(&fwserial_list_mutex); - return err; -} - -/* - * fwserial_remove: bus removal function for firewire 'serial' unit devices - * - * The corresponding 'peer' for this unit device is removed from the list of - * peers for the associated fw_serial (which has a 1:1 correspondence with a - * specific fw_card). If this is the last peer being removed, then trigger - * the destruction of the underlying TTYs. - */ -static void fwserial_remove(struct fw_unit *unit) -{ - struct fwtty_peer *peer = dev_get_drvdata(&unit->device); - struct fw_serial *serial = peer->serial; - int i; - - mutex_lock(&fwserial_list_mutex); - fwserial_remove_peer(peer); - - if (list_empty(&serial->peer_list)) { - /* unlink from the fwserial_list here */ - list_del_rcu(&serial->list); - - debugfs_remove_recursive(serial->debugfs); - - for (i = 0; i < num_ttys; ++i) - fwserial_close_port(fwtty_driver, serial->ports[i]); - if (create_loop_dev) - fwserial_close_port(fwloop_driver, serial->ports[i]); - kref_put(&serial->kref, fwserial_destroy); - } - mutex_unlock(&fwserial_list_mutex); -} - -/* - * fwserial_update: bus update function for 'firewire' serial unit devices - * - * Updates the new node_id and bus generation for this peer. Note that locking - * is unnecessary; but careful memory barrier usage is important to enforce the - * load and store order of generation & node_id. - * - * The fw-core orders the write of node_id before generation in the parent - * fw_device to ensure that a stale node_id cannot be used with a current - * bus generation. So the generation value must be read before the node_id. - * - * In turn, this orders the write of node_id before generation in the peer to - * also ensure a stale node_id cannot be used with a current bus generation. - */ -static void fwserial_update(struct fw_unit *unit) -{ - struct fw_device *parent = fw_parent_device(unit); - struct fwtty_peer *peer = dev_get_drvdata(&unit->device); - int generation; - - generation = parent->generation; - smp_rmb(); - peer->node_id = parent->node_id; - smp_wmb(); - peer->generation = generation; -} - -static const struct ieee1394_device_id fwserial_id_table[] = { - { - .match_flags = IEEE1394_MATCH_SPECIFIER_ID | - IEEE1394_MATCH_VERSION, - .specifier_id = LINUX_VENDOR_ID, - .version = FWSERIAL_VERSION, - }, - { } -}; - -static struct fw_driver fwserial_driver = { - .driver = { - .owner = THIS_MODULE, - .name = KBUILD_MODNAME, - .bus = &fw_bus_type, - }, - .probe = fwserial_probe, - .update = fwserial_update, - .remove = fwserial_remove, - .id_table = fwserial_id_table, -}; - -#define FW_UNIT_SPECIFIER(id) ((CSR_SPECIFIER_ID << 24) | (id)) -#define FW_UNIT_VERSION(ver) ((CSR_VERSION << 24) | (ver)) -#define FW_UNIT_ADDRESS(ofs) (((CSR_OFFSET | CSR_DEPENDENT_INFO) << 24) \ - | (((ofs) - CSR_REGISTER_BASE) >> 2)) -/* XXX: config ROM definitons could be improved with semi-automated offset - * and length calculation - */ -#define FW_ROM_LEN(quads) ((quads) << 16) -#define FW_ROM_DESCRIPTOR(ofs) (((CSR_LEAF | CSR_DESCRIPTOR) << 24) | (ofs)) - -struct fwserial_unit_directory_data { - u32 len_crc; - u32 unit_specifier; - u32 unit_sw_version; - u32 unit_addr_offset; - u32 desc1_ofs; - u32 desc1_len_crc; - u32 desc1_data[5]; -} __packed; - -static struct fwserial_unit_directory_data fwserial_unit_directory_data = { - .len_crc = FW_ROM_LEN(4), - .unit_specifier = FW_UNIT_SPECIFIER(LINUX_VENDOR_ID), - .unit_sw_version = FW_UNIT_VERSION(FWSERIAL_VERSION), - .desc1_ofs = FW_ROM_DESCRIPTOR(1), - .desc1_len_crc = FW_ROM_LEN(5), - .desc1_data = { - 0x00000000, /* type = text */ - 0x00000000, /* enc = ASCII, lang EN */ - 0x4c696e75, /* 'Linux TTY' */ - 0x78205454, - 0x59000000, - }, -}; - -static struct fw_descriptor fwserial_unit_directory = { - .length = sizeof(fwserial_unit_directory_data) / sizeof(u32), - .key = (CSR_DIRECTORY | CSR_UNIT) << 24, - .data = (u32 *)&fwserial_unit_directory_data, -}; - -/* - * The management address is in the unit space region but above other known - * address users (to keep wild writes from causing havoc) - */ -static const struct fw_address_region fwserial_mgmt_addr_region = { - .start = CSR_REGISTER_BASE + 0x1e0000ULL, - .end = 0x1000000000000ULL, -}; - -static struct fw_address_handler fwserial_mgmt_addr_handler; - -/** - * fwserial_handle_plug_req - handle VIRT_CABLE_PLUG request work - * @work: ptr to peer->work - * - * Attempts to complete the VIRT_CABLE_PLUG handshake sequence for this peer. - * - * This checks for a collided request-- ie, that a VIRT_CABLE_PLUG request was - * already sent to this peer. If so, the collision is resolved by comparing - * guid values; the loser sends the plug response. - * - * Note: if an error prevents a response, don't do anything -- the - * remote will timeout its request. - */ -static void fwserial_handle_plug_req(struct work_struct *work) -{ - struct fwtty_peer *peer = to_peer(work, work); - struct virt_plug_params *plug_req = &peer->work_params.plug_req; - struct fwtty_port *port; - struct fwserial_mgmt_pkt *pkt; - int rcode; - - pkt = kmalloc(sizeof(*pkt), GFP_KERNEL); - if (!pkt) - return; - - port = fwserial_find_port(peer); - - spin_lock_bh(&peer->lock); - - switch (peer->state) { - case FWPS_NOT_ATTACHED: - if (!port) { - fwtty_err(&peer->unit, "no more ports avail\n"); - fill_plug_rsp_nack(pkt); - } else { - peer->port = port; - fill_plug_rsp_ok(pkt, peer->port); - peer_set_state(peer, FWPS_PLUG_RESPONDING); - /* don't release claimed port */ - port = NULL; - } - break; - - case FWPS_PLUG_PENDING: - if (peer->serial->card->guid > peer->guid) - goto cleanup; - - /* We lost - hijack the already-claimed port and send ok */ - del_timer(&peer->timer); - fill_plug_rsp_ok(pkt, peer->port); - peer_set_state(peer, FWPS_PLUG_RESPONDING); - break; - - default: - fill_plug_rsp_nack(pkt); - } - - spin_unlock_bh(&peer->lock); - if (port) - fwserial_release_port(port, false); - - rcode = fwserial_send_mgmt_sync(peer, pkt); - - spin_lock_bh(&peer->lock); - if (peer->state == FWPS_PLUG_RESPONDING) { - if (rcode == RCODE_COMPLETE) { - struct fwtty_port *tmp = peer->port; - - fwserial_virt_plug_complete(peer, plug_req); - spin_unlock_bh(&peer->lock); - - fwtty_write_port_status(tmp); - spin_lock_bh(&peer->lock); - } else { - fwtty_err(&peer->unit, "PLUG_RSP error (%d)\n", rcode); - port = peer_revert_state(peer); - } - } -cleanup: - spin_unlock_bh(&peer->lock); - if (port) - fwserial_release_port(port, false); - kfree(pkt); -} - -static void fwserial_handle_unplug_req(struct work_struct *work) -{ - struct fwtty_peer *peer = to_peer(work, work); - struct fwtty_port *port = NULL; - struct fwserial_mgmt_pkt *pkt; - int rcode; - - pkt = kmalloc(sizeof(*pkt), GFP_KERNEL); - if (!pkt) - return; - - spin_lock_bh(&peer->lock); - - switch (peer->state) { - case FWPS_ATTACHED: - fill_unplug_rsp_ok(pkt); - peer_set_state(peer, FWPS_UNPLUG_RESPONDING); - break; - - case FWPS_UNPLUG_PENDING: - if (peer->serial->card->guid > peer->guid) - goto cleanup; - - /* We lost - send unplug rsp */ - del_timer(&peer->timer); - fill_unplug_rsp_ok(pkt); - peer_set_state(peer, FWPS_UNPLUG_RESPONDING); - break; - - default: - fill_unplug_rsp_nack(pkt); - } - - spin_unlock_bh(&peer->lock); - - rcode = fwserial_send_mgmt_sync(peer, pkt); - - spin_lock_bh(&peer->lock); - if (peer->state == FWPS_UNPLUG_RESPONDING) { - if (rcode != RCODE_COMPLETE) - fwtty_err(&peer->unit, "UNPLUG_RSP error (%d)\n", - rcode); - port = peer_revert_state(peer); - } -cleanup: - spin_unlock_bh(&peer->lock); - if (port) - fwserial_release_port(port, true); - kfree(pkt); -} - -static int fwserial_parse_mgmt_write(struct fwtty_peer *peer, - struct fwserial_mgmt_pkt *pkt, - unsigned long long addr, - size_t len) -{ - struct fwtty_port *port = NULL; - bool reset = false; - int rcode; - - if (addr != fwserial_mgmt_addr_handler.offset || len < sizeof(pkt->hdr)) - return RCODE_ADDRESS_ERROR; - - if (len != be16_to_cpu(pkt->hdr.len) || - len != mgmt_pkt_expected_len(pkt->hdr.code)) - return RCODE_DATA_ERROR; - - spin_lock_bh(&peer->lock); - if (peer->state == FWPS_GONE) { - /* - * This should never happen - it would mean that the - * remote unit that just wrote this transaction was - * already removed from the bus -- and the removal was - * processed before we rec'd this transaction - */ - fwtty_err(&peer->unit, "peer already removed\n"); - spin_unlock_bh(&peer->lock); - return RCODE_ADDRESS_ERROR; - } - - rcode = RCODE_COMPLETE; - - fwtty_dbg(&peer->unit, "mgmt: hdr.code: %04x\n", pkt->hdr.code); - - switch (be16_to_cpu(pkt->hdr.code) & FWSC_CODE_MASK) { - case FWSC_VIRT_CABLE_PLUG: - if (work_pending(&peer->work)) { - fwtty_err(&peer->unit, "plug req: busy\n"); - rcode = RCODE_CONFLICT_ERROR; - - } else { - peer->work_params.plug_req = pkt->plug_req; - peer->workfn = fwserial_handle_plug_req; - queue_work(system_unbound_wq, &peer->work); - } - break; - - case FWSC_VIRT_CABLE_PLUG_RSP: - if (peer->state != FWPS_PLUG_PENDING) { - rcode = RCODE_CONFLICT_ERROR; - - } else if (be16_to_cpu(pkt->hdr.code) & FWSC_RSP_NACK) { - fwtty_notice(&peer->unit, "NACK plug rsp\n"); - port = peer_revert_state(peer); - - } else { - struct fwtty_port *tmp = peer->port; - - fwserial_virt_plug_complete(peer, &pkt->plug_rsp); - spin_unlock_bh(&peer->lock); - - fwtty_write_port_status(tmp); - spin_lock_bh(&peer->lock); - } - break; - - case FWSC_VIRT_CABLE_UNPLUG: - if (work_pending(&peer->work)) { - fwtty_err(&peer->unit, "unplug req: busy\n"); - rcode = RCODE_CONFLICT_ERROR; - } else { - peer->workfn = fwserial_handle_unplug_req; - queue_work(system_unbound_wq, &peer->work); - } - break; - - case FWSC_VIRT_CABLE_UNPLUG_RSP: - if (peer->state != FWPS_UNPLUG_PENDING) { - rcode = RCODE_CONFLICT_ERROR; - } else { - if (be16_to_cpu(pkt->hdr.code) & FWSC_RSP_NACK) - fwtty_notice(&peer->unit, "NACK unplug?\n"); - port = peer_revert_state(peer); - reset = true; - } - break; - - default: - fwtty_err(&peer->unit, "unknown mgmt code %d\n", - be16_to_cpu(pkt->hdr.code)); - rcode = RCODE_DATA_ERROR; - } - spin_unlock_bh(&peer->lock); - - if (port) - fwserial_release_port(port, reset); - - return rcode; -} - -/* - * fwserial_mgmt_handler: bus address handler for mgmt requests - * - * This handler is responsible for handling virtual cable requests from remotes - * for all cards. - */ -static void fwserial_mgmt_handler(struct fw_card *card, - struct fw_request *request, - int tcode, int destination, int source, - int generation, - unsigned long long addr, - void *data, size_t len, - void *callback_data) -{ - struct fwserial_mgmt_pkt *pkt = data; - struct fwtty_peer *peer; - int rcode; - - rcu_read_lock(); - peer = __fwserial_peer_by_node_id(card, generation, source); - if (!peer) { - fwtty_dbg(card, "peer(%d:%x) not found\n", generation, source); - __dump_peer_list(card); - rcode = RCODE_CONFLICT_ERROR; - - } else { - switch (tcode) { - case TCODE_WRITE_BLOCK_REQUEST: - rcode = fwserial_parse_mgmt_write(peer, pkt, addr, len); - break; - - default: - rcode = RCODE_TYPE_ERROR; - } - } - - rcu_read_unlock(); - fw_send_response(card, request, rcode); -} - -static int __init fwserial_init(void) -{ - int err, num_loops = !!(create_loop_dev); - - /* XXX: placeholder for a "firewire" debugfs node */ - fwserial_debugfs = debugfs_create_dir(KBUILD_MODNAME, NULL); - - /* num_ttys/num_ports must not be set above the static alloc avail */ - if (num_ttys + num_loops > MAX_CARD_PORTS) - num_ttys = MAX_CARD_PORTS - num_loops; - - num_ports = num_ttys + num_loops; - - fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW - | TTY_DRIVER_DYNAMIC_DEV); - if (IS_ERR(fwtty_driver)) { - err = PTR_ERR(fwtty_driver); - goto remove_debugfs; - } - - fwtty_driver->driver_name = KBUILD_MODNAME; - fwtty_driver->name = tty_dev_name; - fwtty_driver->major = 0; - fwtty_driver->minor_start = 0; - fwtty_driver->type = TTY_DRIVER_TYPE_SERIAL; - fwtty_driver->subtype = SERIAL_TYPE_NORMAL; - fwtty_driver->init_termios = tty_std_termios; - fwtty_driver->init_termios.c_cflag |= CLOCAL; - tty_set_operations(fwtty_driver, &fwtty_ops); - - err = tty_register_driver(fwtty_driver); - if (err) { - pr_err("register tty driver failed (%d)\n", err); - goto put_tty; - } - - if (create_loop_dev) { - fwloop_driver = tty_alloc_driver(MAX_TOTAL_PORTS / num_ports, - TTY_DRIVER_REAL_RAW - | TTY_DRIVER_DYNAMIC_DEV); - if (IS_ERR(fwloop_driver)) { - err = PTR_ERR(fwloop_driver); - goto unregister_driver; - } - - fwloop_driver->driver_name = KBUILD_MODNAME "_loop"; - fwloop_driver->name = loop_dev_name; - fwloop_driver->major = 0; - fwloop_driver->minor_start = 0; - fwloop_driver->type = TTY_DRIVER_TYPE_SERIAL; - fwloop_driver->subtype = SERIAL_TYPE_NORMAL; - fwloop_driver->init_termios = tty_std_termios; - fwloop_driver->init_termios.c_cflag |= CLOCAL; - tty_set_operations(fwloop_driver, &fwloop_ops); - - err = tty_register_driver(fwloop_driver); - if (err) { - pr_err("register loop driver failed (%d)\n", err); - goto put_loop; - } - } - - fwtty_txn_cache = kmem_cache_create("fwtty_txn_cache", - sizeof(struct fwtty_transaction), - 0, 0, NULL); - if (!fwtty_txn_cache) { - err = -ENOMEM; - goto unregister_loop; - } - - /* - * Ideally, this address handler would be registered per local node - * (rather than the same handler for all local nodes). However, - * since the firewire core requires the config rom descriptor *before* - * the local unit device(s) are created, a single management handler - * must suffice for all local serial units. - */ - fwserial_mgmt_addr_handler.length = sizeof(struct fwserial_mgmt_pkt); - fwserial_mgmt_addr_handler.address_callback = fwserial_mgmt_handler; - - err = fw_core_add_address_handler(&fwserial_mgmt_addr_handler, - &fwserial_mgmt_addr_region); - if (err) { - pr_err("add management handler failed (%d)\n", err); - goto destroy_cache; - } - - fwserial_unit_directory_data.unit_addr_offset = - FW_UNIT_ADDRESS(fwserial_mgmt_addr_handler.offset); - err = fw_core_add_descriptor(&fwserial_unit_directory); - if (err) { - pr_err("add unit descriptor failed (%d)\n", err); - goto remove_handler; - } - - err = driver_register(&fwserial_driver.driver); - if (err) { - pr_err("register fwserial driver failed (%d)\n", err); - goto remove_descriptor; - } - - return 0; - -remove_descriptor: - fw_core_remove_descriptor(&fwserial_unit_directory); -remove_handler: - fw_core_remove_address_handler(&fwserial_mgmt_addr_handler); -destroy_cache: - kmem_cache_destroy(fwtty_txn_cache); -unregister_loop: - if (create_loop_dev) - tty_unregister_driver(fwloop_driver); -put_loop: - if (create_loop_dev) - tty_driver_kref_put(fwloop_driver); -unregister_driver: - tty_unregister_driver(fwtty_driver); -put_tty: - tty_driver_kref_put(fwtty_driver); -remove_debugfs: - debugfs_remove_recursive(fwserial_debugfs); - - return err; -} - -static void __exit fwserial_exit(void) -{ - driver_unregister(&fwserial_driver.driver); - fw_core_remove_descriptor(&fwserial_unit_directory); - fw_core_remove_address_handler(&fwserial_mgmt_addr_handler); - kmem_cache_destroy(fwtty_txn_cache); - if (create_loop_dev) { - tty_unregister_driver(fwloop_driver); - tty_driver_kref_put(fwloop_driver); - } - tty_unregister_driver(fwtty_driver); - tty_driver_kref_put(fwtty_driver); - debugfs_remove_recursive(fwserial_debugfs); -} - -module_init(fwserial_init); -module_exit(fwserial_exit); - -MODULE_AUTHOR("Peter Hurley (peter@hurleysoftware.com)"); -MODULE_DESCRIPTION("FireWire Serial TTY Driver"); -MODULE_LICENSE("GPL"); -MODULE_DEVICE_TABLE(ieee1394, fwserial_id_table); -MODULE_PARM_DESC(ttys, "Number of ttys to create for each local firewire node"); -MODULE_PARM_DESC(auto, "Auto-connect a tty to each firewire node discovered"); -MODULE_PARM_DESC(loop, "Create a loopback device, fwloop<n>, with ttys"); diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h deleted file mode 100644 index 1d15f183e0fa..000000000000 --- a/drivers/staging/fwserial/fwserial.h +++ /dev/null @@ -1,359 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _FIREWIRE_FWSERIAL_H -#define _FIREWIRE_FWSERIAL_H - -#include <linux/kernel.h> -#include <linux/tty.h> -#include <linux/tty_driver.h> -#include <linux/tty_flip.h> -#include <linux/list.h> -#include <linux/firewire.h> -#include <linux/firewire-constants.h> -#include <linux/spinlock.h> -#include <linux/rcupdate.h> -#include <linux/mutex.h> -#include <linux/serial.h> -#include <linux/serial_reg.h> -#include <linux/module.h> -#include <linux/seq_file.h> -#include <linux/debugfs.h> - -#include "dma_fifo.h" - -#ifdef FWTTY_PROFILING -#define DISTRIBUTION_MAX_SIZE 8192 -#define DISTRIBUTION_MAX_INDEX (ilog2(DISTRIBUTION_MAX_SIZE) + 1) -static inline void fwtty_profile_data(unsigned int stat[], unsigned int val) -{ - int n = (val) ? min(ilog2(val) + 1, DISTRIBUTION_MAX_INDEX) : 0; - ++stat[n]; -} -#else -#define DISTRIBUTION_MAX_INDEX 0 -#define fwtty_profile_data(st, n) -#endif - -/* Parameters for both VIRT_CABLE_PLUG & VIRT_CABLE_PLUG_RSP mgmt codes */ -struct virt_plug_params { - __be32 status_hi; - __be32 status_lo; - __be32 fifo_hi; - __be32 fifo_lo; - __be32 fifo_len; -}; - -struct peer_work_params { - union { - struct virt_plug_params plug_req; - }; -}; - -/** - * fwtty_peer: structure representing local & remote unit devices - * @unit: unit child device of fw_device node - * @serial: back pointer to associated fw_serial aggregate - * @guid: unique 64-bit guid for this unit device - * @generation: most recent bus generation - * @node_id: most recent node_id - * @speed: link speed of peer (0 = S100, 2 = S400, ... 5 = S3200) - * @mgmt_addr: bus addr region to write mgmt packets to - * @status_addr: bus addr register to write line status to - * @fifo_addr: bus addr region to write serial output to - * @fifo_len: max length for single write to fifo_addr - * @list: link for insertion into fw_serial's peer_list - * @rcu: for deferring peer reclamation - * @lock: spinlock to synchonize changes to state & port fields - * @work: only one work item can be queued at any one time - * Note: pending work is canceled prior to removal, so this - * peer is valid for at least the lifetime of the work function - * @work_params: parameter block for work functions - * @timer: timer for resetting peer state if remote request times out - * @state: current state - * @connect: work item for auto-connecting - * @connect_retries: # of connections already attempted - * @port: associated tty_port (usable if state == FWSC_ATTACHED) - */ -struct fwtty_peer { - struct fw_unit *unit; - struct fw_serial *serial; - u64 guid; - int generation; - int node_id; - unsigned int speed; - int max_payload; - u64 mgmt_addr; - - /* these are usable only if state == FWSC_ATTACHED */ - u64 status_addr; - u64 fifo_addr; - int fifo_len; - - struct list_head list; - struct rcu_head rcu; - - spinlock_t lock; - work_func_t workfn; - struct work_struct work; - struct peer_work_params work_params; - struct timer_list timer; - int state; - struct delayed_work connect; - int connect_retries; - - struct fwtty_port *port; -}; - -#define to_peer(ptr, field) (container_of(ptr, struct fwtty_peer, field)) - -/* state values for fwtty_peer.state field */ -enum fwtty_peer_state { - FWPS_GONE, - FWPS_NOT_ATTACHED, - FWPS_ATTACHED, - FWPS_PLUG_PENDING, - FWPS_PLUG_RESPONDING, - FWPS_UNPLUG_PENDING, - FWPS_UNPLUG_RESPONDING, - - FWPS_NO_MGMT_ADDR = -1, -}; - -#define CONNECT_RETRY_DELAY HZ -#define MAX_CONNECT_RETRIES 10 - -/* must be holding peer lock for these state funclets */ -static inline void peer_set_state(struct fwtty_peer *peer, int new) -{ - peer->state = new; -} - -static inline struct fwtty_port *peer_revert_state(struct fwtty_peer *peer) -{ - struct fwtty_port *port = peer->port; - - peer->port = NULL; - peer_set_state(peer, FWPS_NOT_ATTACHED); - return port; -} - -struct fwserial_mgmt_pkt { - struct { - __be16 len; - __be16 code; - } hdr; - union { - struct virt_plug_params plug_req; - struct virt_plug_params plug_rsp; - }; -} __packed; - -/* fwserial_mgmt_packet codes */ -#define FWSC_RSP_OK 0x0000 -#define FWSC_RSP_NACK 0x8000 -#define FWSC_CODE_MASK 0x0fff - -#define FWSC_VIRT_CABLE_PLUG 1 -#define FWSC_VIRT_CABLE_UNPLUG 2 -#define FWSC_VIRT_CABLE_PLUG_RSP 3 -#define FWSC_VIRT_CABLE_UNPLUG_RSP 4 - -/* 1 min. plug timeout -- suitable for userland authorization */ -#define VIRT_CABLE_PLUG_TIMEOUT (60 * HZ) - -struct stats { - unsigned int xchars; - unsigned int dropped; - unsigned int tx_stall; - unsigned int fifo_errs; - unsigned int sent; - unsigned int lost; - unsigned int throttled; - unsigned int reads[DISTRIBUTION_MAX_INDEX + 1]; - unsigned int writes[DISTRIBUTION_MAX_INDEX + 1]; - unsigned int txns[DISTRIBUTION_MAX_INDEX + 1]; - unsigned int unthrottle[DISTRIBUTION_MAX_INDEX + 1]; -}; - -struct fwconsole_ops { - void (*notify)(int code, void *data); - void (*stats)(struct stats *stats, void *data); - void (*proc_show)(struct seq_file *m, void *data); -}; - -/* codes for console ops notify */ -#define FWCON_NOTIFY_ATTACH 1 -#define FWCON_NOTIFY_DETACH 2 - -/** - * fwtty_port: structure used to track/represent underlying tty_port - * @port: underlying tty_port - * @device: tty device - * @index: index into port_table for this particular port - * note: minor = index + minor_start assigned by tty_alloc_driver() - * @serial: back pointer to the containing fw_serial - * @rx_handler: bus address handler for unique addr region used by remotes - * to communicate with this port. Every port uses - * fwtty_port_handler() for per port transactions. - * @fwcon_ops: ops for attached fw_console (if any) - * @con_data: private data for fw_console - * @wait_tx: waitqueue for sleeping until writer/drain completes tx - * @emit_breaks: delayed work responsible for generating breaks when the - * break line status is active - * @cps : characters per second computed from the termios settings - * @break_last: timestamp in jiffies from last emit_breaks - * @hangup: work responsible for HUPing when carrier is dropped/lost - * @mstatus: loose virtualization of LSR/MSR - * bits 15..0 correspond to TIOCM_* bits - * bits 19..16 reserved for mctrl - * bit 20 OOB_TX_THROTTLE - * bits 23..21 reserved - * bits 31..24 correspond to UART_LSR_* bits - * @lock: spinlock for protecting concurrent access to fields below it - * @mctrl: loose virtualization of MCR - * bits 15..0 correspond to TIOCM_* bits - * bit 16 OOB_RX_THROTTLE - * bits 19..17 reserved - * bits 31..20 reserved for mstatus - * @drain: delayed work scheduled to ensure that writes are flushed. - * The work can race with the writer but concurrent sending is - * prevented with the IN_TX flag. Scheduled under lock to - * limit scheduling when fifo has just been drained. - * @tx_fifo: fifo used to store & block-up writes for dma to remote - * @max_payload: max bytes transmissible per dma (based on peer's max_payload) - * @status_mask: UART_LSR_* bitmask significant to rx (based on termios) - * @ignore_mask: UART_LSR_* bitmask of states to ignore (also based on termios) - * @break_ctl: if set, port is 'sending break' to remote - * @write_only: self-explanatory - * @overrun: previous rx was lost (partially or completely) - * @loopback: if set, port is in loopback mode - * @flags: atomic bit flags - * bit 0: IN_TX - gate to allow only one cpu to send from the dma fifo - * at a time. - * bit 1: STOP_TX - force tx to exit while sending - * @peer: rcu-pointer to associated fwtty_peer (if attached) - * NULL if no peer attached - * @icount: predefined statistics reported by the TIOCGICOUNT ioctl - * @stats: additional statistics reported in /proc/tty/driver/firewire_serial - */ -struct fwtty_port { - struct tty_port port; - struct device *device; - unsigned int index; - struct fw_serial *serial; - struct fw_address_handler rx_handler; - - struct fwconsole_ops *fwcon_ops; - void *con_data; - - wait_queue_head_t wait_tx; - struct delayed_work emit_breaks; - unsigned int cps; - unsigned long break_last; - - struct work_struct hangup; - - unsigned int mstatus; - - spinlock_t lock; - unsigned int mctrl; - struct delayed_work drain; - struct dma_fifo tx_fifo; - int max_payload; - unsigned int status_mask; - unsigned int ignore_mask; - unsigned int break_ctl:1, - write_only:1, - overrun:1, - loopback:1; - unsigned long flags; - - struct fwtty_peer __rcu *peer; - - struct async_icount icount; - struct stats stats; -}; - -#define to_port(ptr, field) (container_of(ptr, struct fwtty_port, field)) - -/* bit #s for flags field */ -#define IN_TX 0 -#define STOP_TX 1 - -/* bitmasks for special mctrl/mstatus bits */ -#define OOB_RX_THROTTLE 0x00010000 -#define MCTRL_RSRVD 0x000e0000 -#define OOB_TX_THROTTLE 0x00100000 -#define MSTATUS_RSRVD 0x00e00000 - -#define MCTRL_MASK (TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | TIOCM_OUT2 | \ - TIOCM_LOOP | OOB_RX_THROTTLE | MCTRL_RSRVD) - -/* XXX even every 1/50th secs. may be unnecessarily accurate */ -/* delay in jiffies between brk emits */ -#define FREQ_BREAKS (HZ / 50) - -/* Ports are allocated in blocks of num_ports for each fw_card */ -#define MAX_CARD_PORTS CONFIG_FWTTY_MAX_CARD_PORTS -#define MAX_TOTAL_PORTS CONFIG_FWTTY_MAX_TOTAL_PORTS - -/* tuning parameters */ -#define FWTTY_PORT_TXFIFO_LEN 4096 -#define FWTTY_PORT_MAX_PEND_DMA 8 /* costs a cache line per pend */ -#define DRAIN_THRESHOLD 1024 -#define MAX_ASYNC_PAYLOAD 4096 /* ohci-defined limit */ -#define WRITER_MINIMUM 128 -/* TODO: how to set watermark to AR context size? see fwtty_rx() */ -#define HIGH_WATERMARK 32768 /* AR context is 32K */ - -/* - * Size of bus addr region above 4GB used per port as the recv addr - * - must be at least as big as the MAX_ASYNC_PAYLOAD - */ -#define FWTTY_PORT_RXFIFO_LEN MAX_ASYNC_PAYLOAD - -/** - * fw_serial: aggregate used to associate tty ports with specific fw_card - * @card: fw_card associated with this fw_serial device (1:1 association) - * @kref: reference-counted multi-port management allows delayed destroy - * @self: local unit device as 'peer'. Not valid until local unit device - * is enumerated. - * @list: link for insertion into fwserial_list - * @peer_list: list of local & remote unit devices attached to this card - * @ports: fixed array of tty_ports provided by this serial device - */ -struct fw_serial { - struct fw_card *card; - struct kref kref; - - struct dentry *debugfs; - struct fwtty_peer *self; - - struct list_head list; - struct list_head peer_list; - - struct fwtty_port *ports[MAX_CARD_PORTS]; -}; - -#define to_serial(ptr, field) (container_of(ptr, struct fw_serial, field)) - -#define TTY_DEV_NAME "fwtty" /* ttyFW was taken */ -static const char tty_dev_name[] = TTY_DEV_NAME; -static const char loop_dev_name[] = "fwloop"; - -extern struct tty_driver *fwtty_driver; - -/* - * Returns the max send async payload size in bytes based on the unit device - * link speed. Self-limiting asynchronous bandwidth (via reducing the payload) - * is not necessary and does not work, because - * 1) asynchronous traffic will absorb all available bandwidth (less that - * being used for isochronous traffic) - * 2) isochronous arbitration always wins. - */ -static inline int link_speed_to_max_payload(unsigned int speed) -{ - /* Max async payload is 4096 - see IEEE 1394-2008 tables 6-4, 16-18 */ - return min(512 << speed, 4096); -} - -#endif /* _FIREWIRE_FWSERIAL_H */ diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c index 493ed4821515..671ee8843c88 100644 --- a/drivers/staging/gdm724x/gdm_lte.c +++ b/drivers/staging/gdm724x/gdm_lte.c @@ -76,14 +76,15 @@ static void tx_complete(void *arg) static int gdm_lte_rx(struct sk_buff *skb, struct nic *nic, int nic_type) { - int ret; + int ret, len; - ret = netif_rx_ni(skb); + len = skb->len + ETH_HLEN; + ret = netif_rx(skb); if (ret == NET_RX_DROP) { nic->stats.rx_dropped++; } else { nic->stats.rx_packets++; - nic->stats.rx_bytes += skb->len + ETH_HLEN; + nic->stats.rx_bytes += len; } return 0; @@ -194,7 +195,6 @@ static __sum16 icmp6_checksum(struct ipv6hdr *ipv6, u16 *ptr, int len) pseudo_header.ph.ph_len = be16_to_cpu(ipv6->payload_len); pseudo_header.ph.ph_nxt = ipv6->nexthdr; - w = (u16 *)&pseudo_header; for (i = 0; i < ARRAY_SIZE(pseudo_header.pa); i++) { pa = pseudo_header.pa[i]; sum = csum_add(sum, csum_unfold((__force __sum16)pa)); diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c index 04df6f9f5403..cc6d80554c98 100644 --- a/drivers/staging/gdm724x/gdm_tty.c +++ b/drivers/staging/gdm724x/gdm_tty.c @@ -17,12 +17,6 @@ #define GDM_TTY_MAJOR 0 #define GDM_TTY_MINOR 32 -#define ACM_CTRL_DTR 0x01 -#define ACM_CTRL_RTS 0x02 -#define ACM_CTRL_DSR 0x02 -#define ACM_CTRL_RI 0x08 -#define ACM_CTRL_DCD 0x01 - #define WRITE_SIZE 2048 #define MUX_TX_MAX_SIZE 2048 diff --git a/drivers/staging/gdm724x/hci_packet.h b/drivers/staging/gdm724x/hci_packet.h index faecdfbc664f..3bb01e94f3b5 100644 --- a/drivers/staging/gdm724x/hci_packet.h +++ b/drivers/staging/gdm724x/hci_packet.h @@ -34,7 +34,7 @@ struct hci_packet { struct tlv { u8 type; u8 len; - u8 *data[1]; + u8 *data[]; } __packed; struct sdu_header { diff --git a/drivers/staging/greybus/arche-apb-ctrl.c b/drivers/staging/greybus/arche-apb-ctrl.c index bbf3ba744fc4..45afa208d004 100644 --- a/drivers/staging/greybus/arche-apb-ctrl.c +++ b/drivers/staging/greybus/arche-apb-ctrl.c @@ -445,7 +445,7 @@ static int __maybe_unused arche_apb_ctrl_suspend(struct device *dev) static int __maybe_unused arche_apb_ctrl_resume(struct device *dev) { /* - * Atleast for ES2 we have to meet the delay requirement between + * At least for ES2 we have to meet the delay requirement between * unipro switch and AP bridge init, depending on whether bridge is in * OFF state or standby state. * diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c index e374dfc0c92f..fcbd5f71eff2 100644 --- a/drivers/staging/greybus/arche-platform.c +++ b/drivers/staging/greybus/arche-platform.c @@ -591,7 +591,7 @@ static __maybe_unused int arche_platform_suspend(struct device *dev) static __maybe_unused int arche_platform_resume(struct device *dev) { /* - * Atleast for ES2 we have to meet the delay requirement between + * At least for ES2 we have to meet the delay requirement between * unipro switch and AP bridge init, depending on whether bridge is in * OFF state or standby state. * diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c index b589cf6b1d03..0ad8aeabccbf 100644 --- a/drivers/staging/greybus/audio_codec.c +++ b/drivers/staging/greybus/audio_codec.c @@ -497,7 +497,7 @@ static int gbcodec_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { int ret; - struct gbaudio_module_info *module; + struct gbaudio_module_info *module = NULL, *iter; struct gbaudio_data_connection *data; struct gb_bundle *bundle; struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev); @@ -511,11 +511,13 @@ static int gbcodec_prepare(struct snd_pcm_substream *substream, return -ENODEV; } - list_for_each_entry(module, &codec->module_list, list) { + list_for_each_entry(iter, &codec->module_list, list) { /* find the dai */ - data = find_data(module, dai->id); - if (data) + data = find_data(iter, dai->id); + if (data) { + module = iter; break; + } } if (!data) { dev_err(dai->dev, "DATA connection missing\n"); @@ -563,7 +565,7 @@ static int gbcodec_mute_stream(struct snd_soc_dai *dai, int mute, int stream) { int ret; struct gbaudio_data_connection *data; - struct gbaudio_module_info *module; + struct gbaudio_module_info *module = NULL, *iter; struct gb_bundle *bundle; struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev); struct gbaudio_stream_params *params; @@ -592,15 +594,17 @@ static int gbcodec_mute_stream(struct snd_soc_dai *dai, int mute, int stream) return ret; } - list_for_each_entry(module, &codec->module_list, list) { + list_for_each_entry(iter, &codec->module_list, list) { /* find the dai */ - data = find_data(module, dai->id); - if (data) + data = find_data(iter, dai->id); + if (data) { + module = iter; break; + } } if (!data) { - dev_err(dai->dev, "%s:%s DATA connection missing\n", - dai->name, module->name); + dev_err(dai->dev, "%s DATA connection missing\n", + dai->name); mutex_unlock(&codec->lock); return -ENODEV; } @@ -702,8 +706,9 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, headset->pin = module->jack_name; headset->mask = module->jack_mask; - ret = snd_soc_card_jack_new(card, module->jack_name, module->jack_mask, - &module->headset.jack, headset, 1); + ret = snd_soc_card_jack_new_pins(card, module->jack_name, + module->jack_mask, + &module->headset.jack, headset, 1); if (ret) { dev_err(module->dev, "Failed to create new jack\n"); return ret; @@ -725,9 +730,10 @@ static int gbaudio_init_jack(struct gbaudio_module_info *module, button->pin = module->button_name; button->mask = module->button_mask; - ret = snd_soc_card_jack_new(card, module->button_name, - module->button_mask, &module->button.jack, - button, 1); + ret = snd_soc_card_jack_new_pins(card, module->button_name, + module->button_mask, + &module->button.jack, + button, 1); if (ret) { dev_err(module->dev, "Failed to create button jack\n"); goto free_jacks; @@ -1025,12 +1031,6 @@ static int gbcodec_probe(struct snd_soc_component *comp) return 0; } -static void gbcodec_remove(struct snd_soc_component *comp) -{ - /* Empty function for now */ - return; -} - static int gbcodec_write(struct snd_soc_component *comp, unsigned int reg, unsigned int value) { @@ -1045,8 +1045,6 @@ static unsigned int gbcodec_read(struct snd_soc_component *comp, static const struct snd_soc_component_driver soc_codec_dev_gbaudio = { .probe = gbcodec_probe, - .remove = gbcodec_remove, - .read = gbcodec_read, .write = gbcodec_write, }; diff --git a/drivers/staging/greybus/audio_helper.c b/drivers/staging/greybus/audio_helper.c index 843760675876..223987616e07 100644 --- a/drivers/staging/greybus/audio_helper.c +++ b/drivers/staging/greybus/audio_helper.c @@ -3,7 +3,6 @@ * Greybus Audio Sound SoC helper APIs */ -#include <linux/debugfs.h> #include <sound/core.h> #include <sound/soc.h> #include <sound/soc-dapm.h> @@ -115,22 +114,18 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm, int num) { int i; - struct snd_soc_dapm_widget *w, *next_w; -#ifdef CONFIG_DEBUG_FS - struct dentry *parent = dapm->debugfs_dapm; - struct dentry *debugfs_w = NULL; -#endif + struct snd_soc_dapm_widget *w, *tmp_w; mutex_lock(&dapm->card->dapm_mutex); for (i = 0; i < num; i++) { /* below logic can be optimized to identify widget pointer */ - list_for_each_entry_safe(w, next_w, &dapm->card->widgets, - list) { - if (w->dapm != dapm) - continue; - if (!strcmp(w->name, widget->name)) + w = NULL; + list_for_each_entry(tmp_w, &dapm->card->widgets, list) { + if (tmp_w->dapm == dapm && + !strcmp(tmp_w->name, widget->name)) { + w = tmp_w; break; - w = NULL; + } } if (!w) { dev_err(dapm->dev, "%s: widget not found\n", @@ -139,12 +134,6 @@ int gbaudio_dapm_free_controls(struct snd_soc_dapm_context *dapm, continue; } widget++; -#ifdef CONFIG_DEBUG_FS - if (!parent) - debugfs_w = debugfs_lookup(w->name, parent); - debugfs_remove(debugfs_w); - debugfs_w = NULL; -#endif gbaudio_dapm_free_widget(w); } mutex_unlock(&dapm->card->dapm_mutex); diff --git a/drivers/staging/greybus/audio_manager_module.c b/drivers/staging/greybus/audio_manager_module.c index 525cf8f8394f..0a0f0a394c84 100644 --- a/drivers/staging/greybus/audio_manager_module.c +++ b/drivers/staging/greybus/audio_manager_module.c @@ -142,11 +142,12 @@ static struct attribute *gb_audio_module_default_attrs[] = { &gb_audio_module_op_devices_attribute.attr, NULL, /* need to NULL terminate the list of attributes */ }; +ATTRIBUTE_GROUPS(gb_audio_module_default); static struct kobj_type gb_audio_module_type = { .sysfs_ops = &gb_audio_module_sysfs_ops, .release = gb_audio_module_release, - .default_attrs = gb_audio_module_default_attrs, + .default_groups = gb_audio_module_default_groups, }; static void send_add_uevent(struct gb_audio_manager_module *module) diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c index 1e613d42d823..62d7674852be 100644 --- a/drivers/staging/greybus/audio_topology.c +++ b/drivers/staging/greybus/audio_topology.c @@ -147,6 +147,9 @@ static const char **gb_generate_enum_strings(struct gbaudio_module_info *gb, items = le32_to_cpu(gbenum->items); strings = devm_kcalloc(gb->dev, items, sizeof(char *), GFP_KERNEL); + if (!strings) + return NULL; + data = gbenum->names; for (i = 0; i < items; i++) { @@ -655,6 +658,8 @@ static int gbaudio_tplg_create_enum_kctl(struct gbaudio_module_info *gb, /* since count=1, and reg is dummy */ gbe->items = le32_to_cpu(gb_enum->items); gbe->texts = gb_generate_enum_strings(gb, gb_enum); + if (!gbe->texts) + return -ENOMEM; /* debug enum info */ dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->items, @@ -862,6 +867,8 @@ static int gbaudio_tplg_create_enum_ctl(struct gbaudio_module_info *gb, /* since count=1, and reg is dummy */ gbe->items = le32_to_cpu(gb_enum->items); gbe->texts = gb_generate_enum_strings(gb, gb_enum); + if (!gbe->texts) + return -ENOMEM; /* debug enum info */ dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->items, @@ -974,6 +981,44 @@ static int gbaudio_widget_event(struct snd_soc_dapm_widget *w, return ret; } +static const struct snd_soc_dapm_widget gbaudio_widgets[] = { + [snd_soc_dapm_spk] = SND_SOC_DAPM_SPK(NULL, gbcodec_event_spk), + [snd_soc_dapm_hp] = SND_SOC_DAPM_HP(NULL, gbcodec_event_hp), + [snd_soc_dapm_mic] = SND_SOC_DAPM_MIC(NULL, gbcodec_event_int_mic), + [snd_soc_dapm_output] = SND_SOC_DAPM_OUTPUT(NULL), + [snd_soc_dapm_input] = SND_SOC_DAPM_INPUT(NULL), + [snd_soc_dapm_switch] = SND_SOC_DAPM_SWITCH_E(NULL, SND_SOC_NOPM, + 0, 0, NULL, + gbaudio_widget_event, + SND_SOC_DAPM_PRE_PMU | + SND_SOC_DAPM_POST_PMD), + [snd_soc_dapm_pga] = SND_SOC_DAPM_PGA_E(NULL, SND_SOC_NOPM, + 0, 0, NULL, 0, + gbaudio_widget_event, + SND_SOC_DAPM_PRE_PMU | + SND_SOC_DAPM_POST_PMD), + [snd_soc_dapm_mixer] = SND_SOC_DAPM_MIXER_E(NULL, SND_SOC_NOPM, + 0, 0, NULL, 0, + gbaudio_widget_event, + SND_SOC_DAPM_PRE_PMU | + SND_SOC_DAPM_POST_PMD), + [snd_soc_dapm_mux] = SND_SOC_DAPM_MUX_E(NULL, SND_SOC_NOPM, + 0, 0, NULL, + gbaudio_widget_event, + SND_SOC_DAPM_PRE_PMU | + SND_SOC_DAPM_POST_PMD), + [snd_soc_dapm_aif_in] = SND_SOC_DAPM_AIF_IN_E(NULL, NULL, 0, + SND_SOC_NOPM, 0, 0, + gbaudio_widget_event, + SND_SOC_DAPM_PRE_PMU | + SND_SOC_DAPM_POST_PMD), + [snd_soc_dapm_aif_out] = SND_SOC_DAPM_AIF_OUT_E(NULL, NULL, 0, + SND_SOC_NOPM, 0, 0, + gbaudio_widget_event, + SND_SOC_DAPM_PRE_PMU | + SND_SOC_DAPM_POST_PMD), +}; + static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module, struct snd_soc_dapm_widget *dw, struct gb_audio_widget *w, int *w_size) @@ -1034,6 +1079,10 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module, csize += le16_to_cpu(gbenum->names_length); control->texts = (const char * const *) gb_generate_enum_strings(module, gbenum); + if (!control->texts) { + ret = -ENOMEM; + goto error; + } control->items = le32_to_cpu(gbenum->items); } else { csize = sizeof(struct gb_audio_control); @@ -1052,77 +1101,37 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module, switch (w->type) { case snd_soc_dapm_spk: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_SPK(w->name, gbcodec_event_spk); + *dw = gbaudio_widgets[w->type]; module->op_devices |= GBAUDIO_DEVICE_OUT_SPEAKER; break; case snd_soc_dapm_hp: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_HP(w->name, gbcodec_event_hp); + *dw = gbaudio_widgets[w->type]; module->op_devices |= (GBAUDIO_DEVICE_OUT_WIRED_HEADSET | GBAUDIO_DEVICE_OUT_WIRED_HEADPHONE); module->ip_devices |= GBAUDIO_DEVICE_IN_WIRED_HEADSET; break; case snd_soc_dapm_mic: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_MIC(w->name, gbcodec_event_int_mic); + *dw = gbaudio_widgets[w->type]; module->ip_devices |= GBAUDIO_DEVICE_IN_BUILTIN_MIC; break; case snd_soc_dapm_output: - *dw = (struct snd_soc_dapm_widget)SND_SOC_DAPM_OUTPUT(w->name); - break; case snd_soc_dapm_input: - *dw = (struct snd_soc_dapm_widget)SND_SOC_DAPM_INPUT(w->name); - break; case snd_soc_dapm_switch: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_SWITCH_E(w->name, SND_SOC_NOPM, 0, 0, - widget_kctls, - gbaudio_widget_event, - SND_SOC_DAPM_PRE_PMU | - SND_SOC_DAPM_POST_PMD); - break; case snd_soc_dapm_pga: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_PGA_E(w->name, SND_SOC_NOPM, 0, 0, NULL, 0, - gbaudio_widget_event, - SND_SOC_DAPM_PRE_PMU | - SND_SOC_DAPM_POST_PMD); - break; case snd_soc_dapm_mixer: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_MIXER_E(w->name, SND_SOC_NOPM, 0, 0, NULL, - 0, gbaudio_widget_event, - SND_SOC_DAPM_PRE_PMU | - SND_SOC_DAPM_POST_PMD); - break; case snd_soc_dapm_mux: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_MUX_E(w->name, SND_SOC_NOPM, 0, 0, - widget_kctls, gbaudio_widget_event, - SND_SOC_DAPM_PRE_PMU | - SND_SOC_DAPM_POST_PMD); + *dw = gbaudio_widgets[w->type]; break; case snd_soc_dapm_aif_in: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_AIF_IN_E(w->name, w->sname, 0, - SND_SOC_NOPM, - 0, 0, gbaudio_widget_event, - SND_SOC_DAPM_PRE_PMU | - SND_SOC_DAPM_POST_PMD); - break; case snd_soc_dapm_aif_out: - *dw = (struct snd_soc_dapm_widget) - SND_SOC_DAPM_AIF_OUT_E(w->name, w->sname, 0, - SND_SOC_NOPM, - 0, 0, gbaudio_widget_event, - SND_SOC_DAPM_PRE_PMU | - SND_SOC_DAPM_POST_PMD); + *dw = gbaudio_widgets[w->type]; + dw->sname = w->sname; break; default: ret = -EINVAL; goto error; } + dw->name = w->name; dev_dbg(module->dev, "%s: widget of type %d created\n", dw->name, dw->id); @@ -1183,6 +1192,10 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module, csize += le16_to_cpu(gbenum->names_length); control->texts = (const char * const *) gb_generate_enum_strings(module, gbenum); + if (!control->texts) { + ret = -ENOMEM; + goto error; + } control->items = le32_to_cpu(gbenum->items); } else { csize = sizeof(struct gb_audio_control); diff --git a/drivers/staging/greybus/fw-management.c b/drivers/staging/greybus/fw-management.c index 687c6405c65b..3342b84597da 100644 --- a/drivers/staging/greybus/fw-management.c +++ b/drivers/staging/greybus/fw-management.c @@ -102,7 +102,7 @@ unlock: } static int fw_mgmt_interface_fw_version_operation(struct fw_mgmt *fw_mgmt, - struct fw_mgmt_ioc_get_intf_version *fw_info) + struct fw_mgmt_ioc_get_intf_version *fw_info) { struct gb_connection *connection = fw_mgmt->connection; struct gb_fw_mgmt_interface_fw_version_response response; @@ -240,7 +240,7 @@ static int fw_mgmt_interface_fw_loaded_operation(struct gb_operation *op) } static int fw_mgmt_backend_fw_version_operation(struct fw_mgmt *fw_mgmt, - struct fw_mgmt_ioc_get_backend_version *fw_info) + struct fw_mgmt_ioc_get_backend_version *fw_info) { struct gb_connection *connection = fw_mgmt->connection; struct gb_fw_mgmt_backend_fw_version_request request; @@ -473,7 +473,7 @@ static int fw_mgmt_ioctl(struct fw_mgmt *fw_mgmt, unsigned int cmd, return -EFAULT; ret = fw_mgmt_backend_fw_update_operation(fw_mgmt, - backend_update.firmware_tag); + backend_update.firmware_tag); if (ret) return ret; diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c index 7e6347fe93f9..8a7cf1d0e968 100644 --- a/drivers/staging/greybus/gpio.c +++ b/drivers/staging/greybus/gpio.c @@ -391,10 +391,7 @@ static int gb_gpio_request_handler(struct gb_operation *op) return -EINVAL; } - local_irq_disable(); - ret = generic_handle_irq(irq); - local_irq_enable(); - + ret = generic_handle_irq_safe(irq); if (ret) dev_err(dev, "failed to invoke irq handler\n"); diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c index 2471448ba42a..1a61fce98056 100644 --- a/drivers/staging/greybus/loopback.c +++ b/drivers/staging/greybus/loopback.c @@ -870,7 +870,7 @@ static int gb_loopback_fn(void *data) if (gb->send_count == gb->iteration_max) { mutex_unlock(&gb->mutex); - /* Wait for synchronous and asynchronus completion */ + /* Wait for synchronous and asynchronous completion */ gb_loopback_async_wait_all(gb); /* Mark complete unless user-space has poked us */ diff --git a/drivers/staging/greybus/pwm.c b/drivers/staging/greybus/pwm.c index 891a6a672378..3fda172239d2 100644 --- a/drivers/staging/greybus/pwm.c +++ b/drivers/staging/greybus/pwm.c @@ -204,43 +204,59 @@ static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) gb_pwm_deactivate_operation(pwmc, pwm->hwpwm); } -static int gb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, - int duty_ns, int period_ns) +static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, + const struct pwm_state *state) { + int err; + bool enabled = pwm->state.enabled; + u64 period = state->period; + u64 duty_cycle = state->duty_cycle; struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); - return gb_pwm_config_operation(pwmc, pwm->hwpwm, duty_ns, period_ns); -}; + /* Set polarity */ + if (state->polarity != pwm->state.polarity) { + if (enabled) { + gb_pwm_disable_operation(pwmc, pwm->hwpwm); + enabled = false; + } + err = gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, state->polarity); + if (err) + return err; + } -static int gb_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, - enum pwm_polarity polarity) -{ - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); + if (!state->enabled) { + if (enabled) + gb_pwm_disable_operation(pwmc, pwm->hwpwm); + return 0; + } - return gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, polarity); -}; + /* + * Set period and duty cycle + * + * PWM privodes 64-bit period and duty_cycle, but greybus only accepts + * 32-bit, so their values have to be limited to U32_MAX. + */ + if (period > U32_MAX) + period = U32_MAX; -static int gb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) -{ - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); + if (duty_cycle > period) + duty_cycle = period; - return gb_pwm_enable_operation(pwmc, pwm->hwpwm); -}; + err = gb_pwm_config_operation(pwmc, pwm->hwpwm, duty_cycle, period); + if (err) + return err; -static void gb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) -{ - struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip); + /* enable/disable */ + if (!enabled) + return gb_pwm_enable_operation(pwmc, pwm->hwpwm); - gb_pwm_disable_operation(pwmc, pwm->hwpwm); -}; + return 0; +} static const struct pwm_ops gb_pwm_ops = { .request = gb_pwm_request, .free = gb_pwm_free, - .config = gb_pwm_config, - .set_polarity = gb_pwm_set_polarity, - .enable = gb_pwm_enable, - .disable = gb_pwm_disable, + .apply = gb_pwm_apply, .owner = THIS_MODULE, }; @@ -281,7 +297,6 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev, pwm->dev = &gbphy_dev->dev; pwm->ops = &gb_pwm_ops; - pwm->base = -1; /* Allocate base dynamically */ pwm->npwm = pwmc->pwm_max + 1; ret = pwmchip_add(pwm); diff --git a/drivers/staging/greybus/sdio.c b/drivers/staging/greybus/sdio.c index 37bf04c22dbc..25bee5335c70 100644 --- a/drivers/staging/greybus/sdio.c +++ b/drivers/staging/greybus/sdio.c @@ -858,7 +858,6 @@ static void gb_sdio_remove(struct gbphy_device *gbphy_dev) gb_connection_set_data(connection, NULL); mutex_unlock(&host->lock); - flush_workqueue(host->mrq_workqueue); destroy_workqueue(host->mrq_workqueue); gb_connection_disable_rx(connection); mmc_remove_host(mmc); diff --git a/drivers/staging/greybus/tools/Makefile b/drivers/staging/greybus/tools/Makefile index ad0ae8053b79..a3bbd73171f2 100644 --- a/drivers/staging/greybus/tools/Makefile +++ b/drivers/staging/greybus/tools/Makefile @@ -12,7 +12,8 @@ CFLAGS += -std=gnu99 -Wall -Wextra -g \ -Wredundant-decls \ -Wcast-align \ -Wsign-compare \ - -Wno-missing-field-initializers + -Wno-missing-field-initializers \ + -Wno-shift-negative-value CC := $(CROSS_COMPILE)gcc diff --git a/drivers/staging/greybus/tools/loopback_test.c b/drivers/staging/greybus/tools/loopback_test.c index 867bf289df2e..4c42e393cd3d 100644 --- a/drivers/staging/greybus/tools/loopback_test.c +++ b/drivers/staging/greybus/tools/loopback_test.c @@ -533,7 +533,7 @@ static int log_results(struct loopback_test *t) fd = open(file_name, O_WRONLY | O_CREAT | O_APPEND, 0644); if (fd < 0) { - fprintf(stderr, "unable to open %s for appendation\n", file_name); + fprintf(stderr, "unable to open %s for appending\n", file_name); abort(); } diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c index dc4ed0ff1ae2..90ff07f2cbf7 100644 --- a/drivers/staging/greybus/uart.c +++ b/drivers/staging/greybus/uart.c @@ -480,7 +480,7 @@ static int gb_tty_break_ctl(struct tty_struct *tty, int state) } static void gb_tty_set_termios(struct tty_struct *tty, - struct ktermios *termios_old) + const struct ktermios *termios_old) { struct gb_uart_set_line_coding_request newline; struct gb_tty *gb_tty = tty->driver_data; diff --git a/drivers/staging/gs_fpgaboot/Kconfig b/drivers/staging/gs_fpgaboot/Kconfig deleted file mode 100644 index 968a153c4ab6..000000000000 --- a/drivers/staging/gs_fpgaboot/Kconfig +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# "xilinx FPGA firmware download, fpgaboot" -# -config GS_FPGABOOT - tristate "Xilinx FPGA firmware download module" - help - Xilinx FPGA firmware download module diff --git a/drivers/staging/gs_fpgaboot/Makefile b/drivers/staging/gs_fpgaboot/Makefile deleted file mode 100644 index 33e238be63d6..000000000000 --- a/drivers/staging/gs_fpgaboot/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -gs_fpga-y += gs_fpgaboot.o io.o -obj-$(CONFIG_GS_FPGABOOT) += gs_fpga.o diff --git a/drivers/staging/gs_fpgaboot/README b/drivers/staging/gs_fpgaboot/README deleted file mode 100644 index ec1235a21bcc..000000000000 --- a/drivers/staging/gs_fpgaboot/README +++ /dev/null @@ -1,70 +0,0 @@ -============================================================================== -Linux Driver Source for Xilinx FPGA firmware download -============================================================================== - - -TABLE OF CONTENTS. - -1. SUMMARY -2. BACKGROUND -3. DESIGN -4. HOW TO USE -5. REFERENCE - -1. SUMMARY - - - Download Xilinx FPGA firmware - - This module downloads Xilinx FPGA firmware using gpio pins. - -2. BACKGROUND - - An FPGA (Field Programmable Gate Array) is a programmable hardware that is - used in various applications. Hardware design needs to programmed through - a dedicated device or CPU assisted way (serial or parallel). - This driver provides a way to download FPGA firmware. - -3. DESIGN - - - load Xilinx FPGA bitstream format[1] firmware image file using - kernel firmware framework, request_firmware() - - program the Xilinx FPGA using SelectMAP (parallel) mode [2] - - FPGA prgram is done by gpio based bit-banging, as an example - - platform independent file: gs_fpgaboot.c - - platform dependent file: io.c - -4. HOW TO USE - - $ insmod gs_fpga.ko file="xlinx_fpga_top_bitstream.bit" - $ rmmod gs_fpga - -5. USE CASE (from a mailing list discussion with Greg) - - a. As an FPGA development support tool, - During FPGA firmware development, you need to download a new FPGA - image frequently. - You would do that with a dedicated JTAG, which usually a limited - resource in the lab. - However, if you use my driver, you don't have to have a dedicated JTAG. - This is a real gain :) - - b. For the FPGA that runs without config after the download, which - doesn't talk to any of Linux interfaces (such as PCIE). - - We download FPGA firmware from user triggered or some other way, and that's it. - Since that FPGA runs on its own, it doesn't require a linux driver - after the download. - - c. For the FPGA that requires config after the download, which talk to - any of linux interfaces (such as PCIE) - - Then, this type of FPGA config can be put into device tree and have a - separate driver (pcie or others), then THAT driver calls my driver to - download FPGA firmware during the Linux boot, the take over the device - through the interface. - -6. REFERENCE - - 1. Xilinx APP NOTE XAPP583: - https://www.xilinx.com/support/documentation/application_notes/xapp583-fpga-configuration.pdf - 2. bitstream file info: - http://home.earthlink.net/~davesullins/software/bitinfo.html diff --git a/drivers/staging/gs_fpgaboot/TODO b/drivers/staging/gs_fpgaboot/TODO deleted file mode 100644 index 2d9fb17d606d..000000000000 --- a/drivers/staging/gs_fpgaboot/TODO +++ /dev/null @@ -1,7 +0,0 @@ -TODO: - - get bus width input instead of hardcoded bus width - - get it reviewed - -Please send any patches for this driver to Insop Song<insop.song@gainspeed.com> -and Greg Kroah-Hartman <gregkh@linuxfoundation.org>. -And please CC to "Staging subsystem" mail list <devel@driverdev.osuosl.org> too. diff --git a/drivers/staging/gs_fpgaboot/gs_fpgaboot.c b/drivers/staging/gs_fpgaboot/gs_fpgaboot.c deleted file mode 100644 index 3e154562c64d..000000000000 --- a/drivers/staging/gs_fpgaboot/gs_fpgaboot.c +++ /dev/null @@ -1,394 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ - -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/module.h> -#include <linux/types.h> -#include <linux/device.h> -#include <linux/string.h> -#include <linux/slab.h> -#include <linux/fs.h> -#include <linux/platform_device.h> -#include <linux/of.h> -#include <linux/delay.h> -#include <linux/io.h> -#include <linux/firmware.h> -#include <asm/unaligned.h> - -#include "gs_fpgaboot.h" -#include "io.h" - -#define DEVICE_NAME "device" -#define CLASS_NAME "fpgaboot" - -static u8 bits_magic[] = { - 0x0, 0x9, 0xf, 0xf0, 0xf, 0xf0, - 0xf, 0xf0, 0xf, 0xf0, 0x0, 0x0, 0x1}; - -/* fake device for request_firmware */ -static struct platform_device *firmware_pdev; - -static char *file = "xlinx_fpga_firmware.bit"; -module_param(file, charp, 0444); -MODULE_PARM_DESC(file, "Xilinx FPGA firmware file."); - -static void read_bitstream(u8 *bitdata, u8 *buf, int *offset, int rdsize) -{ - memcpy(buf, bitdata + *offset, rdsize); - *offset += rdsize; -} - -static int readinfo_bitstream(u8 *bitdata, u8 *buf, int size, int *offset) -{ - u8 tbuf[2]; - u16 len; - - /* read section char */ - read_bitstream(bitdata, tbuf, offset, 1); - - /* read length */ - read_bitstream(bitdata, tbuf, offset, 2); - - len = get_unaligned_be16(tbuf); - if (len >= size) { - pr_err("error: readinfo buffer too small\n"); - return -EINVAL; - } - - read_bitstream(bitdata, buf, offset, len); - buf[len] = '\0'; - - return 0; -} - -/* - * read bitdata length - */ -static int readlength_bitstream(u8 *bitdata, int *lendata, int *offset) -{ - u8 tbuf[4]; - - /* read section char */ - read_bitstream(bitdata, tbuf, offset, 1); - - /* make sure it is section 'e' */ - if (tbuf[0] != 'e') { - pr_err("error: length section is not 'e', but %c\n", tbuf[0]); - return -EINVAL; - } - - /* read 4bytes length */ - read_bitstream(bitdata, tbuf, offset, 4); - - *lendata = get_unaligned_be32(tbuf); - - return 0; -} - -/* - * read first 13 bytes to check bitstream magic number - */ -static int readmagic_bitstream(u8 *bitdata, int *offset) -{ - u8 buf[13]; - int r; - - read_bitstream(bitdata, buf, offset, 13); - r = memcmp(buf, bits_magic, 13); - if (r) { - pr_err("error: corrupted header\n"); - return -EINVAL; - } - pr_info("bitstream file magic number Ok\n"); - - *offset = 13; /* magic length */ - - return 0; -} - -/* - * NOTE: supports only bitstream format - */ -static enum fmt_image get_imageformat(void) -{ - return f_bit; -} - -static void gs_print_header(struct fpgaimage *fimage) -{ - pr_info("file: %s\n", fimage->filename); - pr_info("part: %s\n", fimage->part); - pr_info("date: %s\n", fimage->date); - pr_info("time: %s\n", fimage->time); - pr_info("lendata: %d\n", fimage->lendata); -} - -static int gs_read_bitstream(struct fpgaimage *fimage) -{ - u8 *bitdata; - int offset; - int err; - - offset = 0; - bitdata = (u8 *)fimage->fw_entry->data; - - err = readmagic_bitstream(bitdata, &offset); - if (err) - return err; - - err = readinfo_bitstream(bitdata, fimage->filename, MAX_STR, &offset); - if (err) - return err; - err = readinfo_bitstream(bitdata, fimage->part, MAX_STR, &offset); - if (err) - return err; - err = readinfo_bitstream(bitdata, fimage->date, MAX_STR, &offset); - if (err) - return err; - err = readinfo_bitstream(bitdata, fimage->time, MAX_STR, &offset); - if (err) - return err; - - err = readlength_bitstream(bitdata, &fimage->lendata, &offset); - if (err) - return err; - - fimage->fpgadata = bitdata + offset; - - return 0; -} - -static int gs_read_image(struct fpgaimage *fimage) -{ - int img_fmt; - int err; - - img_fmt = get_imageformat(); - - switch (img_fmt) { - case f_bit: - pr_info("image is bitstream format\n"); - err = gs_read_bitstream(fimage); - if (err) - return err; - break; - default: - pr_err("unsupported fpga image format\n"); - return -EINVAL; - } - - gs_print_header(fimage); - - return 0; -} - -static int gs_load_image(struct fpgaimage *fimage, char *fw_file) -{ - int err; - - pr_info("load fpgaimage %s\n", fw_file); - - err = request_firmware(&fimage->fw_entry, fw_file, &firmware_pdev->dev); - if (err != 0) { - pr_err("firmware %s is missing, cannot continue.\n", fw_file); - return err; - } - - return 0; -} - -static int gs_download_image(struct fpgaimage *fimage, enum wbus bus_bytes) -{ - u8 *bitdata; - int size, i, cnt; - - cnt = 0; - bitdata = (u8 *)fimage->fpgadata; - size = fimage->lendata; - -#ifdef DEBUG_FPGA - print_hex_dump_bytes("bitfile sample: ", DUMP_PREFIX_OFFSET, - bitdata, 0x100); -#endif /* DEBUG_FPGA */ - if (!xl_supported_prog_bus_width(bus_bytes)) { - pr_err("unsupported program bus width %d\n", - bus_bytes); - return -EINVAL; - } - - /* Bring csi_b, rdwr_b Low and program_b High */ - xl_program_b(1); - xl_rdwr_b(0); - xl_csi_b(0); - - /* Configuration reset */ - xl_program_b(0); - msleep(20); - xl_program_b(1); - - /* Wait for Device Initialization */ - while (xl_get_init_b() == 0) - ; - - pr_info("device init done\n"); - - for (i = 0; i < size; i += bus_bytes) - xl_shift_bytes_out(bus_bytes, bitdata + i); - - pr_info("program done\n"); - - /* Check INIT_B */ - if (xl_get_init_b() == 0) { - pr_err("init_b 0\n"); - return -EIO; - } - - while (xl_get_done_b() == 0) { - if (cnt++ > MAX_WAIT_DONE) { - pr_err("init_B %d\n", xl_get_init_b()); - break; - } - } - - if (cnt > MAX_WAIT_DONE) { - pr_err("fpga download fail\n"); - return -EIO; - } - - pr_info("download fpgaimage\n"); - - /* Compensate for Special Startup Conditions */ - xl_shift_cclk(8); - - return 0; -} - -static int gs_release_image(struct fpgaimage *fimage) -{ - release_firmware(fimage->fw_entry); - pr_info("release fpgaimage\n"); - - return 0; -} - -/* - * NOTE: supports systemmap parallel programming - */ -static int gs_set_download_method(struct fpgaimage *fimage) -{ - pr_info("set program method\n"); - - fimage->dmethod = m_systemmap; - - pr_info("systemmap program method\n"); - - return 0; -} - -static int init_driver(void) -{ - firmware_pdev = platform_device_register_simple("fpgaboot", -1, - NULL, 0); - return PTR_ERR_OR_ZERO(firmware_pdev); -} - -static int gs_fpgaboot(void) -{ - int err; - struct fpgaimage *fimage; - - fimage = kmalloc(sizeof(*fimage), GFP_KERNEL); - if (!fimage) - return -ENOMEM; - - err = gs_load_image(fimage, file); - if (err) { - pr_err("gs_load_image error\n"); - goto err_out1; - } - - err = gs_read_image(fimage); - if (err) { - pr_err("gs_read_image error\n"); - goto err_out2; - } - - err = gs_set_download_method(fimage); - if (err) { - pr_err("gs_set_download_method error\n"); - goto err_out2; - } - - err = gs_download_image(fimage, bus_2byte); - if (err) { - pr_err("gs_download_image error\n"); - goto err_out2; - } - - err = gs_release_image(fimage); - if (err) { - pr_err("gs_release_image error\n"); - goto err_out1; - } - - kfree(fimage); - return 0; - -err_out2: - err = gs_release_image(fimage); - if (err) - pr_err("gs_release_image error\n"); -err_out1: - kfree(fimage); - - return err; -} - -static int __init gs_fpgaboot_init(void) -{ - int err; - - pr_info("FPGA DOWNLOAD --->\n"); - - pr_info("FPGA image file name: %s\n", file); - - err = init_driver(); - if (err) { - pr_err("FPGA DRIVER INIT FAIL!!\n"); - return err; - } - - err = xl_init_io(); - if (err) { - pr_err("GPIO INIT FAIL!!\n"); - goto errout; - } - - err = gs_fpgaboot(); - if (err) { - pr_err("FPGA DOWNLOAD FAIL!!\n"); - goto errout; - } - - pr_info("FPGA DOWNLOAD DONE <---\n"); - - return 0; - -errout: - platform_device_unregister(firmware_pdev); - - return err; -} - -static void __exit gs_fpgaboot_exit(void) -{ - platform_device_unregister(firmware_pdev); - pr_info("FPGA image download module removed\n"); -} - -module_init(gs_fpgaboot_init); -module_exit(gs_fpgaboot_exit); - -MODULE_AUTHOR("Insop Song"); -MODULE_DESCRIPTION("Xlinix FPGA firmware download"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/gs_fpgaboot/gs_fpgaboot.h b/drivers/staging/gs_fpgaboot/gs_fpgaboot.h deleted file mode 100644 index 5cf12c14cca4..000000000000 --- a/drivers/staging/gs_fpgaboot/gs_fpgaboot.h +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ - -#include <linux/firmware.h> - -#define MAX_STR 256 - -enum fmt_image { - f_bit, /* only bitstream is supported */ - f_rbt, - f_bin, - f_mcs, - f_hex, -}; - -enum mdownload { - m_systemmap, /* only system map is supported */ - m_serial, - m_jtag, -}; - -/* - * xilinx fpgaimage information - * NOTE: use MAX_STR instead of dynamic alloc for simplicity - */ -struct fpgaimage { - enum fmt_image fmt_img; - enum mdownload dmethod; - - const struct firmware *fw_entry; - - /* - * the following can be read from bitstream, - * but other image format should have as well - */ - char filename[MAX_STR]; - char part[MAX_STR]; - char date[MAX_STR]; - char time[MAX_STR]; - int lendata; - u8 *fpgadata; -}; diff --git a/drivers/staging/gs_fpgaboot/io.c b/drivers/staging/gs_fpgaboot/io.c deleted file mode 100644 index 80903ec36b76..000000000000 --- a/drivers/staging/gs_fpgaboot/io.c +++ /dev/null @@ -1,105 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ - -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/module.h> -#include <linux/types.h> -#include <linux/device.h> -#include <linux/string.h> -#include <linux/slab.h> -#include <linux/fs.h> -#include <linux/platform_device.h> -#include <linux/of.h> -#include <linux/of_address.h> -#include <linux/firmware.h> -#include <linux/io.h> - -#include "io.h" - -static inline void byte0_out(unsigned char data); -static inline void byte1_out(unsigned char data); -static inline void xl_cclk_b(int32_t i); - -/* Assert and Deassert CCLK */ -void xl_shift_cclk(int count) -{ - int i; - - for (i = 0; i < count; i++) { - xl_cclk_b(1); - xl_cclk_b(0); - } -} - -int xl_supported_prog_bus_width(enum wbus bus_bytes) -{ - switch (bus_bytes) { - case bus_1byte: - break; - case bus_2byte: - break; - default: - pr_err("unsupported program bus width %d\n", bus_bytes); - return 0; - } - - return 1; -} - -/* Serialize byte and clock each bit on target's DIN and CCLK pins */ -void xl_shift_bytes_out(enum wbus bus_byte, unsigned char *pdata) -{ - /* - * supports 1 and 2 bytes programming mode - */ - if (likely(bus_byte == bus_2byte)) - byte0_out(pdata[0]); - - byte1_out(pdata[1]); - xl_shift_cclk(1); -} - -/* - * generic bit swap for xilinx SYSTEMMAP FPGA programming - */ -void xl_program_b(int32_t i) -{ -} - -void xl_rdwr_b(int32_t i) -{ -} - -void xl_csi_b(int32_t i) -{ -} - -int xl_get_init_b(void) -{ - return -1; -} - -int xl_get_done_b(void) -{ - return -1; -} - -static inline void byte0_out(unsigned char data) -{ -} - -static inline void byte1_out(unsigned char data) -{ -} - -static inline void xl_cclk_b(int32_t i) -{ -} - -/* - * configurable per device type for different I/O config - */ -int xl_init_io(void) -{ - return -1; -} diff --git a/drivers/staging/gs_fpgaboot/io.h b/drivers/staging/gs_fpgaboot/io.h deleted file mode 100644 index 9bd86a92e90f..000000000000 --- a/drivers/staging/gs_fpgaboot/io.h +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ - -#define GPDIR 0 -#define GPCFG 4 /* open drain or not */ -#define GPDAT 8 - -/* - * gpio port and pin definitions - * NOTE: port number starts from 0 - */ -#define XL_INITN_PORT 1 -#define XL_INITN_PIN 14 -#define XL_RDWRN_PORT 1 -#define XL_RDWRN_PIN 13 -#define XL_CCLK_PORT 1 -#define XL_CCLK_PIN 10 -#define XL_PROGN_PORT 1 -#define XL_PROGN_PIN 25 -#define XL_CSIN_PORT 1 -#define XL_CSIN_PIN 26 -#define XL_DONE_PORT 1 -#define XL_DONE_PIN 27 - -/* - * gpio mapping - * - XL_config_D0 – gpio1_31 - Xl_config_d1 – gpio1_30 - Xl_config_d2 – gpio1_29 - Xl_config_d3 – gpio1_28 - Xl_config_d4 – gpio1_27 - Xl_config_d5 – gpio1_26 - Xl_config_d6 – gpio1_25 - Xl_config_d7 – gpio1_24 - Xl_config_d8 – gpio1_23 - Xl_config_d9 – gpio1_22 - Xl_config_d10 – gpio1_21 - Xl_config_d11 – gpio1_20 - Xl_config_d12 – gpio1_19 - Xl_config_d13 – gpio1_18 - Xl_config_d14 – gpio1_16 - Xl_config_d15 – gpio1_14 -* -*/ - -/* - * program bus width in bytes - */ -enum wbus { - bus_1byte = 1, - bus_2byte = 2, -}; - -#define MAX_WAIT_DONE 10000 - -struct gpiobus { - int ngpio; - void __iomem *r[4]; -}; - -int xl_supported_prog_bus_width(enum wbus bus_bytes); - -void xl_program_b(int32_t i); -void xl_rdwr_b(int32_t i); -void xl_csi_b(int32_t i); - -int xl_get_init_b(void); -int xl_get_done_b(void); - -void xl_shift_cclk(int count); -void xl_shift_bytes_out(enum wbus bus_byte, unsigned char *pdata); - -int xl_init_io(void); diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig index a8e970db179d..afd05bf3345e 100644 --- a/drivers/staging/iio/Kconfig +++ b/drivers/staging/iio/Kconfig @@ -8,7 +8,6 @@ menu "IIO staging drivers" source "drivers/staging/iio/accel/Kconfig" source "drivers/staging/iio/adc/Kconfig" source "drivers/staging/iio/addac/Kconfig" -source "drivers/staging/iio/cdc/Kconfig" source "drivers/staging/iio/frequency/Kconfig" source "drivers/staging/iio/impedance-analyzer/Kconfig" source "drivers/staging/iio/meter/Kconfig" diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile index b15904b99581..5ed56fe57e14 100644 --- a/drivers/staging/iio/Makefile +++ b/drivers/staging/iio/Makefile @@ -6,7 +6,6 @@ obj-y += accel/ obj-y += adc/ obj-y += addac/ -obj-y += cdc/ obj-y += frequency/ obj-y += impedance-analyzer/ obj-y += meter/ diff --git a/drivers/staging/iio/accel/adis16203.c b/drivers/staging/iio/accel/adis16203.c index 1d3026dae827..62d5397ff1f9 100644 --- a/drivers/staging/iio/accel/adis16203.c +++ b/drivers/staging/iio/accel/adis16203.c @@ -312,3 +312,4 @@ MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); MODULE_DESCRIPTION("Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("spi:adis16203"); +MODULE_IMPORT_NS(IIO_ADISLIB); diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c index 2a8aa83b8d9e..bca857eef92e 100644 --- a/drivers/staging/iio/accel/adis16240.c +++ b/drivers/staging/iio/accel/adis16240.c @@ -440,3 +440,4 @@ MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); MODULE_DESCRIPTION("Analog Devices Programmable Impact Sensor and Recorder"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("spi:adis16240"); +MODULE_IMPORT_NS(IIO_ADISLIB); diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index b25f41053fac..2f0d6cf048d2 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -15,15 +15,4 @@ config AD7816 To compile this driver as a module, choose M here: the module will be called ad7816. -config AD7280 - tristate "Analog Devices AD7280A Lithium Ion Battery Monitoring System" - depends on SPI - select CRC8 - help - Say yes here to build support for Analog Devices AD7280A - Lithium Ion Battery Monitoring System. - - To compile this driver as a module, choose M here: the - module will be called ad7280a - endmenu diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile index 6436a62b6278..1e2a94c4db84 100644 --- a/drivers/staging/iio/adc/Makefile +++ b/drivers/staging/iio/adc/Makefile @@ -4,4 +4,3 @@ # obj-$(CONFIG_AD7816) += ad7816.o -obj-$(CONFIG_AD7280) += ad7280a.o diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c deleted file mode 100644 index fef0055b8990..000000000000 --- a/drivers/staging/iio/adc/ad7280a.c +++ /dev/null @@ -1,1044 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * AD7280A Lithium Ion Battery Monitoring System - * - * Copyright 2011 Analog Devices Inc. - */ - -#include <linux/crc8.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/sysfs.h> -#include <linux/spi/spi.h> -#include <linux/err.h> -#include <linux/delay.h> -#include <linux/interrupt.h> -#include <linux/module.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/events.h> - -#include "ad7280a.h" - -/* Registers */ -#define AD7280A_CELL_VOLTAGE_1 0x0 /* D11 to D0, Read only */ -#define AD7280A_CELL_VOLTAGE_2 0x1 /* D11 to D0, Read only */ -#define AD7280A_CELL_VOLTAGE_3 0x2 /* D11 to D0, Read only */ -#define AD7280A_CELL_VOLTAGE_4 0x3 /* D11 to D0, Read only */ -#define AD7280A_CELL_VOLTAGE_5 0x4 /* D11 to D0, Read only */ -#define AD7280A_CELL_VOLTAGE_6 0x5 /* D11 to D0, Read only */ -#define AD7280A_AUX_ADC_1 0x6 /* D11 to D0, Read only */ -#define AD7280A_AUX_ADC_2 0x7 /* D11 to D0, Read only */ -#define AD7280A_AUX_ADC_3 0x8 /* D11 to D0, Read only */ -#define AD7280A_AUX_ADC_4 0x9 /* D11 to D0, Read only */ -#define AD7280A_AUX_ADC_5 0xA /* D11 to D0, Read only */ -#define AD7280A_AUX_ADC_6 0xB /* D11 to D0, Read only */ -#define AD7280A_SELF_TEST 0xC /* D11 to D0, Read only */ -#define AD7280A_CONTROL_HB 0xD /* D15 to D8, Read/write */ -#define AD7280A_CONTROL_LB 0xE /* D7 to D0, Read/write */ -#define AD7280A_CELL_OVERVOLTAGE 0xF /* D7 to D0, Read/write */ -#define AD7280A_CELL_UNDERVOLTAGE 0x10 /* D7 to D0, Read/write */ -#define AD7280A_AUX_ADC_OVERVOLTAGE 0x11 /* D7 to D0, Read/write */ -#define AD7280A_AUX_ADC_UNDERVOLTAGE 0x12 /* D7 to D0, Read/write */ -#define AD7280A_ALERT 0x13 /* D7 to D0, Read/write */ -#define AD7280A_CELL_BALANCE 0x14 /* D7 to D0, Read/write */ -#define AD7280A_CB1_TIMER 0x15 /* D7 to D0, Read/write */ -#define AD7280A_CB2_TIMER 0x16 /* D7 to D0, Read/write */ -#define AD7280A_CB3_TIMER 0x17 /* D7 to D0, Read/write */ -#define AD7280A_CB4_TIMER 0x18 /* D7 to D0, Read/write */ -#define AD7280A_CB5_TIMER 0x19 /* D7 to D0, Read/write */ -#define AD7280A_CB6_TIMER 0x1A /* D7 to D0, Read/write */ -#define AD7280A_PD_TIMER 0x1B /* D7 to D0, Read/write */ -#define AD7280A_READ 0x1C /* D7 to D0, Read/write */ -#define AD7280A_CNVST_CONTROL 0x1D /* D7 to D0, Read/write */ - -/* Bits and Masks */ -#define AD7280A_CTRL_HB_CONV_INPUT_ALL 0 -#define AD7280A_CTRL_HB_CONV_INPUT_6CELL_AUX1_3_4 BIT(6) -#define AD7280A_CTRL_HB_CONV_INPUT_6CELL BIT(7) -#define AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST (BIT(7) | BIT(6)) -#define AD7280A_CTRL_HB_CONV_RES_READ_ALL 0 -#define AD7280A_CTRL_HB_CONV_RES_READ_6CELL_AUX1_3_4 BIT(4) -#define AD7280A_CTRL_HB_CONV_RES_READ_6CELL BIT(5) -#define AD7280A_CTRL_HB_CONV_RES_READ_NO (BIT(5) | BIT(4)) -#define AD7280A_CTRL_HB_CONV_START_CNVST 0 -#define AD7280A_CTRL_HB_CONV_START_CS BIT(3) -#define AD7280A_CTRL_HB_CONV_AVG_DIS 0 -#define AD7280A_CTRL_HB_CONV_AVG_2 BIT(1) -#define AD7280A_CTRL_HB_CONV_AVG_4 BIT(2) -#define AD7280A_CTRL_HB_CONV_AVG_8 (BIT(2) | BIT(1)) -#define AD7280A_CTRL_HB_CONV_AVG(x) ((x) << 1) -#define AD7280A_CTRL_HB_PWRDN_SW BIT(0) - -#define AD7280A_CTRL_LB_SWRST BIT(7) -#define AD7280A_CTRL_LB_ACQ_TIME_400ns 0 -#define AD7280A_CTRL_LB_ACQ_TIME_800ns BIT(5) -#define AD7280A_CTRL_LB_ACQ_TIME_1200ns BIT(6) -#define AD7280A_CTRL_LB_ACQ_TIME_1600ns (BIT(6) | BIT(5)) -#define AD7280A_CTRL_LB_ACQ_TIME(x) ((x) << 5) -#define AD7280A_CTRL_LB_MUST_SET BIT(4) -#define AD7280A_CTRL_LB_THERMISTOR_EN BIT(3) -#define AD7280A_CTRL_LB_LOCK_DEV_ADDR BIT(2) -#define AD7280A_CTRL_LB_INC_DEV_ADDR BIT(1) -#define AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN BIT(0) - -#define AD7280A_ALERT_GEN_STATIC_HIGH BIT(6) -#define AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN (BIT(7) | BIT(6)) - -#define AD7280A_ALL_CELLS (0xAD << 16) - -#define AD7280A_MAX_SPI_CLK_HZ 700000 /* < 1MHz */ -#define AD7280A_MAX_CHAIN 8 -#define AD7280A_CELLS_PER_DEV 6 -#define AD7280A_BITS 12 -#define AD7280A_NUM_CH (AD7280A_AUX_ADC_6 - \ - AD7280A_CELL_VOLTAGE_1 + 1) - -#define AD7280A_CALC_VOLTAGE_CHAN_NUM(d, c) (((d) * AD7280A_CELLS_PER_DEV) + \ - (c)) -#define AD7280A_CALC_TEMP_CHAN_NUM(d, c) (((d) * AD7280A_CELLS_PER_DEV) + \ - (c) - AD7280A_CELLS_PER_DEV) - -#define AD7280A_DEVADDR_MASTER 0 -#define AD7280A_DEVADDR_ALL 0x1F -/* 5-bit device address is sent LSB first */ -static unsigned int ad7280a_devaddr(unsigned int addr) -{ - return ((addr & 0x1) << 4) | - ((addr & 0x2) << 3) | - (addr & 0x4) | - ((addr & 0x8) >> 3) | - ((addr & 0x10) >> 4); -} - -/* During a read a valid write is mandatory. - * So writing to the highest available address (Address 0x1F) - * and setting the address all parts bit to 0 is recommended - * So the TXVAL is AD7280A_DEVADDR_ALL + CRC - */ -#define AD7280A_READ_TXVAL 0xF800030A - -/* - * AD7280 CRC - * - * P(x) = x^8 + x^5 + x^3 + x^2 + x^1 + x^0 = 0b100101111 => 0x2F - */ -#define POLYNOM 0x2F - -struct ad7280_state { - struct spi_device *spi; - struct iio_chan_spec *channels; - struct iio_dev_attr *iio_attr; - int slave_num; - int scan_cnt; - int readback_delay_us; - unsigned char crc_tab[CRC8_TABLE_SIZE]; - unsigned char ctrl_hb; - unsigned char ctrl_lb; - unsigned char cell_threshhigh; - unsigned char cell_threshlow; - unsigned char aux_threshhigh; - unsigned char aux_threshlow; - unsigned char cb_mask[AD7280A_MAX_CHAIN]; - struct mutex lock; /* protect sensor state */ - - __be32 buf[2] ____cacheline_aligned; -}; - -static unsigned char ad7280_calc_crc8(unsigned char *crc_tab, unsigned int val) -{ - unsigned char crc; - - crc = crc_tab[val >> 16 & 0xFF]; - crc = crc_tab[crc ^ (val >> 8 & 0xFF)]; - - return crc ^ (val & 0xFF); -} - -static int ad7280_check_crc(struct ad7280_state *st, unsigned int val) -{ - unsigned char crc = ad7280_calc_crc8(st->crc_tab, val >> 10); - - if (crc != ((val >> 2) & 0xFF)) - return -EIO; - - return 0; -} - -/* After initiating a conversion sequence we need to wait until the - * conversion is done. The delay is typically in the range of 15..30 us - * however depending an the number of devices in the daisy chain and the - * number of averages taken, conversion delays and acquisition time options - * it may take up to 250us, in this case we better sleep instead of busy - * wait. - */ - -static void ad7280_delay(struct ad7280_state *st) -{ - if (st->readback_delay_us < 50) - udelay(st->readback_delay_us); - else - usleep_range(250, 500); -} - -static int __ad7280_read32(struct ad7280_state *st, unsigned int *val) -{ - int ret; - struct spi_transfer t = { - .tx_buf = &st->buf[0], - .rx_buf = &st->buf[1], - .len = 4, - }; - - st->buf[0] = cpu_to_be32(AD7280A_READ_TXVAL); - - ret = spi_sync_transfer(st->spi, &t, 1); - if (ret) - return ret; - - *val = be32_to_cpu(st->buf[1]); - - return 0; -} - -static int ad7280_write(struct ad7280_state *st, unsigned int devaddr, - unsigned int addr, bool all, unsigned int val) -{ - unsigned int reg = devaddr << 27 | addr << 21 | - (val & 0xFF) << 13 | all << 12; - - reg |= ad7280_calc_crc8(st->crc_tab, reg >> 11) << 3 | 0x2; - st->buf[0] = cpu_to_be32(reg); - - return spi_write(st->spi, &st->buf[0], 4); -} - -static int ad7280_read(struct ad7280_state *st, unsigned int devaddr, - unsigned int addr) -{ - int ret; - unsigned int tmp; - - /* turns off the read operation on all parts */ - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, - AD7280A_CTRL_HB_CONV_INPUT_ALL | - AD7280A_CTRL_HB_CONV_RES_READ_NO | - st->ctrl_hb); - if (ret) - return ret; - - /* turns on the read operation on the addressed part */ - ret = ad7280_write(st, devaddr, AD7280A_CONTROL_HB, 0, - AD7280A_CTRL_HB_CONV_INPUT_ALL | - AD7280A_CTRL_HB_CONV_RES_READ_ALL | - st->ctrl_hb); - if (ret) - return ret; - - /* Set register address on the part to be read from */ - ret = ad7280_write(st, devaddr, AD7280A_READ, 0, addr << 2); - if (ret) - return ret; - - ret = __ad7280_read32(st, &tmp); - if (ret) - return ret; - - if (ad7280_check_crc(st, tmp)) - return -EIO; - - if (((tmp >> 27) != devaddr) || (((tmp >> 21) & 0x3F) != addr)) - return -EFAULT; - - return (tmp >> 13) & 0xFF; -} - -static int ad7280_read_channel(struct ad7280_state *st, unsigned int devaddr, - unsigned int addr) -{ - int ret; - unsigned int tmp; - - ret = ad7280_write(st, devaddr, AD7280A_READ, 0, addr << 2); - if (ret) - return ret; - - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, - AD7280A_CTRL_HB_CONV_INPUT_ALL | - AD7280A_CTRL_HB_CONV_RES_READ_NO | - st->ctrl_hb); - if (ret) - return ret; - - ret = ad7280_write(st, devaddr, AD7280A_CONTROL_HB, 0, - AD7280A_CTRL_HB_CONV_INPUT_ALL | - AD7280A_CTRL_HB_CONV_RES_READ_ALL | - AD7280A_CTRL_HB_CONV_START_CS | - st->ctrl_hb); - if (ret) - return ret; - - ad7280_delay(st); - - ret = __ad7280_read32(st, &tmp); - if (ret) - return ret; - - if (ad7280_check_crc(st, tmp)) - return -EIO; - - if (((tmp >> 27) != devaddr) || (((tmp >> 23) & 0xF) != addr)) - return -EFAULT; - - return (tmp >> 11) & 0xFFF; -} - -static int ad7280_read_all_channels(struct ad7280_state *st, unsigned int cnt, - unsigned int *array) -{ - int i, ret; - unsigned int tmp, sum = 0; - - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_READ, 1, - AD7280A_CELL_VOLTAGE_1 << 2); - if (ret) - return ret; - - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, - AD7280A_CTRL_HB_CONV_INPUT_ALL | - AD7280A_CTRL_HB_CONV_RES_READ_ALL | - AD7280A_CTRL_HB_CONV_START_CS | - st->ctrl_hb); - if (ret) - return ret; - - ad7280_delay(st); - - for (i = 0; i < cnt; i++) { - ret = __ad7280_read32(st, &tmp); - if (ret) - return ret; - - if (ad7280_check_crc(st, tmp)) - return -EIO; - - if (array) - array[i] = tmp; - /* only sum cell voltages */ - if (((tmp >> 23) & 0xF) <= AD7280A_CELL_VOLTAGE_6) - sum += ((tmp >> 11) & 0xFFF); - } - - return sum; -} - -static void ad7280_sw_power_down(void *data) -{ - struct ad7280_state *st = data; - - ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, - AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); -} - -static int ad7280_chain_setup(struct ad7280_state *st) -{ - unsigned int val, n; - int ret; - - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_LB, 1, - AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN | - AD7280A_CTRL_LB_LOCK_DEV_ADDR | - AD7280A_CTRL_LB_MUST_SET | - AD7280A_CTRL_LB_SWRST | - st->ctrl_lb); - if (ret) - return ret; - - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_LB, 1, - AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN | - AD7280A_CTRL_LB_LOCK_DEV_ADDR | - AD7280A_CTRL_LB_MUST_SET | - st->ctrl_lb); - if (ret) - goto error_power_down; - - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_READ, 1, - AD7280A_CONTROL_LB << 2); - if (ret) - goto error_power_down; - - for (n = 0; n <= AD7280A_MAX_CHAIN; n++) { - ret = __ad7280_read32(st, &val); - if (ret) - goto error_power_down; - - if (val == 0) - return n - 1; - - if (ad7280_check_crc(st, val)) { - ret = -EIO; - goto error_power_down; - } - - if (n != ad7280a_devaddr(val >> 27)) { - ret = -EIO; - goto error_power_down; - } - } - ret = -EFAULT; - -error_power_down: - ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, - AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); - - return ret; -} - -static ssize_t ad7280_show_balance_sw(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7280_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - - return sprintf(buf, "%d\n", - !!(st->cb_mask[this_attr->address >> 8] & - (1 << ((this_attr->address & 0xFF) + 2)))); -} - -static ssize_t ad7280_store_balance_sw(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7280_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - bool readin; - int ret; - unsigned int devaddr, ch; - - ret = strtobool(buf, &readin); - if (ret) - return ret; - - devaddr = this_attr->address >> 8; - ch = this_attr->address & 0xFF; - - mutex_lock(&st->lock); - if (readin) - st->cb_mask[devaddr] |= 1 << (ch + 2); - else - st->cb_mask[devaddr] &= ~(1 << (ch + 2)); - - ret = ad7280_write(st, devaddr, AD7280A_CELL_BALANCE, - 0, st->cb_mask[devaddr]); - mutex_unlock(&st->lock); - - return ret ? ret : len; -} - -static ssize_t ad7280_show_balance_timer(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7280_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - int ret; - unsigned int msecs; - - mutex_lock(&st->lock); - ret = ad7280_read(st, this_attr->address >> 8, - this_attr->address & 0xFF); - mutex_unlock(&st->lock); - - if (ret < 0) - return ret; - - msecs = (ret >> 3) * 71500; - - return sprintf(buf, "%u\n", msecs); -} - -static ssize_t ad7280_store_balance_timer(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7280_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - unsigned long val; - int ret; - - ret = kstrtoul(buf, 10, &val); - if (ret) - return ret; - - val /= 71500; - - if (val > 31) - return -EINVAL; - - mutex_lock(&st->lock); - ret = ad7280_write(st, this_attr->address >> 8, - this_attr->address & 0xFF, - 0, (val & 0x1F) << 3); - mutex_unlock(&st->lock); - - return ret ? ret : len; -} - -static struct attribute *ad7280_attributes[AD7280A_MAX_CHAIN * - AD7280A_CELLS_PER_DEV * 2 + 1]; - -static const struct attribute_group ad7280_attrs_group = { - .attrs = ad7280_attributes, -}; - -static void ad7280_voltage_channel_init(struct iio_chan_spec *chan, int i) -{ - chan->type = IIO_VOLTAGE; - chan->differential = 1; - chan->channel = i; - chan->channel2 = chan->channel + 1; -} - -static void ad7280_temp_channel_init(struct iio_chan_spec *chan, int i) -{ - chan->type = IIO_TEMP; - chan->channel = i; -} - -static void ad7280_common_fields_init(struct iio_chan_spec *chan, int addr, - int cnt) -{ - chan->indexed = 1; - chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); - chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); - chan->address = addr; - chan->scan_index = cnt; - chan->scan_type.sign = 'u'; - chan->scan_type.realbits = 12; - chan->scan_type.storagebits = 32; -} - -static void ad7280_total_voltage_channel_init(struct iio_chan_spec *chan, - int cnt, int dev) -{ - chan->type = IIO_VOLTAGE; - chan->differential = 1; - chan->channel = 0; - chan->channel2 = dev * AD7280A_CELLS_PER_DEV; - chan->address = AD7280A_ALL_CELLS; - chan->indexed = 1; - chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); - chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); - chan->scan_index = cnt; - chan->scan_type.sign = 'u'; - chan->scan_type.realbits = 32; - chan->scan_type.storagebits = 32; -} - -static void ad7280_timestamp_channel_init(struct iio_chan_spec *chan, int cnt) -{ - chan->type = IIO_TIMESTAMP; - chan->channel = -1; - chan->scan_index = cnt; - chan->scan_type.sign = 's'; - chan->scan_type.realbits = 64; - chan->scan_type.storagebits = 64; -} - -static void ad7280_init_dev_channels(struct ad7280_state *st, int dev, int *cnt) -{ - int addr, ch, i; - struct iio_chan_spec *chan; - - for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_AUX_ADC_6; ch++) { - chan = &st->channels[*cnt]; - - if (ch < AD7280A_AUX_ADC_1) { - i = AD7280A_CALC_VOLTAGE_CHAN_NUM(dev, ch); - ad7280_voltage_channel_init(chan, i); - } else { - i = AD7280A_CALC_TEMP_CHAN_NUM(dev, ch); - ad7280_temp_channel_init(chan, i); - } - - addr = ad7280a_devaddr(dev) << 8 | ch; - ad7280_common_fields_init(chan, addr, *cnt); - - (*cnt)++; - } -} - -static int ad7280_channel_init(struct ad7280_state *st) -{ - int dev, cnt = 0; - - st->channels = devm_kcalloc(&st->spi->dev, (st->slave_num + 1) * 12 + 2, - sizeof(*st->channels), GFP_KERNEL); - if (!st->channels) - return -ENOMEM; - - for (dev = 0; dev <= st->slave_num; dev++) - ad7280_init_dev_channels(st, dev, &cnt); - - ad7280_total_voltage_channel_init(&st->channels[cnt], cnt, dev); - cnt++; - ad7280_timestamp_channel_init(&st->channels[cnt], cnt); - - return cnt + 1; -} - -static int ad7280_balance_switch_attr_init(struct iio_dev_attr *attr, - struct device *dev, int addr, int i) -{ - attr->address = addr; - attr->dev_attr.attr.mode = 0644; - attr->dev_attr.show = ad7280_show_balance_sw; - attr->dev_attr.store = ad7280_store_balance_sw; - attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, - "in%d-in%d_balance_switch_en", - i, i + 1); - if (!attr->dev_attr.attr.name) - return -ENOMEM; - - return 0; -} - -static int ad7280_balance_timer_attr_init(struct iio_dev_attr *attr, - struct device *dev, int addr, int i) -{ - attr->address = addr; - attr->dev_attr.attr.mode = 0644; - attr->dev_attr.show = ad7280_show_balance_timer; - attr->dev_attr.store = ad7280_store_balance_timer; - attr->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, - "in%d-in%d_balance_timer", - i, i + 1); - if (!attr->dev_attr.attr.name) - return -ENOMEM; - - return 0; -} - -static int ad7280_init_dev_attrs(struct ad7280_state *st, int dev, int *cnt) -{ - int addr, ch, i, ret; - struct iio_dev_attr *iio_attr; - struct device *sdev = &st->spi->dev; - - for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6; ch++) { - iio_attr = &st->iio_attr[*cnt]; - addr = ad7280a_devaddr(dev) << 8 | ch; - i = dev * AD7280A_CELLS_PER_DEV + ch; - - ret = ad7280_balance_switch_attr_init(iio_attr, sdev, addr, i); - if (ret < 0) - return ret; - - ad7280_attributes[*cnt] = &iio_attr->dev_attr.attr; - - (*cnt)++; - iio_attr = &st->iio_attr[*cnt]; - addr = ad7280a_devaddr(dev) << 8 | (AD7280A_CB1_TIMER + ch); - - ret = ad7280_balance_timer_attr_init(iio_attr, sdev, addr, i); - if (ret < 0) - return ret; - - ad7280_attributes[*cnt] = &iio_attr->dev_attr.attr; - (*cnt)++; - } - - ad7280_attributes[*cnt] = NULL; - - return 0; -} - -static int ad7280_attr_init(struct ad7280_state *st) -{ - int dev, cnt = 0, ret; - - st->iio_attr = devm_kcalloc(&st->spi->dev, 2, sizeof(*st->iio_attr) * - (st->slave_num + 1) * AD7280A_CELLS_PER_DEV, - GFP_KERNEL); - if (!st->iio_attr) - return -ENOMEM; - - for (dev = 0; dev <= st->slave_num; dev++) { - ret = ad7280_init_dev_attrs(st, dev, &cnt); - if (ret < 0) - return ret; - } - - return 0; -} - -static ssize_t ad7280_read_channel_config(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7280_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - unsigned int val; - - switch (this_attr->address) { - case AD7280A_CELL_OVERVOLTAGE: - val = 1000 + (st->cell_threshhigh * 1568) / 100; - break; - case AD7280A_CELL_UNDERVOLTAGE: - val = 1000 + (st->cell_threshlow * 1568) / 100; - break; - case AD7280A_AUX_ADC_OVERVOLTAGE: - val = (st->aux_threshhigh * 196) / 10; - break; - case AD7280A_AUX_ADC_UNDERVOLTAGE: - val = (st->aux_threshlow * 196) / 10; - break; - default: - return -EINVAL; - } - - return sprintf(buf, "%u\n", val); -} - -static ssize_t ad7280_write_channel_config(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7280_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - - long val; - int ret; - - ret = kstrtol(buf, 10, &val); - if (ret) - return ret; - - switch (this_attr->address) { - case AD7280A_CELL_OVERVOLTAGE: - case AD7280A_CELL_UNDERVOLTAGE: - val = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */ - break; - case AD7280A_AUX_ADC_OVERVOLTAGE: - case AD7280A_AUX_ADC_UNDERVOLTAGE: - val = (val * 10) / 196; /* LSB 19.6mV */ - break; - default: - return -EFAULT; - } - - val = clamp(val, 0L, 0xFFL); - - mutex_lock(&st->lock); - switch (this_attr->address) { - case AD7280A_CELL_OVERVOLTAGE: - st->cell_threshhigh = val; - break; - case AD7280A_CELL_UNDERVOLTAGE: - st->cell_threshlow = val; - break; - case AD7280A_AUX_ADC_OVERVOLTAGE: - st->aux_threshhigh = val; - break; - case AD7280A_AUX_ADC_UNDERVOLTAGE: - st->aux_threshlow = val; - break; - } - - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, - this_attr->address, 1, val); - - mutex_unlock(&st->lock); - - return ret ? ret : len; -} - -static irqreturn_t ad7280_event_handler(int irq, void *private) -{ - struct iio_dev *indio_dev = private; - struct ad7280_state *st = iio_priv(indio_dev); - unsigned int *channels; - int i, ret; - - channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL); - if (!channels) - return IRQ_HANDLED; - - ret = ad7280_read_all_channels(st, st->scan_cnt, channels); - if (ret < 0) - goto out; - - for (i = 0; i < st->scan_cnt; i++) { - if (((channels[i] >> 23) & 0xF) <= AD7280A_CELL_VOLTAGE_6) { - if (((channels[i] >> 11) & 0xFFF) >= - st->cell_threshhigh) { - u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0, - IIO_EV_DIR_RISING, - IIO_EV_TYPE_THRESH, - 0, 0, 0); - iio_push_event(indio_dev, tmp, - iio_get_time_ns(indio_dev)); - } else if (((channels[i] >> 11) & 0xFFF) <= - st->cell_threshlow) { - u64 tmp = IIO_EVENT_CODE(IIO_VOLTAGE, 1, 0, - IIO_EV_DIR_FALLING, - IIO_EV_TYPE_THRESH, - 0, 0, 0); - iio_push_event(indio_dev, tmp, - iio_get_time_ns(indio_dev)); - } - } else { - if (((channels[i] >> 11) & 0xFFF) >= - st->aux_threshhigh) { - u64 tmp = IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING); - iio_push_event(indio_dev, tmp, - iio_get_time_ns(indio_dev)); - } else if (((channels[i] >> 11) & 0xFFF) <= - st->aux_threshlow) { - u64 tmp = IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_FALLING); - iio_push_event(indio_dev, tmp, - iio_get_time_ns(indio_dev)); - } - } - } - -out: - kfree(channels); - - return IRQ_HANDLED; -} - -/* Note: No need to fix checkpatch warning that reads: - * CHECK: spaces preferred around that '-' (ctx:VxV) - * The function argument is stringified and doesn't need a fix - */ -static IIO_DEVICE_ATTR_NAMED(in_thresh_low_value, - in_voltage-voltage_thresh_low_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_CELL_UNDERVOLTAGE); - -static IIO_DEVICE_ATTR_NAMED(in_thresh_high_value, - in_voltage-voltage_thresh_high_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_CELL_OVERVOLTAGE); - -static IIO_DEVICE_ATTR(in_temp_thresh_low_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_AUX_ADC_UNDERVOLTAGE); - -static IIO_DEVICE_ATTR(in_temp_thresh_high_value, - 0644, - ad7280_read_channel_config, - ad7280_write_channel_config, - AD7280A_AUX_ADC_OVERVOLTAGE); - -static struct attribute *ad7280_event_attributes[] = { - &iio_dev_attr_in_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in_thresh_high_value.dev_attr.attr, - &iio_dev_attr_in_temp_thresh_low_value.dev_attr.attr, - &iio_dev_attr_in_temp_thresh_high_value.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ad7280_event_attrs_group = { - .attrs = ad7280_event_attributes, -}; - -static int ad7280_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - struct ad7280_state *st = iio_priv(indio_dev); - int ret; - - switch (m) { - case IIO_CHAN_INFO_RAW: - mutex_lock(&st->lock); - if (chan->address == AD7280A_ALL_CELLS) - ret = ad7280_read_all_channels(st, st->scan_cnt, NULL); - else - ret = ad7280_read_channel(st, chan->address >> 8, - chan->address & 0xFF); - mutex_unlock(&st->lock); - - if (ret < 0) - return ret; - - *val = ret; - - return IIO_VAL_INT; - case IIO_CHAN_INFO_SCALE: - if ((chan->address & 0xFF) <= AD7280A_CELL_VOLTAGE_6) - *val = 4000; - else - *val = 5000; - - *val2 = AD7280A_BITS; - return IIO_VAL_FRACTIONAL_LOG2; - } - return -EINVAL; -} - -static const struct iio_info ad7280_info = { - .read_raw = ad7280_read_raw, - .event_attrs = &ad7280_event_attrs_group, - .attrs = &ad7280_attrs_group, -}; - -static const struct ad7280_platform_data ad7793_default_pdata = { - .acquisition_time = AD7280A_ACQ_TIME_400ns, - .conversion_averaging = AD7280A_CONV_AVG_DIS, - .thermistor_term_en = true, -}; - -static int ad7280_probe(struct spi_device *spi) -{ - const struct ad7280_platform_data *pdata = dev_get_platdata(&spi->dev); - struct ad7280_state *st; - int ret; - const unsigned short t_acq_ns[4] = {465, 1010, 1460, 1890}; - const unsigned short n_avg[4] = {1, 2, 4, 8}; - struct iio_dev *indio_dev; - - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); - if (!indio_dev) - return -ENOMEM; - - st = iio_priv(indio_dev); - spi_set_drvdata(spi, indio_dev); - st->spi = spi; - mutex_init(&st->lock); - - if (!pdata) - pdata = &ad7793_default_pdata; - - crc8_populate_msb(st->crc_tab, POLYNOM); - - st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ; - st->spi->mode = SPI_MODE_1; - spi_setup(st->spi); - - st->ctrl_lb = AD7280A_CTRL_LB_ACQ_TIME(pdata->acquisition_time & 0x3); - st->ctrl_hb = AD7280A_CTRL_HB_CONV_AVG(pdata->conversion_averaging - & 0x3) | (pdata->thermistor_term_en ? - AD7280A_CTRL_LB_THERMISTOR_EN : 0); - - ret = ad7280_chain_setup(st); - if (ret < 0) - return ret; - - st->slave_num = ret; - st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH; - st->cell_threshhigh = 0xFF; - st->aux_threshhigh = 0xFF; - - ret = devm_add_action_or_reset(&spi->dev, ad7280_sw_power_down, st); - if (ret) - return ret; - - /* - * Total Conversion Time = ((tACQ + tCONV) * - * (Number of Conversions per Part)) − - * tACQ + ((N - 1) * tDELAY) - * - * Readback Delay = Total Conversion Time + tWAIT - */ - - st->readback_delay_us = - ((t_acq_ns[pdata->acquisition_time & 0x3] + 695) * - (AD7280A_NUM_CH * n_avg[pdata->conversion_averaging & 0x3])) - - t_acq_ns[pdata->acquisition_time & 0x3] + st->slave_num * 250; - - /* Convert to usecs */ - st->readback_delay_us = DIV_ROUND_UP(st->readback_delay_us, 1000); - st->readback_delay_us += 5; /* Add tWAIT */ - - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->modes = INDIO_DIRECT_MODE; - - ret = ad7280_channel_init(st); - if (ret < 0) - return ret; - - indio_dev->num_channels = ret; - indio_dev->channels = st->channels; - indio_dev->info = &ad7280_info; - - ret = ad7280_attr_init(st); - if (ret < 0) - return ret; - - ret = devm_iio_device_register(&spi->dev, indio_dev); - if (ret) - return ret; - - if (spi->irq > 0) { - ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, - AD7280A_ALERT, 1, - AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN); - if (ret) - return ret; - - ret = ad7280_write(st, ad7280a_devaddr(st->slave_num), - AD7280A_ALERT, 0, - AD7280A_ALERT_GEN_STATIC_HIGH | - (pdata->chain_last_alert_ignore & 0xF)); - if (ret) - return ret; - - ret = devm_request_threaded_irq(&spi->dev, spi->irq, - NULL, - ad7280_event_handler, - IRQF_TRIGGER_FALLING | - IRQF_ONESHOT, - indio_dev->name, - indio_dev); - if (ret) - return ret; - } - - return 0; -} - -static const struct spi_device_id ad7280_id[] = { - {"ad7280a", 0}, - {} -}; -MODULE_DEVICE_TABLE(spi, ad7280_id); - -static struct spi_driver ad7280_driver = { - .driver = { - .name = "ad7280", - }, - .probe = ad7280_probe, - .id_table = ad7280_id, -}; -module_spi_driver(ad7280_driver); - -MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); -MODULE_DESCRIPTION("Analog Devices AD7280A"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/ad7280a.h b/drivers/staging/iio/adc/ad7280a.h deleted file mode 100644 index 23f18bb9e279..000000000000 --- a/drivers/staging/iio/adc/ad7280a.h +++ /dev/null @@ -1,37 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * AD7280A Lithium Ion Battery Monitoring System - * - * Copyright 2011 Analog Devices Inc. - */ - -#ifndef IIO_ADC_AD7280_H_ -#define IIO_ADC_AD7280_H_ - -/* - * TODO: struct ad7280_platform_data needs to go into include/linux/iio - */ - -#define AD7280A_ACQ_TIME_400ns 0 -#define AD7280A_ACQ_TIME_800ns 1 -#define AD7280A_ACQ_TIME_1200ns 2 -#define AD7280A_ACQ_TIME_1600ns 3 - -#define AD7280A_CONV_AVG_DIS 0 -#define AD7280A_CONV_AVG_2 1 -#define AD7280A_CONV_AVG_4 2 -#define AD7280A_CONV_AVG_8 3 - -#define AD7280A_ALERT_REMOVE_VIN5 BIT(2) -#define AD7280A_ALERT_REMOVE_VIN4_VIN5 BIT(3) -#define AD7280A_ALERT_REMOVE_AUX5 BIT(0) -#define AD7280A_ALERT_REMOVE_AUX4_AUX5 BIT(1) - -struct ad7280_platform_data { - unsigned int acquisition_time; - unsigned int conversion_averaging; - unsigned int chain_last_alert_ignore; - bool thermistor_term_en; -}; - -#endif /* IIO_ADC_AD7280_H_ */ diff --git a/drivers/staging/iio/cdc/Kconfig b/drivers/staging/iio/cdc/Kconfig deleted file mode 100644 index a7386bbbcb79..000000000000 --- a/drivers/staging/iio/cdc/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# CDC drivers -# -menu "Capacitance to digital converters" - -config AD7746 - tristate "Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver" - depends on I2C - help - Say yes here to build support for Analog Devices capacitive sensors. - (AD7745, AD7746, AD7747) Provides direct access via sysfs. - - To compile this driver as a module, choose M here: the - module will be called ad7746. - -endmenu diff --git a/drivers/staging/iio/cdc/Makefile b/drivers/staging/iio/cdc/Makefile deleted file mode 100644 index afb7499a7090..000000000000 --- a/drivers/staging/iio/cdc/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Makefile for industrial I/O CDC drivers -# - -obj-$(CONFIG_AD7746) += ad7746.o diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c deleted file mode 100644 index 71c709771676..000000000000 --- a/drivers/staging/iio/cdc/ad7746.c +++ /dev/null @@ -1,767 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * AD7746 capacitive sensor driver supporting AD7745, AD7746 and AD7747 - * - * Copyright 2011 Analog Devices Inc. - */ - -#include <linux/delay.h> -#include <linux/device.h> -#include <linux/i2c.h> -#include <linux/interrupt.h> -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/stat.h> -#include <linux/sysfs.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> - -/* - * AD7746 Register Definition - */ - -#define AD7746_REG_STATUS 0 -#define AD7746_REG_CAP_DATA_HIGH 1 -#define AD7746_REG_VT_DATA_HIGH 4 -#define AD7746_REG_CAP_SETUP 7 -#define AD7746_REG_VT_SETUP 8 -#define AD7746_REG_EXC_SETUP 9 -#define AD7746_REG_CFG 10 -#define AD7746_REG_CAPDACA 11 -#define AD7746_REG_CAPDACB 12 -#define AD7746_REG_CAP_OFFH 13 -#define AD7746_REG_CAP_GAINH 15 -#define AD7746_REG_VOLT_GAINH 17 - -/* Status Register Bit Designations (AD7746_REG_STATUS) */ -#define AD7746_STATUS_EXCERR BIT(3) -#define AD7746_STATUS_RDY BIT(2) -#define AD7746_STATUS_RDYVT BIT(1) -#define AD7746_STATUS_RDYCAP BIT(0) - -/* Capacitive Channel Setup Register Bit Designations (AD7746_REG_CAP_SETUP) */ -#define AD7746_CAPSETUP_CAPEN BIT(7) -#define AD7746_CAPSETUP_CIN2 BIT(6) /* AD7746 only */ -#define AD7746_CAPSETUP_CAPDIFF BIT(5) -#define AD7746_CAPSETUP_CACHOP BIT(0) - -/* Voltage/Temperature Setup Register Bit Designations (AD7746_REG_VT_SETUP) */ -#define AD7746_VTSETUP_VTEN (1 << 7) -#define AD7746_VTSETUP_VTMD_INT_TEMP (0 << 5) -#define AD7746_VTSETUP_VTMD_EXT_TEMP (1 << 5) -#define AD7746_VTSETUP_VTMD_VDD_MON (2 << 5) -#define AD7746_VTSETUP_VTMD_EXT_VIN (3 << 5) -#define AD7746_VTSETUP_EXTREF BIT(4) -#define AD7746_VTSETUP_VTSHORT BIT(1) -#define AD7746_VTSETUP_VTCHOP BIT(0) - -/* Excitation Setup Register Bit Designations (AD7746_REG_EXC_SETUP) */ -#define AD7746_EXCSETUP_CLKCTRL BIT(7) -#define AD7746_EXCSETUP_EXCON BIT(6) -#define AD7746_EXCSETUP_EXCB BIT(5) -#define AD7746_EXCSETUP_NEXCB BIT(4) -#define AD7746_EXCSETUP_EXCA BIT(3) -#define AD7746_EXCSETUP_NEXCA BIT(2) -#define AD7746_EXCSETUP_EXCLVL(x) (((x) & 0x3) << 0) - -/* Config Register Bit Designations (AD7746_REG_CFG) */ -#define AD7746_CONF_VTFS_SHIFT 6 -#define AD7746_CONF_CAPFS_SHIFT 3 -#define AD7746_CONF_VTFS_MASK GENMASK(7, 6) -#define AD7746_CONF_CAPFS_MASK GENMASK(5, 3) -#define AD7746_CONF_MODE_IDLE (0 << 0) -#define AD7746_CONF_MODE_CONT_CONV (1 << 0) -#define AD7746_CONF_MODE_SINGLE_CONV (2 << 0) -#define AD7746_CONF_MODE_PWRDN (3 << 0) -#define AD7746_CONF_MODE_OFFS_CAL (5 << 0) -#define AD7746_CONF_MODE_GAIN_CAL (6 << 0) - -/* CAPDAC Register Bit Designations (AD7746_REG_CAPDACx) */ -#define AD7746_CAPDAC_DACEN BIT(7) -#define AD7746_CAPDAC_DACP(x) ((x) & 0x7F) - -struct ad7746_chip_info { - struct i2c_client *client; - struct mutex lock; /* protect sensor state */ - /* - * Capacitive channel digital filter setup; - * conversion time/update rate setup per channel - */ - u8 config; - u8 cap_setup; - u8 vt_setup; - u8 capdac[2][2]; - s8 capdac_set; - - union { - __be32 d32; - u8 d8[4]; - } data ____cacheline_aligned; -}; - -enum ad7746_chan { - VIN, - VIN_VDD, - TEMP_INT, - TEMP_EXT, - CIN1, - CIN1_DIFF, - CIN2, - CIN2_DIFF, -}; - -static const struct iio_chan_spec ad7746_channels[] = { - [VIN] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ), - .address = AD7746_REG_VT_DATA_HIGH << 8 | - AD7746_VTSETUP_VTMD_EXT_VIN, - }, - [VIN_VDD] = { - .type = IIO_VOLTAGE, - .indexed = 1, - .channel = 1, - .extend_name = "supply", - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | - BIT(IIO_CHAN_INFO_SAMP_FREQ), - .address = AD7746_REG_VT_DATA_HIGH << 8 | - AD7746_VTSETUP_VTMD_VDD_MON, - }, - [TEMP_INT] = { - .type = IIO_TEMP, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), - .address = AD7746_REG_VT_DATA_HIGH << 8 | - AD7746_VTSETUP_VTMD_INT_TEMP, - }, - [TEMP_EXT] = { - .type = IIO_TEMP, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), - .address = AD7746_REG_VT_DATA_HIGH << 8 | - AD7746_VTSETUP_VTMD_EXT_TEMP, - }, - [CIN1] = { - .type = IIO_CAPACITANCE, - .indexed = 1, - .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | - BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), - .address = AD7746_REG_CAP_DATA_HIGH << 8, - }, - [CIN1_DIFF] = { - .type = IIO_CAPACITANCE, - .differential = 1, - .indexed = 1, - .channel = 0, - .channel2 = 2, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | - BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), - .address = AD7746_REG_CAP_DATA_HIGH << 8 | - AD7746_CAPSETUP_CAPDIFF - }, - [CIN2] = { - .type = IIO_CAPACITANCE, - .indexed = 1, - .channel = 1, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | - BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), - .address = AD7746_REG_CAP_DATA_HIGH << 8 | - AD7746_CAPSETUP_CIN2, - }, - [CIN2_DIFF] = { - .type = IIO_CAPACITANCE, - .differential = 1, - .indexed = 1, - .channel = 1, - .channel2 = 3, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | - BIT(IIO_CHAN_INFO_CALIBSCALE) | BIT(IIO_CHAN_INFO_OFFSET), - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBBIAS) | - BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_SAMP_FREQ), - .address = AD7746_REG_CAP_DATA_HIGH << 8 | - AD7746_CAPSETUP_CAPDIFF | AD7746_CAPSETUP_CIN2, - } -}; - -/* Values are Update Rate (Hz), Conversion Time (ms) + 1*/ -static const unsigned char ad7746_vt_filter_rate_table[][2] = { - {50, 20 + 1}, {31, 32 + 1}, {16, 62 + 1}, {8, 122 + 1}, -}; - -static const unsigned char ad7746_cap_filter_rate_table[][2] = { - {91, 11 + 1}, {84, 12 + 1}, {50, 20 + 1}, {26, 38 + 1}, - {16, 62 + 1}, {13, 77 + 1}, {11, 92 + 1}, {9, 110 + 1}, -}; - -static int ad7746_set_capdac(struct ad7746_chip_info *chip, int channel) -{ - int ret = i2c_smbus_write_byte_data(chip->client, - AD7746_REG_CAPDACA, - chip->capdac[channel][0]); - if (ret < 0) - return ret; - - return i2c_smbus_write_byte_data(chip->client, - AD7746_REG_CAPDACB, - chip->capdac[channel][1]); -} - -static int ad7746_select_channel(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan) -{ - struct ad7746_chip_info *chip = iio_priv(indio_dev); - u8 vt_setup, cap_setup; - int ret, delay, idx; - - switch (chan->type) { - case IIO_CAPACITANCE: - cap_setup = (chan->address & 0xFF) | AD7746_CAPSETUP_CAPEN; - vt_setup = chip->vt_setup & ~AD7746_VTSETUP_VTEN; - idx = (chip->config & AD7746_CONF_CAPFS_MASK) >> - AD7746_CONF_CAPFS_SHIFT; - delay = ad7746_cap_filter_rate_table[idx][1]; - - ret = ad7746_set_capdac(chip, chan->channel); - if (ret < 0) - return ret; - - if (chip->capdac_set != chan->channel) - chip->capdac_set = chan->channel; - break; - case IIO_VOLTAGE: - case IIO_TEMP: - vt_setup = (chan->address & 0xFF) | AD7746_VTSETUP_VTEN; - cap_setup = chip->cap_setup & ~AD7746_CAPSETUP_CAPEN; - idx = (chip->config & AD7746_CONF_VTFS_MASK) >> - AD7746_CONF_VTFS_SHIFT; - delay = ad7746_cap_filter_rate_table[idx][1]; - break; - default: - return -EINVAL; - } - - if (chip->cap_setup != cap_setup) { - ret = i2c_smbus_write_byte_data(chip->client, - AD7746_REG_CAP_SETUP, - cap_setup); - if (ret < 0) - return ret; - - chip->cap_setup = cap_setup; - } - - if (chip->vt_setup != vt_setup) { - ret = i2c_smbus_write_byte_data(chip->client, - AD7746_REG_VT_SETUP, - vt_setup); - if (ret < 0) - return ret; - - chip->vt_setup = vt_setup; - } - - return delay; -} - -static inline ssize_t ad7746_start_calib(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len, - u8 regval) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7746_chip_info *chip = iio_priv(indio_dev); - int ret, timeout = 10; - bool doit; - - ret = strtobool(buf, &doit); - if (ret < 0) - return ret; - - if (!doit) - return 0; - - mutex_lock(&chip->lock); - regval |= chip->config; - ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval); - if (ret < 0) - goto unlock; - - do { - msleep(20); - ret = i2c_smbus_read_byte_data(chip->client, AD7746_REG_CFG); - if (ret < 0) - goto unlock; - - } while ((ret == regval) && timeout--); - - mutex_unlock(&chip->lock); - - return len; - -unlock: - mutex_unlock(&chip->lock); - return ret; -} - -static ssize_t ad7746_start_offset_calib(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - int ret = ad7746_select_channel(indio_dev, - &ad7746_channels[to_iio_dev_attr(attr)->address]); - if (ret < 0) - return ret; - - return ad7746_start_calib(dev, attr, buf, len, - AD7746_CONF_MODE_OFFS_CAL); -} - -static ssize_t ad7746_start_gain_calib(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - int ret = ad7746_select_channel(indio_dev, - &ad7746_channels[to_iio_dev_attr(attr)->address]); - if (ret < 0) - return ret; - - return ad7746_start_calib(dev, attr, buf, len, - AD7746_CONF_MODE_GAIN_CAL); -} - -static IIO_DEVICE_ATTR(in_capacitance0_calibbias_calibration, - 0200, NULL, ad7746_start_offset_calib, CIN1); -static IIO_DEVICE_ATTR(in_capacitance1_calibbias_calibration, - 0200, NULL, ad7746_start_offset_calib, CIN2); -static IIO_DEVICE_ATTR(in_capacitance0_calibscale_calibration, - 0200, NULL, ad7746_start_gain_calib, CIN1); -static IIO_DEVICE_ATTR(in_capacitance1_calibscale_calibration, - 0200, NULL, ad7746_start_gain_calib, CIN2); -static IIO_DEVICE_ATTR(in_voltage0_calibscale_calibration, - 0200, NULL, ad7746_start_gain_calib, VIN); - -static int ad7746_store_cap_filter_rate_setup(struct ad7746_chip_info *chip, - int val) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(ad7746_cap_filter_rate_table); i++) - if (val >= ad7746_cap_filter_rate_table[i][0]) - break; - - if (i >= ARRAY_SIZE(ad7746_cap_filter_rate_table)) - i = ARRAY_SIZE(ad7746_cap_filter_rate_table) - 1; - - chip->config &= ~AD7746_CONF_CAPFS_MASK; - chip->config |= i << AD7746_CONF_CAPFS_SHIFT; - - return 0; -} - -static int ad7746_store_vt_filter_rate_setup(struct ad7746_chip_info *chip, - int val) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(ad7746_vt_filter_rate_table); i++) - if (val >= ad7746_vt_filter_rate_table[i][0]) - break; - - if (i >= ARRAY_SIZE(ad7746_vt_filter_rate_table)) - i = ARRAY_SIZE(ad7746_vt_filter_rate_table) - 1; - - chip->config &= ~AD7746_CONF_VTFS_MASK; - chip->config |= i << AD7746_CONF_VTFS_SHIFT; - - return 0; -} - -static IIO_CONST_ATTR(in_voltage_sampling_frequency_available, "50 31 16 8"); -static IIO_CONST_ATTR(in_capacitance_sampling_frequency_available, - "91 84 50 26 16 13 11 9"); - -static struct attribute *ad7746_attributes[] = { - &iio_dev_attr_in_capacitance0_calibbias_calibration.dev_attr.attr, - &iio_dev_attr_in_capacitance0_calibscale_calibration.dev_attr.attr, - &iio_dev_attr_in_capacitance1_calibscale_calibration.dev_attr.attr, - &iio_dev_attr_in_capacitance1_calibbias_calibration.dev_attr.attr, - &iio_dev_attr_in_voltage0_calibscale_calibration.dev_attr.attr, - &iio_const_attr_in_voltage_sampling_frequency_available.dev_attr.attr, - &iio_const_attr_in_capacitance_sampling_frequency_available.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ad7746_attribute_group = { - .attrs = ad7746_attributes, -}; - -static int ad7746_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) -{ - struct ad7746_chip_info *chip = iio_priv(indio_dev); - int ret, reg; - - mutex_lock(&chip->lock); - - switch (mask) { - case IIO_CHAN_INFO_CALIBSCALE: - if (val != 1) { - ret = -EINVAL; - goto out; - } - - val = (val2 * 1024) / 15625; - - switch (chan->type) { - case IIO_CAPACITANCE: - reg = AD7746_REG_CAP_GAINH; - break; - case IIO_VOLTAGE: - reg = AD7746_REG_VOLT_GAINH; - break; - default: - ret = -EINVAL; - goto out; - } - - ret = i2c_smbus_write_word_swapped(chip->client, reg, val); - if (ret < 0) - goto out; - - ret = 0; - break; - case IIO_CHAN_INFO_CALIBBIAS: - if (val < 0 || val > 0xFFFF) { - ret = -EINVAL; - goto out; - } - ret = i2c_smbus_write_word_swapped(chip->client, - AD7746_REG_CAP_OFFH, val); - if (ret < 0) - goto out; - - ret = 0; - break; - case IIO_CHAN_INFO_OFFSET: - if (val < 0 || val > 43008000) { /* 21pF */ - ret = -EINVAL; - goto out; - } - - /* - * CAPDAC Scale = 21pF_typ / 127 - * CIN Scale = 8.192pF / 2^24 - * Offset Scale = CAPDAC Scale / CIN Scale = 338646 - */ - - val /= 338646; - - chip->capdac[chan->channel][chan->differential] = val > 0 ? - AD7746_CAPDAC_DACP(val) | AD7746_CAPDAC_DACEN : 0; - - ret = ad7746_set_capdac(chip, chan->channel); - if (ret < 0) - goto out; - - chip->capdac_set = chan->channel; - - ret = 0; - break; - case IIO_CHAN_INFO_SAMP_FREQ: - if (val2) { - ret = -EINVAL; - goto out; - } - - switch (chan->type) { - case IIO_CAPACITANCE: - ret = ad7746_store_cap_filter_rate_setup(chip, val); - break; - case IIO_VOLTAGE: - ret = ad7746_store_vt_filter_rate_setup(chip, val); - break; - default: - ret = -EINVAL; - } - break; - default: - ret = -EINVAL; - } - -out: - mutex_unlock(&chip->lock); - return ret; -} - -static int ad7746_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, - long mask) -{ - struct ad7746_chip_info *chip = iio_priv(indio_dev); - int ret, delay, idx; - u8 regval, reg; - - mutex_lock(&chip->lock); - - switch (mask) { - case IIO_CHAN_INFO_RAW: - case IIO_CHAN_INFO_PROCESSED: - ret = ad7746_select_channel(indio_dev, chan); - if (ret < 0) - goto out; - delay = ret; - - regval = chip->config | AD7746_CONF_MODE_SINGLE_CONV; - ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, - regval); - if (ret < 0) - goto out; - - msleep(delay); - /* Now read the actual register */ - - ret = i2c_smbus_read_i2c_block_data(chip->client, - chan->address >> 8, 3, - &chip->data.d8[1]); - - if (ret < 0) - goto out; - - *val = (be32_to_cpu(chip->data.d32) & 0xFFFFFF) - 0x800000; - - switch (chan->type) { - case IIO_TEMP: - /* - * temperature in milli degrees Celsius - * T = ((*val / 2048) - 4096) * 1000 - */ - *val = (*val * 125) / 256; - break; - case IIO_VOLTAGE: - if (chan->channel == 1) /* supply_raw*/ - *val = *val * 6; - break; - default: - break; - } - - ret = IIO_VAL_INT; - break; - case IIO_CHAN_INFO_CALIBSCALE: - switch (chan->type) { - case IIO_CAPACITANCE: - reg = AD7746_REG_CAP_GAINH; - break; - case IIO_VOLTAGE: - reg = AD7746_REG_VOLT_GAINH; - break; - default: - ret = -EINVAL; - goto out; - } - - ret = i2c_smbus_read_word_swapped(chip->client, reg); - if (ret < 0) - goto out; - /* 1 + gain_val / 2^16 */ - *val = 1; - *val2 = (15625 * ret) / 1024; - - ret = IIO_VAL_INT_PLUS_MICRO; - break; - case IIO_CHAN_INFO_CALIBBIAS: - ret = i2c_smbus_read_word_swapped(chip->client, - AD7746_REG_CAP_OFFH); - if (ret < 0) - goto out; - *val = ret; - - ret = IIO_VAL_INT; - break; - case IIO_CHAN_INFO_OFFSET: - *val = AD7746_CAPDAC_DACP(chip->capdac[chan->channel] - [chan->differential]) * 338646; - - ret = IIO_VAL_INT; - break; - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_CAPACITANCE: - /* 8.192pf / 2^24 */ - *val = 0; - *val2 = 488; - ret = IIO_VAL_INT_PLUS_NANO; - break; - case IIO_VOLTAGE: - /* 1170mV / 2^23 */ - *val = 1170; - *val2 = 23; - ret = IIO_VAL_FRACTIONAL_LOG2; - break; - default: - ret = -EINVAL; - break; - } - - break; - case IIO_CHAN_INFO_SAMP_FREQ: - switch (chan->type) { - case IIO_CAPACITANCE: - idx = (chip->config & AD7746_CONF_CAPFS_MASK) >> - AD7746_CONF_CAPFS_SHIFT; - *val = ad7746_cap_filter_rate_table[idx][0]; - ret = IIO_VAL_INT; - break; - case IIO_VOLTAGE: - idx = (chip->config & AD7746_CONF_VTFS_MASK) >> - AD7746_CONF_VTFS_SHIFT; - *val = ad7746_vt_filter_rate_table[idx][0]; - ret = IIO_VAL_INT; - break; - default: - ret = -EINVAL; - } - break; - default: - ret = -EINVAL; - } -out: - mutex_unlock(&chip->lock); - return ret; -} - -static const struct iio_info ad7746_info = { - .attrs = &ad7746_attribute_group, - .read_raw = ad7746_read_raw, - .write_raw = ad7746_write_raw, -}; - -static int ad7746_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct device *dev = &client->dev; - struct ad7746_chip_info *chip; - struct iio_dev *indio_dev; - unsigned char regval = 0; - unsigned int vdd_permille; - int ret; - - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); - if (!indio_dev) - return -ENOMEM; - chip = iio_priv(indio_dev); - mutex_init(&chip->lock); - /* this is only used for device removal purposes */ - i2c_set_clientdata(client, indio_dev); - - chip->client = client; - chip->capdac_set = -1; - - indio_dev->name = id->name; - indio_dev->info = &ad7746_info; - indio_dev->channels = ad7746_channels; - if (id->driver_data == 7746) - indio_dev->num_channels = ARRAY_SIZE(ad7746_channels); - else - indio_dev->num_channels = ARRAY_SIZE(ad7746_channels) - 2; - indio_dev->modes = INDIO_DIRECT_MODE; - - if (device_property_read_bool(dev, "adi,exca-output-en")) { - if (device_property_read_bool(dev, "adi,exca-output-invert")) - regval |= AD7746_EXCSETUP_NEXCA; - else - regval |= AD7746_EXCSETUP_EXCA; - } - - if (device_property_read_bool(dev, "adi,excb-output-en")) { - if (device_property_read_bool(dev, "adi,excb-output-invert")) - regval |= AD7746_EXCSETUP_NEXCB; - else - regval |= AD7746_EXCSETUP_EXCB; - } - - ret = device_property_read_u32(dev, "adi,excitation-vdd-permille", - &vdd_permille); - if (!ret) { - switch (vdd_permille) { - case 125: - regval |= AD7746_EXCSETUP_EXCLVL(0); - break; - case 250: - regval |= AD7746_EXCSETUP_EXCLVL(1); - break; - case 375: - regval |= AD7746_EXCSETUP_EXCLVL(2); - break; - case 500: - regval |= AD7746_EXCSETUP_EXCLVL(3); - break; - default: - break; - } - } - - ret = i2c_smbus_write_byte_data(chip->client, - AD7746_REG_EXC_SETUP, regval); - if (ret < 0) - return ret; - - return devm_iio_device_register(indio_dev->dev.parent, indio_dev); -} - -static const struct i2c_device_id ad7746_id[] = { - { "ad7745", 7745 }, - { "ad7746", 7746 }, - { "ad7747", 7747 }, - {} -}; - -MODULE_DEVICE_TABLE(i2c, ad7746_id); - -static const struct of_device_id ad7746_of_match[] = { - { .compatible = "adi,ad7745" }, - { .compatible = "adi,ad7746" }, - { .compatible = "adi,ad7747" }, - { }, -}; - -MODULE_DEVICE_TABLE(of, ad7746_of_match); - -static struct i2c_driver ad7746_driver = { - .driver = { - .name = KBUILD_MODNAME, - .of_match_table = ad7746_of_match, - }, - .probe = ad7746_probe, - .id_table = ad7746_id, -}; -module_i2c_driver(ad7746_driver); - -MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); -MODULE_DESCRIPTION("Analog Devices AD7746/5/7 capacitive sensor driver"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c index f43464db618a..6f9eebd6c7ee 100644 --- a/drivers/staging/iio/frequency/ad9832.c +++ b/drivers/staging/iio/frequency/ad9832.c @@ -112,10 +112,10 @@ struct ad9832_state { * transfer buffers to live in their own cache lines. */ union { - __be16 freq_data[4]____cacheline_aligned; + __be16 freq_data[4]; __be16 phase_data[2]; __be16 data; - }; + } __aligned(IIO_DMA_MINALIGN); }; static unsigned long ad9832_calc_freqreg(unsigned long mclk, unsigned long fout) diff --git a/drivers/staging/iio/frequency/ad9834.c b/drivers/staging/iio/frequency/ad9834.c index 94b131ef8a22..2b4267a87e65 100644 --- a/drivers/staging/iio/frequency/ad9834.c +++ b/drivers/staging/iio/frequency/ad9834.c @@ -83,7 +83,7 @@ struct ad9834_state { * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. */ - __be16 data ____cacheline_aligned; + __be16 data __aligned(IIO_DMA_MINALIGN); __be16 freq_data[2]; }; diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 793918e1c45f..f177b20f0f2d 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -749,7 +749,6 @@ static int ad5933_probe(struct i2c_client *client, indio_dev->num_channels = ARRAY_SIZE(ad5933_channels); ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev, - INDIO_BUFFER_SOFTWARE, &ad5933_ring_setup_ops); if (ret) return ret; diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h index a51e6e3183d3..7a49f8f1016f 100644 --- a/drivers/staging/iio/meter/ade7854.h +++ b/drivers/staging/iio/meter/ade7854.h @@ -162,7 +162,7 @@ struct ade7854_state { int bits); int irq; struct mutex buf_lock; - u8 tx[ADE7854_MAX_TX] ____cacheline_aligned; + u8 tx[ADE7854_MAX_TX] __aligned(IIO_DMA_MINALIGN); u8 rx[ADE7854_MAX_RX]; }; diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 74adb82f37c3..e4cf42438487 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -94,8 +94,8 @@ struct ad2s1210_state { bool hysteresis; u8 resolution; enum ad2s1210_mode mode; - u8 rx[2] ____cacheline_aligned; - u8 tx[2] ____cacheline_aligned; + u8 rx[2] __aligned(IIO_DMA_MINALIGN); + u8 tx[2]; }; static const int ad2s1210_mode_vals[4][2] = { @@ -499,7 +499,6 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, ret = IIO_VAL_INT; break; case IIO_ANGL_VEL: - negative = st->rx[0] & 0x80; vel = be16_to_cpup((__be16 *)st->rx); vel >>= 16 - st->resolution; if (vel & 0x8000) { diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c index 98d759e7cc95..9fb118e77a1f 100644 --- a/drivers/staging/ks7010/ks7010_sdio.c +++ b/drivers/staging/ks7010/ks7010_sdio.c @@ -1102,10 +1102,8 @@ static void ks7010_sdio_remove(struct sdio_func *func) if (ret) /* memory allocation failure */ goto err_free_card; - if (priv->wq) { - flush_workqueue(priv->wq); + if (priv->wq) destroy_workqueue(priv->wq); - } hostif_exit(priv); diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c index 1c63d595313d..9429ee155910 100644 --- a/drivers/staging/ks7010/ks_hostif.c +++ b/drivers/staging/ks7010/ks_hostif.c @@ -84,10 +84,6 @@ static void ks_wlan_hw_wakeup_task(struct work_struct *work) return; } } - - /* power save */ - if (atomic_read(&priv->sme_task.count) > 0) - tasklet_enable(&priv->sme_task); } static void ks_wlan_do_power_save(struct ks_wlan_private *priv) @@ -2200,10 +2196,11 @@ static void hostif_sme_execute(struct ks_wlan_private *priv, int event) } } -static -void hostif_sme_task(struct tasklet_struct *t) +static void hostif_sme_work(struct work_struct *work) { - struct ks_wlan_private *priv = from_tasklet(priv, t, sme_task); + struct ks_wlan_private *priv; + + priv = container_of(work, struct ks_wlan_private, sme_work); if (priv->dev_state < DEVICE_STATE_BOOT) return; @@ -2214,7 +2211,7 @@ void hostif_sme_task(struct tasklet_struct *t) hostif_sme_execute(priv, priv->sme_i.event_buff[priv->sme_i.qhead]); inc_smeqhead(priv); if (cnt_smeqbody(priv) > 0) - tasklet_schedule(&priv->sme_task); + schedule_work(&priv->sme_work); } /* send to Station Management Entity module */ @@ -2229,7 +2226,7 @@ void hostif_sme_enqueue(struct ks_wlan_private *priv, u16 event) netdev_err(priv->net_dev, "sme queue buffer overflow\n"); } - tasklet_schedule(&priv->sme_task); + schedule_work(&priv->sme_work); } static inline void hostif_aplist_init(struct ks_wlan_private *priv) @@ -2254,7 +2251,7 @@ static inline void hostif_sme_init(struct ks_wlan_private *priv) priv->sme_i.qtail = 0; spin_lock_init(&priv->sme_i.sme_spin); priv->sme_i.sme_flag = 0; - tasklet_setup(&priv->sme_task, hostif_sme_task); + INIT_WORK(&priv->sme_work, hostif_sme_work); } static inline void hostif_wpa_init(struct ks_wlan_private *priv) @@ -2312,5 +2309,5 @@ int hostif_init(struct ks_wlan_private *priv) void hostif_exit(struct ks_wlan_private *priv) { - tasklet_kill(&priv->sme_task); + cancel_work_sync(&priv->sme_work); } diff --git a/drivers/staging/ks7010/ks_wlan.h b/drivers/staging/ks7010/ks_wlan.h index 7aaf8d780939..3e9a91b5131c 100644 --- a/drivers/staging/ks7010/ks_wlan.h +++ b/drivers/staging/ks7010/ks_wlan.h @@ -449,7 +449,7 @@ struct ks_wlan_private { struct sme_info sme_i; u8 *rxp; unsigned int rx_size; - struct tasklet_struct sme_task; + struct work_struct sme_work; struct work_struct wakeup_work; int scan_ind_count; diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig index e3aaae920847..d4f03b203ae5 100644 --- a/drivers/staging/media/Kconfig +++ b/drivers/staging/media/Kconfig @@ -22,10 +22,12 @@ if STAGING_MEDIA && MEDIA_SUPPORT # Please keep them in alphabetic order source "drivers/staging/media/atomisp/Kconfig" -source "drivers/staging/media/hantro/Kconfig" - source "drivers/staging/media/imx/Kconfig" +source "drivers/staging/media/ipu3/Kconfig" + +source "drivers/staging/media/max96712/Kconfig" + source "drivers/staging/media/meson/vdec/Kconfig" source "drivers/staging/media/omap4iss/Kconfig" @@ -34,14 +36,29 @@ source "drivers/staging/media/rkvdec/Kconfig" source "drivers/staging/media/sunxi/Kconfig" -source "drivers/staging/media/tegra-vde/Kconfig" +source "drivers/staging/media/tegra-video/Kconfig" -source "drivers/staging/media/zoran/Kconfig" +menuconfig STAGING_MEDIA_DEPRECATED + bool "Media staging drivers (DEPRECATED)" + default n + help + This option enables deprecated media drivers that are + scheduled for future removal from the kernel. -source "drivers/staging/media/tegra-video/Kconfig" + If you wish to work on these drivers to prevent their removal, + then contact the linux-media@vger.kernel.org mailing list. -source "drivers/staging/media/ipu3/Kconfig" + If in doubt, say N here. -source "drivers/staging/media/av7110/Kconfig" +if STAGING_MEDIA_DEPRECATED +source "drivers/staging/media/deprecated/cpia2/Kconfig" +source "drivers/staging/media/deprecated/fsl-viu/Kconfig" +source "drivers/staging/media/deprecated/meye/Kconfig" +source "drivers/staging/media/deprecated/saa7146/Kconfig" +source "drivers/staging/media/deprecated/stkwebcam/Kconfig" +source "drivers/staging/media/deprecated/tm6000/Kconfig" +source "drivers/staging/media/deprecated/vpfe_capture/Kconfig" +source "drivers/staging/media/deprecated/zr364xx/Kconfig" +endif endif diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile index 5b5afc5b03a0..a387692b84f2 100644 --- a/drivers/staging/media/Makefile +++ b/drivers/staging/media/Makefile @@ -1,13 +1,18 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_INTEL_ATOMISP) += atomisp/ +obj-$(CONFIG_VIDEO_CPIA2) += deprecated/cpia2/ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx/ +obj-$(CONFIG_VIDEO_MAX96712) += max96712/ obj-$(CONFIG_VIDEO_MESON_VDEC) += meson/vdec/ +obj-$(CONFIG_VIDEO_MEYE) += deprecated/meye/ obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/ obj-$(CONFIG_VIDEO_ROCKCHIP_VDEC) += rkvdec/ +obj-$(CONFIG_VIDEO_STKWEBCAM) += deprecated/stkwebcam/ obj-$(CONFIG_VIDEO_SUNXI) += sunxi/ obj-$(CONFIG_VIDEO_TEGRA) += tegra-video/ -obj-$(CONFIG_TEGRA_VDE) += tegra-vde/ -obj-$(CONFIG_VIDEO_HANTRO) += hantro/ obj-$(CONFIG_VIDEO_IPU3_IMGU) += ipu3/ -obj-$(CONFIG_VIDEO_ZORAN) += zoran/ -obj-$(CONFIG_DVB_AV7110) += av7110/ +obj-$(CONFIG_VIDEO_TM6000) += deprecated/tm6000/ +obj-$(CONFIG_VIDEO_VIU) += deprecated/fsl-viu/ +obj-$(CONFIG_USB_ZR364XX) += deprecated/zr364xx/ +obj-y += deprecated/vpfe_capture/ +obj-y += deprecated/saa7146/ diff --git a/drivers/staging/media/atomisp/Kconfig b/drivers/staging/media/atomisp/Kconfig index aeed5803dfb1..2c8d7fdcc5f7 100644 --- a/drivers/staging/media/atomisp/Kconfig +++ b/drivers/staging/media/atomisp/Kconfig @@ -11,7 +11,7 @@ menuconfig INTEL_ATOMISP config VIDEO_ATOMISP tristate "Intel Atom Image Signal Processor Driver" - depends on VIDEO_V4L2 && INTEL_ATOMISP + depends on VIDEO_DEV && INTEL_ATOMISP depends on PMIC_OPREGION select IOSF_MBI select VIDEOBUF_VMALLOC diff --git a/drivers/staging/media/atomisp/Makefile b/drivers/staging/media/atomisp/Makefile index 606b7754fdfd..532e12ed72e6 100644 --- a/drivers/staging/media/atomisp/Makefile +++ b/drivers/staging/media/atomisp/Makefile @@ -13,12 +13,10 @@ atomisp = $(srctree)/drivers/staging/media/atomisp/ # SPDX-License-Identifier: GPL-2.0 atomisp-objs += \ - pci/atomisp_acc.o \ pci/atomisp_cmd.o \ pci/atomisp_compat_css20.o \ pci/atomisp_csi2.o \ pci/atomisp_drvfs.o \ - pci/atomisp_file.o \ pci/atomisp_fops.o \ pci/atomisp_ioctl.o \ pci/atomisp_subdev.o \ @@ -27,20 +25,16 @@ atomisp-objs += \ pci/sh_css_firmware.o \ pci/sh_css_host_data.o \ pci/sh_css_hrt.o \ - pci/sh_css_metadata.o \ pci/sh_css_metrics.o \ pci/sh_css_mipi.o \ pci/sh_css_mmu.o \ - pci/sh_css_morph.o \ pci/sh_css.o \ pci/sh_css_param_dvs.o \ pci/sh_css_param_shading.o \ pci/sh_css_params.o \ pci/sh_css_properties.o \ - pci/sh_css_shading.o \ pci/sh_css_sp.o \ pci/sh_css_stream_format.o \ - pci/sh_css_stream.o \ pci/sh_css_version.o \ pci/base/circbuf/src/circbuf.o \ pci/base/refcount/src/refcount.o \ @@ -49,10 +43,11 @@ atomisp-objs += \ pci/camera/pipe/src/pipe_util.o \ pci/camera/util/src/util.o \ pci/hmm/hmm_bo.o \ - pci/hmm/hmm_dynamic_pool.o \ pci/hmm/hmm.o \ - pci/hmm/hmm_reserved_pool.o \ pci/ia_css_device_access.o \ + pci/ia_css_isp_configs.o \ + pci/ia_css_isp_states.o \ + pci/ia_css_isp_params.o \ pci/isp/kernels/aa/aa_2/ia_css_aa2.host.o \ pci/isp/kernels/anr/anr_1.0/ia_css_anr.host.o \ pci/isp/kernels/anr/anr_2/ia_css_anr2.host.o \ @@ -154,21 +149,13 @@ atomisp-objs += \ pci/hive_isp_css_common/host/timed_ctrl.o \ pci/hive_isp_css_common/host/vmem.o \ pci/hive_isp_css_shared/host/tag.o \ - pci/system_local.o \ - -obj-byt = \ - pci/css_2400_system/hive/ia_css_isp_configs.o \ - pci/css_2400_system/hive/ia_css_isp_params.o \ - pci/css_2400_system/hive/ia_css_isp_states.o \ + pci/system_local.o # These will be needed when clean merge CHT support nicely into the driver # Keep them here handy for when we get to that point # obj-cht = \ - pci/css_2401_system/hive/ia_css_isp_configs.o \ - pci/css_2401_system/hive/ia_css_isp_params.o \ - pci/css_2401_system/hive/ia_css_isp_states.o \ pci/css_2401_system/host/csi_rx.o \ pci/css_2401_system/host/ibuf_ctrl.o \ pci/css_2401_system/host/isys_dma.o \ @@ -306,10 +293,8 @@ INCLUDES += \ -I$(atomisp)/pci/runtime/rmgr/interface/ \ -I$(atomisp)/pci/runtime/spctrl/interface/ \ -I$(atomisp)/pci/runtime/tagger/interface/ \ - -I$(atomisp)/pci/css_2400_system/hive/ \ -I$(atomisp)/pci/css_2401_system/ \ -I$(atomisp)/pci/css_2401_system/host/ \ - -I$(atomisp)/pci/css_2401_system/hive/ \ -I$(atomisp)/pci/css_2401_system/hrt/ DEFINES := -DHRT_HW -DHRT_ISP_CSS_CUSTOM_HOST -DHRT_USE_VIR_ADDRS -D__HOST__ @@ -324,10 +309,7 @@ ifeq ($(CONFIG_VIDEO_ATOMISP_ISP2401),y) atomisp-objs += \ $(obj-cht) \ pci/runtime/isys/src/ibuf_ctrl_rmgr.o -DEFINES += -DISP2401 -DISP2401_NEW_INPUT_SYSTEM -DSYSTEM_hive_isp_css_2401_system -else -atomisp-objs += $(obj-byt) -DEFINES += -DISP2400 -DSYSTEM_hive_isp_css_2400_system +DEFINES += -DISP2401 endif ccflags-y += $(INCLUDES) $(DEFINES) -fno-common diff --git a/drivers/staging/media/atomisp/TODO b/drivers/staging/media/atomisp/TODO index 2d1ef9eb262a..43b842043f29 100644 --- a/drivers/staging/media/atomisp/TODO +++ b/drivers/staging/media/atomisp/TODO @@ -1,92 +1,161 @@ +For both Cherrytrail (CHT) and Baytrail (BHT) the driver +requires the "candrpv_0415_20150521_0458" firmware version. +It should be noticed that the firmware file is different, +depending on the ISP model, so they're stored with different +names: + +- for BHT: /lib/firmware/shisp_2400b0_v21.bin + + Warning: The driver was not tested yet for BHT. + +- for CHT: /lib/firmware/shisp_2401a0_v21.bin + + https://github.com/intel-aero/meta-intel-aero-base/blob/master/recipes-kernel/linux/linux-yocto/shisp_2401a0_v21.bin + NOTE: ===== -While the driver probes the hardware and reports itself as a -V4L2 driver, there are still some issues preventing it to -stream (at least it doesn't with the standard V4L2 applications. -Didn't test yet with some custom-made app for this driver). -Solving the related bugs and issues preventing it to work is -needed (items 6 and 7 from the list below). +This driver currently doesn't work with most V4L2 applications, +as there are still some issues with regards to implementing +certain APIs at the standard way. + +Also, currently only USERPTR streaming mode is working. + +In order to test, it is needed to know what's the sensor's +resolution. This can be checked with: + +$ v4l2-ctl --get-fmt-video + Format Video Capture: + Width/Height : 1600/1200 + ... + +It is known to work with: + +- v4l2grab at contrib/test directory at https://git.linuxtv.org/v4l-utils.git/ + + The resolution should not be bigger than the max resolution + supported by the sensor, or it will fail. So, if the sensor + reports: + + The driver can be tested with: + + v4l2grab -f YUYV -x 1600 -y 1200 -d /dev/video2 -u + +- NVT at https://github.com/intel/nvt + + $ ./v4l2n -o testimage_@.raw \ + --device /dev/video2 \ + --input 0 \ + --exposure=30000,30000,30000,30000 \ + --parm type=1,capturemode=CI_MODE_PREVIEW \ + --fmt type=1,width=1600,height=1200,pixelformat=YUYV \ + --reqbufs count=2,memory=USERPTR \ + --parameters=wb_config.r=32768,wb_config.gr=21043,wb_config.gb=21043,wb_config.b=30863 \ + --capture=20 + + As the output is in raw format, images need to be converted with: + + $ for i in $(seq 0 19); do + name="testimage_$(printf "%03i" $i)" + ./raw2pnm -x$WIDTH -y$HEIGHT -f$FORMAT $name.raw $name.pnm + rm $name.raw + done TODO ==== -1. The atomisp doesn't rely at the usual i2c stuff to discover the - sensors. Instead, it calls a function from atomisp_gmin_platform.c. - There are some hacks added there for it to wait for sensors to be - probed (with a timeout of 2 seconds or so). - This should be converted to the usual way, using V4L2 async subdev - framework to wait for cameras to be probed; +1. Fix support for MMAP streaming mode. This is required for most + V4L2 applications; -2. Use ACPI _DSM table - DONE! +2. Implement and/or fix V4L2 ioctls in order to allow a normal app to + use it; -3. Switch the driver to use pm_runtime stuff. Right now, it probes the - existing PMIC code and sensors call it directly. +3. Ensure that the driver will pass v4l2-compliance tests; -4. There's a problem at the sensor drivers: when trying to set a video - format, the atomisp main driver calls the sensor drivers with the - sensor turned off. This causes them to fail. +4. Get manufacturer's authorization to redistribute the binaries for + the firmware files; - The only exception is the atomisp-ov2880, which has a hack inside it - to turn it on when VIDIOC_S_FMT is called. +5. remove VIDEO_ATOMISP_ISP2401, making the driver to auto-detect the + register address differences between ISP2400 and ISP2401; - The right fix seems to power on the sensor when a video device is - opened (or at the first VIDIOC_ ioctl - except for VIDIOC_QUERYCAP), - powering it down at close() syscall. +6. Cleanup the driver code, removing the abstraction layers inside it; - Such kind of control would need to be done inside the atomisp driver, - not at the sensors code. +7. The atomisp doesn't rely at the usual i2c stuff to discover the + sensors. Instead, it calls a function from atomisp_gmin_platform.c. + There are some hacks added there for it to wait for sensors to be + probed (with a timeout of 2 seconds or so). This should be converted + to the usual way, using V4L2 async subdev framework to wait for + cameras to be probed; -5. There are several issues related to memory management, causing - crashes. The atomisp splits the memory management on three separate - regions: +8. Switch to standard V4L2 sub-device API for sensor and lens. In + particular, the user space API needs to support V4L2 controls as + defined in the V4L2 spec and references to atomisp must be removed from + these drivers. + +9. Use LED flash API for flash LED drivers such as LM3554 (which already + has a LED class driver). + +10. Migrate the sensor drivers out of staging or re-using existing + drivers; + +11. Switch the driver to use pm_runtime stuff. Right now, it probes the + existing PMIC code and sensors call it directly. + +12. There's a problem on sensor drivers: when trying to set a video + format, the atomisp main driver calls the sensor drivers with the + sensor turned off. This causes them to fail. + + This was fixed at atomisp-ov2880, which has a hack inside it + to turn it on when VIDIOC_S_FMT is called, but this has to be + cheked on other drivers as well. + + The right fix seems to power on the sensor when a video device is + opened (or at the first VIDIOC_ ioctl - except for VIDIOC_QUERYCAP), + powering it down at close() syscall. + + Such kind of control would need to be done inside the atomisp driver, + not at the sensors code. + +13. There are several issues related to memory management, that can + cause crashes and/or memory leaks. The atomisp splits the memory + management on three separate regions: - dynamic pool; - reserved pool; - generic pool - The code implementing it is at: + The code implementing it is at: drivers/staging/media/atomisp/pci/hmm/ - It also has a separate code for managing DMA buffers at: + It also has a separate code for managing DMA buffers at: drivers/staging/media/atomisp/pci/mmu/ - The code there is really dirty, ugly and probably wrong. I fixed - one bug there already, but the best would be to just trash it and use - something else. Maybe the code from the newer intel driver could - serve as a model: + The code there is really dirty, ugly and probably wrong. I fixed + one bug there already, but the best would be to just trash it and use + something else. Maybe the code from the newer intel driver could + serve as a model: drivers/staging/media/ipu3/ipu3-mmu.c - But converting it to use something like that is painful and may - cause some breakages. - -6. There is some issues at the frame receive logic, causing the - DQBUF ioctls to fail. - -7. A single AtomISP driver needs to be implemented to support both - Baytrail (BYT) and Cherrytail (CHT) platforms at the same time. - The current driver is a mechanical and hand combined merge of the - two using several runtime macros, plus some ifdef ISP2401 to select the - CHT version. Yet, there are some ISP-specific headers that change the - driver's behavior during compile time. + But converting it to use something like that is painful and may + cause some breakages. -8. The file structure needs to get tidied up to resemble a normal Linux - driver. +14. The file structure needs to get tidied up to resemble a normal Linux + driver. -9. Lots of the midlayer glue. unused code and abstraction needs removing. +15. Lots of the midlayer glue. Unused code and abstraction needs removing. -10. The AtomISP driver includes some special IOCTLS (ATOMISP_IOC_XXXX_XXXX) +16. The AtomISP driver includes some special IOCTLS (ATOMISP_IOC_XXXX_XXXX) and controls that require some cleanup. Some of those code may have been removed during the cleanups. They could be needed in order to - properly support 3A algorithms + properly support 3A algorithms. Such IOCTL interface needs more documentation. The better would be to use something close to the interface used by the IPU3 IMGU driver. -11. The ISP code has some dependencies of the exact FW version. +17. The ISP code has some dependencies of the exact FW version. The version defined in pci/sh_css_firmware.c: BYT (isp2400): "irci_stable_candrpv_0415_20150521_0458" @@ -106,24 +175,16 @@ TODO there are any specific things that can be done to fold in support for multiple firmware versions. -12. Switch to standard V4L2 sub-device API for sensor and lens. In - particular, the user space API needs to support V4L2 controls as - defined in the V4L2 spec and references to atomisp must be removed from - these drivers. - -13. Use LED flash API for flash LED drivers such as LM3554 (which already - has a LED class driver). -14. Switch from videobuf1 to videobuf2. Videobuf1 is being removed! +18. Switch from videobuf1 to videobuf2. Videobuf1 is being removed! -15. Correct Coding Style. Please refrain sending coding style patches +19. Correct Coding Style. Please refrain sending coding style patches for this driver until the other work is done, as there will be a lot of code churn until this driver becomes functional again. -16. Fix private ioctls to not need a compat_ioctl handler for running - 32-bit tasks. The compat code has been removed because of bugs, - and should not be needed for modern drivers. Fixing this properly - unfortunately means an incompatible ABI change. +20. Remove the logic which sets up pipelines inside it, moving it to + libcamera and implement MC support. + Limitations =========== diff --git a/drivers/staging/media/atomisp/i2c/Kconfig b/drivers/staging/media/atomisp/i2c/Kconfig index a772b833a85f..e726101b24e4 100644 --- a/drivers/staging/media/atomisp/i2c/Kconfig +++ b/drivers/staging/media/atomisp/i2c/Kconfig @@ -6,7 +6,7 @@ config VIDEO_ATOMISP_OV2722 tristate "OVT ov2722 sensor support" depends on ACPI - depends on I2C && VIDEO_V4L2 + depends on I2C && VIDEO_DEV help This is a Video4Linux2 sensor-level driver for the OVT OV2722 raw camera. @@ -18,7 +18,7 @@ config VIDEO_ATOMISP_OV2722 config VIDEO_ATOMISP_GC2235 tristate "Galaxy gc2235 sensor support" depends on ACPI - depends on I2C && VIDEO_V4L2 + depends on I2C && VIDEO_DEV help This is a Video4Linux2 sensor-level driver for the OVT GC2235 raw camera. @@ -40,7 +40,7 @@ config VIDEO_ATOMISP_MSRLIST_HELPER config VIDEO_ATOMISP_MT9M114 tristate "Aptina mt9m114 sensor support" depends on ACPI - depends on I2C && VIDEO_V4L2 + depends on I2C && VIDEO_DEV help This is a Video4Linux2 sensor-level driver for the Micron mt9m114 1.3 Mpixel camera. @@ -52,7 +52,7 @@ config VIDEO_ATOMISP_MT9M114 config VIDEO_ATOMISP_GC0310 tristate "GC0310 sensor support" depends on ACPI - depends on I2C && VIDEO_V4L2 + depends on I2C && VIDEO_DEV help This is a Video4Linux2 sensor-level driver for the Galaxycore GC0310 0.3MP sensor. @@ -60,7 +60,7 @@ config VIDEO_ATOMISP_GC0310 config VIDEO_ATOMISP_OV2680 tristate "Omnivision OV2680 sensor support" depends on ACPI - depends on I2C && VIDEO_V4L2 + depends on I2C && VIDEO_DEV help This is a Video4Linux2 sensor-level driver for the Omnivision OV2680 raw camera. @@ -72,7 +72,7 @@ config VIDEO_ATOMISP_OV2680 config VIDEO_ATOMISP_OV5693 tristate "Omnivision ov5693 sensor support" depends on ACPI - depends on I2C && VIDEO_V4L2 + depends on I2C && VIDEO_DEV help This is a Video4Linux2 sensor-level driver for the Micron ov5693 5 Mpixel camera. @@ -88,7 +88,7 @@ config VIDEO_ATOMISP_OV5693 config VIDEO_ATOMISP_LM3554 tristate "LM3554 flash light driver" depends on ACPI - depends on VIDEO_V4L2 && I2C + depends on VIDEO_DEV && I2C help This is a Video4Linux2 sub-dev driver for the LM3554 flash light driver. diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c index 687888d643df..783f1b88ebf2 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c @@ -266,7 +266,7 @@ static int gc0310_g_bin_factor_x(struct v4l2_subdev *sd, s32 *val) { struct gc0310_device *dev = to_gc0310_sensor(sd); - *val = gc0310_res[dev->fmt_idx].bin_factor_x; + *val = dev->res->bin_factor_x; return 0; } @@ -275,7 +275,7 @@ static int gc0310_g_bin_factor_y(struct v4l2_subdev *sd, s32 *val) { struct gc0310_device *dev = to_gc0310_sensor(sd); - *val = gc0310_res[dev->fmt_idx].bin_factor_y; + *val = dev->res->bin_factor_y; return 0; } @@ -878,76 +878,6 @@ static int gc0310_s_power(struct v4l2_subdev *sd, int on) return gc0310_init(sd); } -/* - * distance - calculate the distance - * @res: resolution - * @w: width - * @h: height - * - * Get the gap between resolution and w/h. - * res->width/height smaller than w/h wouldn't be considered. - * Returns the value of gap or -1 if fail. - */ -#define LARGEST_ALLOWED_RATIO_MISMATCH 800 -static int distance(struct gc0310_resolution *res, u32 w, u32 h) -{ - unsigned int w_ratio = (res->width << 13) / w; - unsigned int h_ratio; - int match; - - if (h == 0) - return -1; - h_ratio = (res->height << 13) / h; - if (h_ratio == 0) - return -1; - match = abs(((w_ratio << 13) / h_ratio) - 8192); - - if ((w_ratio < 8192) || (h_ratio < 8192) || - (match > LARGEST_ALLOWED_RATIO_MISMATCH)) - return -1; - - return w_ratio + h_ratio; -} - -/* Return the nearest higher resolution index */ -static int nearest_resolution_index(int w, int h) -{ - int i; - int idx = -1; - int dist; - int min_dist = INT_MAX; - struct gc0310_resolution *tmp_res = NULL; - - for (i = 0; i < N_RES; i++) { - tmp_res = &gc0310_res[i]; - dist = distance(tmp_res, w, h); - if (dist == -1) - continue; - if (dist < min_dist) { - min_dist = dist; - idx = i; - } - } - - return idx; -} - -static int get_resolution_index(int w, int h) -{ - int i; - - for (i = 0; i < N_RES; i++) { - if (w != gc0310_res[i].width) - continue; - if (h != gc0310_res[i].height) - continue; - - return i; - } - - return -1; -} - /* TODO: remove it. */ static int startup(struct v4l2_subdev *sd) { @@ -955,7 +885,7 @@ static int startup(struct v4l2_subdev *sd) struct i2c_client *client = v4l2_get_subdevdata(sd); int ret = 0; - ret = gc0310_write_reg_array(client, gc0310_res[dev->fmt_idx].regs); + ret = gc0310_write_reg_array(client, dev->res->regs); if (ret) { dev_err(&client->dev, "gc0310 write register err.\n"); return ret; @@ -972,8 +902,8 @@ static int gc0310_set_fmt(struct v4l2_subdev *sd, struct gc0310_device *dev = to_gc0310_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); struct camera_mipi_info *gc0310_info = NULL; + struct gc0310_resolution *res; int ret = 0; - int idx = 0; if (format->pad) return -EINVAL; @@ -987,15 +917,16 @@ static int gc0310_set_fmt(struct v4l2_subdev *sd, mutex_lock(&dev->input_lock); - idx = nearest_resolution_index(fmt->width, fmt->height); - if (idx == -1) { - /* return the largest resolution */ - fmt->width = gc0310_res[N_RES - 1].width; - fmt->height = gc0310_res[N_RES - 1].height; - } else { - fmt->width = gc0310_res[idx].width; - fmt->height = gc0310_res[idx].height; - } + res = v4l2_find_nearest_size(gc0310_res_preview, + ARRAY_SIZE(gc0310_res_preview), width, + height, fmt->width, fmt->height); + if (!res) + res = &gc0310_res_preview[N_RES - 1]; + + fmt->width = res->width; + fmt->height = res->height; + dev->res = res; + fmt->code = MEDIA_BUS_FMT_SGRBG8_1X8; if (format->which == V4L2_SUBDEV_FORMAT_TRY) { @@ -1004,23 +935,15 @@ static int gc0310_set_fmt(struct v4l2_subdev *sd, return 0; } - dev->fmt_idx = get_resolution_index(fmt->width, fmt->height); - if (dev->fmt_idx == -1) { - dev_err(&client->dev, "get resolution fail\n"); - mutex_unlock(&dev->input_lock); - return -EINVAL; - } - dev_dbg(&client->dev, "%s: before gc0310_write_reg_array %s\n", - __func__, gc0310_res[dev->fmt_idx].desc); + __func__, dev->res->desc); ret = startup(sd); if (ret) { dev_err(&client->dev, "gc0310 startup err\n"); goto err; } - ret = gc0310_get_intg_factor(client, gc0310_info, - &gc0310_res[dev->fmt_idx]); + ret = gc0310_get_intg_factor(client, gc0310_info, dev->res); if (ret) { dev_err(&client->dev, "failed to get integration_factor\n"); goto err; @@ -1044,8 +967,8 @@ static int gc0310_get_fmt(struct v4l2_subdev *sd, if (!fmt) return -EINVAL; - fmt->width = gc0310_res[dev->fmt_idx].width; - fmt->height = gc0310_res[dev->fmt_idx].height; + fmt->width = dev->res->width; + fmt->height = dev->res->height; fmt->code = MEDIA_BUS_FMT_SGRBG8_1X8; return 0; @@ -1199,7 +1122,7 @@ static int gc0310_g_frame_interval(struct v4l2_subdev *sd, struct gc0310_device *dev = to_gc0310_sensor(sd); interval->interval.numerator = 1; - interval->interval.denominator = gc0310_res[dev->fmt_idx].fps; + interval->interval.denominator = dev->res->fps; return 0; } @@ -1237,7 +1160,7 @@ static int gc0310_g_skip_frames(struct v4l2_subdev *sd, u32 *frames) struct gc0310_device *dev = to_gc0310_sensor(sd); mutex_lock(&dev->input_lock); - *frames = gc0310_res[dev->fmt_idx].skip_frames; + *frames = dev->res->skip_frames; mutex_unlock(&dev->input_lock); return 0; @@ -1271,7 +1194,7 @@ static const struct v4l2_subdev_ops gc0310_ops = { .sensor = &gc0310_sensor_ops, }; -static int gc0310_remove(struct i2c_client *client) +static void gc0310_remove(struct i2c_client *client) { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct gc0310_device *dev = to_gc0310_sensor(sd); @@ -1284,8 +1207,6 @@ static int gc0310_remove(struct i2c_client *client) media_entity_cleanup(&dev->sd.entity); v4l2_ctrl_handler_free(&dev->ctrl_handler); kfree(dev); - - return 0; } static int gc0310_probe(struct i2c_client *client) @@ -1301,7 +1222,7 @@ static int gc0310_probe(struct i2c_client *client) mutex_init(&dev->input_lock); - dev->fmt_idx = 0; + dev->res = &gc0310_res_preview[0]; v4l2_i2c_subdev_init(&dev->sd, client, &gc0310_ops); pdata = gmin_camera_platform_data(&dev->sd, diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c b/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c index 4d769590f2d3..4d5a7e335f85 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc2235.c @@ -570,14 +570,16 @@ static int power_ctrl(struct v4l2_subdev *sd, bool flag) static int gpio_ctrl(struct v4l2_subdev *sd, bool flag) { struct gc2235_device *dev = to_gc2235_sensor(sd); - int ret = -1; + int ret; if (!dev || !dev->platform_data) return -ENODEV; - ret |= dev->platform_data->gpio1_ctrl(sd, !flag); + ret = dev->platform_data->gpio1_ctrl(sd, !flag); usleep_range(60, 90); - return dev->platform_data->gpio0_ctrl(sd, flag); + ret |= dev->platform_data->gpio0_ctrl(sd, flag); + + return ret; } static int power_up(struct v4l2_subdev *sd) @@ -670,76 +672,6 @@ static int gc2235_s_power(struct v4l2_subdev *sd, int on) return ret; } -/* - * distance - calculate the distance - * @res: resolution - * @w: width - * @h: height - * - * Get the gap between resolution and w/h. - * res->width/height smaller than w/h wouldn't be considered. - * Returns the value of gap or -1 if fail. - */ -#define LARGEST_ALLOWED_RATIO_MISMATCH 800 -static int distance(struct gc2235_resolution *res, u32 w, u32 h) -{ - unsigned int w_ratio = (res->width << 13) / w; - unsigned int h_ratio; - int match; - - if (h == 0) - return -1; - h_ratio = (res->height << 13) / h; - if (h_ratio == 0) - return -1; - match = abs(((w_ratio << 13) / h_ratio) - 8192); - - if ((w_ratio < 8192) || (h_ratio < 8192) || - (match > LARGEST_ALLOWED_RATIO_MISMATCH)) - return -1; - - return w_ratio + h_ratio; -} - -/* Return the nearest higher resolution index */ -static int nearest_resolution_index(int w, int h) -{ - int i; - int idx = -1; - int dist; - int min_dist = INT_MAX; - struct gc2235_resolution *tmp_res = NULL; - - for (i = 0; i < N_RES; i++) { - tmp_res = &gc2235_res[i]; - dist = distance(tmp_res, w, h); - if (dist == -1) - continue; - if (dist < min_dist) { - min_dist = dist; - idx = i; - } - } - - return idx; -} - -static int get_resolution_index(int w, int h) -{ - int i; - - for (i = 0; i < N_RES; i++) { - if (w != gc2235_res[i].width) - continue; - if (h != gc2235_res[i].height) - continue; - - return i; - } - - return -1; -} - static int startup(struct v4l2_subdev *sd) { struct gc2235_device *dev = to_gc2235_sensor(sd); @@ -758,7 +690,7 @@ static int startup(struct v4l2_subdev *sd) gc2235_write_reg_array(client, gc2235_init_settings); } - ret = gc2235_write_reg_array(client, gc2235_res[dev->fmt_idx].regs); + ret = gc2235_write_reg_array(client, dev->res->regs); if (ret) { dev_err(&client->dev, "gc2235 write register err.\n"); return ret; @@ -776,8 +708,8 @@ static int gc2235_set_fmt(struct v4l2_subdev *sd, struct gc2235_device *dev = to_gc2235_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); struct camera_mipi_info *gc2235_info = NULL; + struct gc2235_resolution *res; int ret = 0; - int idx; gc2235_info = v4l2_get_subdev_hostdata(sd); if (!gc2235_info) @@ -786,16 +718,18 @@ static int gc2235_set_fmt(struct v4l2_subdev *sd, return -EINVAL; if (!fmt) return -EINVAL; + mutex_lock(&dev->input_lock); - idx = nearest_resolution_index(fmt->width, fmt->height); - if (idx == -1) { - /* return the largest resolution */ - fmt->width = gc2235_res[N_RES - 1].width; - fmt->height = gc2235_res[N_RES - 1].height; - } else { - fmt->width = gc2235_res[idx].width; - fmt->height = gc2235_res[idx].height; - } + res = v4l2_find_nearest_size(gc2235_res_preview, + ARRAY_SIZE(gc2235_res_preview), width, + height, fmt->width, fmt->height); + if (!res) + res = &gc2235_res_preview[N_RES - 1]; + + fmt->width = res->width; + fmt->height = res->height; + dev->res = res; + fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; if (format->which == V4L2_SUBDEV_FORMAT_TRY) { sd_state->pads->try_fmt = *fmt; @@ -803,13 +737,6 @@ static int gc2235_set_fmt(struct v4l2_subdev *sd, return 0; } - dev->fmt_idx = get_resolution_index(fmt->width, fmt->height); - if (dev->fmt_idx == -1) { - dev_err(&client->dev, "get resolution fail\n"); - mutex_unlock(&dev->input_lock); - return -EINVAL; - } - ret = startup(sd); if (ret) { dev_err(&client->dev, "gc2235 startup err\n"); @@ -817,7 +744,7 @@ static int gc2235_set_fmt(struct v4l2_subdev *sd, } ret = gc2235_get_intg_factor(client, gc2235_info, - &gc2235_res[dev->fmt_idx]); + dev->res); if (ret) dev_err(&client->dev, "failed to get integration_factor\n"); @@ -839,8 +766,8 @@ static int gc2235_get_fmt(struct v4l2_subdev *sd, if (!fmt) return -EINVAL; - fmt->width = gc2235_res[dev->fmt_idx].width; - fmt->height = gc2235_res[dev->fmt_idx].height; + fmt->width = dev->res->width; + fmt->height = dev->res->height; fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; return 0; @@ -953,7 +880,7 @@ static int gc2235_g_frame_interval(struct v4l2_subdev *sd, struct gc2235_device *dev = to_gc2235_sensor(sd); interval->interval.numerator = 1; - interval->interval.denominator = gc2235_res[dev->fmt_idx].fps; + interval->interval.denominator = dev->res->fps; return 0; } @@ -991,7 +918,7 @@ static int gc2235_g_skip_frames(struct v4l2_subdev *sd, u32 *frames) struct gc2235_device *dev = to_gc2235_sensor(sd); mutex_lock(&dev->input_lock); - *frames = gc2235_res[dev->fmt_idx].skip_frames; + *frames = dev->res->skip_frames; mutex_unlock(&dev->input_lock); return 0; @@ -1025,7 +952,7 @@ static const struct v4l2_subdev_ops gc2235_ops = { .sensor = &gc2235_sensor_ops, }; -static int gc2235_remove(struct i2c_client *client) +static void gc2235_remove(struct i2c_client *client) { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct gc2235_device *dev = to_gc2235_sensor(sd); @@ -1038,8 +965,6 @@ static int gc2235_remove(struct i2c_client *client) media_entity_cleanup(&dev->sd.entity); v4l2_ctrl_handler_free(&dev->ctrl_handler); kfree(dev); - - return 0; } static int gc2235_probe(struct i2c_client *client) @@ -1055,7 +980,7 @@ static int gc2235_probe(struct i2c_client *client) mutex_init(&dev->input_lock); - dev->fmt_idx = 0; + dev->res = &gc2235_res_preview[0]; v4l2_i2c_subdev_init(&dev->sd, client, &gc2235_ops); gcpdev = gmin_camera_platform_data(&dev->sd, diff --git a/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c b/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c index e046489cd253..75d16b525294 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-lm3554.c @@ -910,7 +910,7 @@ free_flash: return err; } -static int lm3554_remove(struct i2c_client *client) +static void lm3554_remove(struct i2c_client *client) { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct lm3554 *flash = to_lm3554(sd); @@ -926,8 +926,6 @@ static int lm3554_remove(struct i2c_client *client) lm3554_gpio_uninit(client); kfree(flash); - - return 0; } static const struct dev_pm_ops lm3554_pm_ops = { diff --git a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c index 49f4090856d3..a0e8e94b2412 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-mt9m114.c @@ -579,107 +579,6 @@ static int mt9m114_s_power(struct v4l2_subdev *sd, int power) return mt9m114_init_common(sd); } -/* - * distance - calculate the distance - * @res: resolution - * @w: width - * @h: height - * - * Get the gap between resolution and w/h. - * res->width/height smaller than w/h wouldn't be considered. - * Returns the value of gap or -1 if fail. - */ -#define LARGEST_ALLOWED_RATIO_MISMATCH 600 -static int distance(struct mt9m114_res_struct const *res, u32 w, u32 h) -{ - unsigned int w_ratio; - unsigned int h_ratio; - int match; - - if (w == 0) - return -1; - w_ratio = (res->width << 13) / w; - if (h == 0) - return -1; - h_ratio = (res->height << 13) / h; - if (h_ratio == 0) - return -1; - match = abs(((w_ratio << 13) / h_ratio) - 8192); - - if ((w_ratio < 8192) || (h_ratio < 8192) || - (match > LARGEST_ALLOWED_RATIO_MISMATCH)) - return -1; - - return w_ratio + h_ratio; -} - -/* Return the nearest higher resolution index */ -static int nearest_resolution_index(int w, int h) -{ - int i; - int idx = -1; - int dist; - int min_dist = INT_MAX; - const struct mt9m114_res_struct *tmp_res = NULL; - - for (i = 0; i < ARRAY_SIZE(mt9m114_res); i++) { - tmp_res = &mt9m114_res[i]; - dist = distance(tmp_res, w, h); - if (dist == -1) - continue; - if (dist < min_dist) { - min_dist = dist; - idx = i; - } - } - - return idx; -} - -static int mt9m114_try_res(u32 *w, u32 *h) -{ - int idx = 0; - - if ((*w > MT9M114_RES_960P_SIZE_H) - || (*h > MT9M114_RES_960P_SIZE_V)) { - *w = MT9M114_RES_960P_SIZE_H; - *h = MT9M114_RES_960P_SIZE_V; - } else { - idx = nearest_resolution_index(*w, *h); - - /* - * nearest_resolution_index() doesn't return smaller - * resolutions. If it fails, it means the requested - * resolution is higher than wecan support. Fallback - * to highest possible resolution in this case. - */ - if (idx == -1) - idx = ARRAY_SIZE(mt9m114_res) - 1; - - *w = mt9m114_res[idx].width; - *h = mt9m114_res[idx].height; - } - - return 0; -} - -static struct mt9m114_res_struct *mt9m114_to_res(u32 w, u32 h) -{ - int index; - - for (index = 0; index < N_RES; index++) { - if ((mt9m114_res[index].width == w) && - (mt9m114_res[index].height == h)) - break; - } - - /* No mode found */ - if (index >= N_RES) - return NULL; - - return &mt9m114_res[index]; -} - static int mt9m114_res2size(struct v4l2_subdev *sd, int *h_size, int *v_size) { struct mt9m114_device *dev = to_mt9m114_sensor(sd); @@ -717,13 +616,15 @@ static int mt9m114_get_intg_factor(struct i2c_client *client, struct camera_mipi_info *info, const struct mt9m114_res_struct *res) { - struct atomisp_sensor_mode_data *buf = &info->data; + struct atomisp_sensor_mode_data *buf; u32 reg_val; int ret; if (!info) return -EINVAL; + buf = &info->data; + ret = mt9m114_read_reg(client, MISENSOR_32BIT, REG_PIXEL_CLK, ®_val); if (ret) @@ -829,7 +730,7 @@ static int mt9m114_set_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt = &format->format; struct i2c_client *c = v4l2_get_subdevdata(sd); struct mt9m114_device *dev = to_mt9m114_sensor(sd); - struct mt9m114_res_struct *res_index; + struct mt9m114_res_struct *res; u32 width = fmt->width; u32 height = fmt->height; struct camera_mipi_info *mt9m114_info = NULL; @@ -845,20 +746,21 @@ static int mt9m114_set_fmt(struct v4l2_subdev *sd, if (!mt9m114_info) return -EINVAL; - mt9m114_try_res(&width, &height); + res = v4l2_find_nearest_size(mt9m114_res, + ARRAY_SIZE(mt9m114_res), width, + height, fmt->width, fmt->height); + if (!res) + res = &mt9m114_res[N_RES - 1]; + + fmt->width = res->width; + fmt->height = res->height; + if (format->which == V4L2_SUBDEV_FORMAT_TRY) { sd_state->pads->try_fmt = *fmt; return 0; } - res_index = mt9m114_to_res(width, height); - /* Sanity check */ - if (unlikely(!res_index)) { - WARN_ON(1); - return -EINVAL; - } - - switch (res_index->res) { + switch (res->res) { case MT9M114_RES_736P: ret = mt9m114_write_reg_array(c, mt9m114_736P_init, NO_POLLING); ret += misensor_rmw_reg(c, MISENSOR_16BIT, MISENSOR_READ_MODE, @@ -876,7 +778,7 @@ static int mt9m114_set_fmt(struct v4l2_subdev *sd, MISENSOR_R_MODE_MASK, MISENSOR_NORMAL_SET); break; default: - v4l2_err(sd, "set resolution: %d failed!\n", res_index->res); + v4l2_err(sd, "set resolution: %d failed!\n", res->res); return -EINVAL; } @@ -890,7 +792,7 @@ static int mt9m114_set_fmt(struct v4l2_subdev *sd, if (mt9m114_set_suspend(sd)) return -EINVAL; - if (dev->res != res_index->res) { + if (dev->res != res->res) { int index; /* Switch to different size */ @@ -922,7 +824,7 @@ static int mt9m114_set_fmt(struct v4l2_subdev *sd, } } ret = mt9m114_get_intg_factor(c, mt9m114_info, - &mt9m114_res[res_index->res]); + &mt9m114_res[res->res]); if (ret) { dev_err(&c->dev, "failed to get integration_factor\n"); return -EINVAL; @@ -931,7 +833,7 @@ static int mt9m114_set_fmt(struct v4l2_subdev *sd, * mt9m114 - we don't poll for context switch * because it does not happen with streaming disabled. */ - dev->res = res_index->res; + dev->res = res->res; fmt->width = width; fmt->height = height; @@ -1811,7 +1713,7 @@ static const struct v4l2_subdev_ops mt9m114_ops = { .sensor = &mt9m114_sensor_ops, }; -static int mt9m114_remove(struct i2c_client *client) +static void mt9m114_remove(struct i2c_client *client) { struct mt9m114_device *dev; struct v4l2_subdev *sd = i2c_get_clientdata(client); @@ -1822,7 +1724,6 @@ static int mt9m114_remove(struct i2c_client *client) media_entity_cleanup(&dev->sd.entity); v4l2_ctrl_handler_free(&dev->ctrl_handler); kfree(dev); - return 0; } static int mt9m114_probe(struct i2c_client *client) diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c index 2111e4a478c1..fa1de45b7a2d 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2680.c @@ -48,7 +48,7 @@ static enum atomisp_bayer_order ov2680_bayer_order_mapping[] = { /* i2c read/write stuff */ static int ov2680_read_reg(struct i2c_client *client, - int len, u16 reg, u16 *val) + int len, u16 reg, u32 *val) { struct i2c_msg msgs[2]; u8 addr_buf[2] = { reg >> 8, reg & 0xff }; @@ -86,7 +86,7 @@ static int ov2680_write_reg(struct i2c_client *client, unsigned int len, int ret; if (len == 2) - put_unaligned_be16(val << (8 * (4 - len)), buf + 2); + put_unaligned_be16(val, buf + 2); else if (len == 1) buf[2] = val; else @@ -147,7 +147,7 @@ static int ov2680_g_bin_factor_x(struct v4l2_subdev *sd, s32 *val) struct i2c_client *client = v4l2_get_subdevdata(sd); dev_dbg(&client->dev, "++++ov2680_g_bin_factor_x\n"); - *val = ov2680_res[dev->fmt_idx].bin_factor_x; + *val = dev->res->bin_factor_x; return 0; } @@ -157,7 +157,7 @@ static int ov2680_g_bin_factor_y(struct v4l2_subdev *sd, s32 *val) struct ov2680_device *dev = to_ov2680_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); - *val = ov2680_res[dev->fmt_idx].bin_factor_y; + *val = dev->res->bin_factor_y; dev_dbg(&client->dev, "++++ov2680_g_bin_factor_y\n"); return 0; } @@ -166,11 +166,9 @@ static int ov2680_get_intg_factor(struct i2c_client *client, struct camera_mipi_info *info, const struct ov2680_resolution *res) { - struct v4l2_subdev *sd = i2c_get_clientdata(client); - struct ov2680_device *dev = to_ov2680_sensor(sd); struct atomisp_sensor_mode_data *buf = &info->data; unsigned int pix_clk_freq_hz; - u16 reg_val; + u32 reg_val; int ret; dev_dbg(&client->dev, "++++ov2680_get_intg_factor\n"); @@ -180,7 +178,6 @@ static int ov2680_get_intg_factor(struct i2c_client *client, /* pixel clock */ pix_clk_freq_hz = res->pix_clk_freq * 1000000; - dev->vt_pix_clk_freq_mhz = pix_clk_freq_hz; buf->vt_pix_clk_freq_mhz = pix_clk_freq_hz; /* get integration time */ @@ -254,7 +251,7 @@ static long __ov2680_set_exposure(struct v4l2_subdev *sd, int coarse_itg, "+++++++__ov2680_set_exposure coarse_itg %d, gain %d, digitgain %d++\n", coarse_itg, gain, digitgain); - vts = ov2680_res[dev->fmt_idx].lines_per_frame; + vts = dev->res->lines_per_frame; /* group hold */ ret = ov2680_write_reg(client, 1, @@ -359,10 +356,17 @@ static int ov2680_set_exposure(struct v4l2_subdev *sd, int exposure, int gain, int digitgain) { struct ov2680_device *dev = to_ov2680_sensor(sd); - int ret; + int ret = 0; mutex_lock(&dev->input_lock); - ret = __ov2680_set_exposure(sd, exposure, gain, digitgain); + + dev->exposure = exposure; + dev->gain = gain; + dev->digitgain = digitgain; + + if (dev->power_on) + ret = __ov2680_set_exposure(sd, exposure, gain, digitgain); + mutex_unlock(&dev->input_lock); return ret; @@ -383,7 +387,6 @@ static long ov2680_s_exposure(struct v4l2_subdev *sd, return -EINVAL; } - // EXPOSURE CONTROL DISABLED FOR INITIAL CHECKIN, TUNING DOESN'T WORK return ov2680_set_exposure(sd, coarse_itg, analog_gain, digital_gain); } @@ -406,56 +409,25 @@ static long ov2680_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) static int ov2680_q_exposure(struct v4l2_subdev *sd, s32 *value) { struct i2c_client *client = v4l2_get_subdevdata(sd); - u16 reg_v, reg_v2; + u32 reg_val; int ret; /* get exposure */ - ret = ov2680_read_reg(client, 1, - OV2680_EXPOSURE_L, - ®_v); - if (ret) - goto err; - - ret = ov2680_read_reg(client, 1, - OV2680_EXPOSURE_M, - ®_v2); - if (ret) - goto err; - - reg_v += reg_v2 << 8; - ret = ov2680_read_reg(client, 1, - OV2680_EXPOSURE_H, - ®_v2); + ret = ov2680_read_reg(client, 3, OV2680_EXPOSURE_H, ®_val); if (ret) - goto err; - - *value = reg_v + (((u32)reg_v2 << 16)); -err: - return ret; -} + return ret; -static u32 ov2680_translate_bayer_order(enum atomisp_bayer_order code) -{ - switch (code) { - case atomisp_bayer_order_rggb: - return MEDIA_BUS_FMT_SRGGB10_1X10; - case atomisp_bayer_order_grbg: - return MEDIA_BUS_FMT_SGRBG10_1X10; - case atomisp_bayer_order_bggr: - return MEDIA_BUS_FMT_SBGGR10_1X10; - case atomisp_bayer_order_gbrg: - return MEDIA_BUS_FMT_SGBRG10_1X10; - } + /* Lower four bits are not part of the exposure val (always 0) */ + *value = reg_val >> 4; return 0; } static int ov2680_v_flip(struct v4l2_subdev *sd, s32 value) { - struct ov2680_device *dev = to_ov2680_sensor(sd); struct camera_mipi_info *ov2680_info = NULL; struct i2c_client *client = v4l2_get_subdevdata(sd); int ret; - u16 val; + u32 val; u8 index; dev_dbg(&client->dev, "@%s: value:%d\n", __func__, value); @@ -476,19 +448,16 @@ static int ov2680_v_flip(struct v4l2_subdev *sd, s32 value) ov2680_info = v4l2_get_subdev_hostdata(sd); if (ov2680_info) { ov2680_info->raw_bayer_order = ov2680_bayer_order_mapping[index]; - dev->format.code = ov2680_translate_bayer_order( - ov2680_info->raw_bayer_order); } return ret; } static int ov2680_h_flip(struct v4l2_subdev *sd, s32 value) { - struct ov2680_device *dev = to_ov2680_sensor(sd); struct camera_mipi_info *ov2680_info = NULL; struct i2c_client *client = v4l2_get_subdevdata(sd); int ret; - u16 val; + u32 val; u8 index; dev_dbg(&client->dev, "@%s: value:%d\n", __func__, value); @@ -510,8 +479,6 @@ static int ov2680_h_flip(struct v4l2_subdev *sd, s32 value) ov2680_info = v4l2_get_subdev_hostdata(sd); if (ov2680_info) { ov2680_info->raw_bayer_order = ov2680_bayer_order_mapping[index]; - dev->format.code = ov2680_translate_bayer_order( - ov2680_info->raw_bayer_order); } return ret; } @@ -677,25 +644,6 @@ static int ov2680_init_registers(struct v4l2_subdev *sd) return ret; } -static int ov2680_init(struct v4l2_subdev *sd) -{ - struct ov2680_device *dev = to_ov2680_sensor(sd); - - int ret; - - mutex_lock(&dev->input_lock); - - /* restore settings */ - ov2680_res = ov2680_res_preview; - N_RES = N_RES_PREVIEW; - - ret = ov2680_init_registers(sd); - - mutex_unlock(&dev->input_lock); - - return ret; -} - static int power_ctrl(struct v4l2_subdev *sd, bool flag) { int ret = 0; @@ -760,6 +708,9 @@ static int power_up(struct v4l2_subdev *sd) return -ENODEV; } + if (dev->power_on) + return 0; /* Already on */ + /* power control */ ret = power_ctrl(sd, 1); if (ret) @@ -784,8 +735,19 @@ static int power_up(struct v4l2_subdev *sd) /* according to DS, 20ms is needed between PWDN and i2c access */ msleep(20); + ret = ov2680_init_registers(sd); + if (ret) + goto fail_init_registers; + + ret = __ov2680_set_exposure(sd, dev->exposure, dev->gain, dev->digitgain); + if (ret) + goto fail_init_registers; + + dev->power_on = true; return 0; +fail_init_registers: + dev->platform_data->flisclk_ctrl(sd, 0); fail_clk: gpio_ctrl(sd, 0); fail_power: @@ -809,6 +771,9 @@ static int power_down(struct v4l2_subdev *sd) return -ENODEV; } + if (!dev->power_on) + return 0; /* Already off */ + ret = dev->platform_data->flisclk_ctrl(sd, 0); if (ret) dev_err(&client->dev, "flisclk failed\n"); @@ -823,94 +788,31 @@ static int power_down(struct v4l2_subdev *sd) /* power control */ ret = power_ctrl(sd, 0); - if (ret) + if (ret) { dev_err(&client->dev, "vprog failed.\n"); + return ret; + } - return ret; + dev->power_on = false; + return 0; } static int ov2680_s_power(struct v4l2_subdev *sd, int on) { + struct ov2680_device *dev = to_ov2680_sensor(sd); int ret; + mutex_lock(&dev->input_lock); + if (on == 0) { ret = power_down(sd); } else { ret = power_up(sd); - if (!ret) - return ov2680_init(sd); } - return ret; -} -/* - * distance - calculate the distance - * @res: resolution - * @w: width - * @h: height - * - * Get the gap between resolution and w/h. - * res->width/height smaller than w/h wouldn't be considered. - * Returns the value of gap or -1 if fail. - */ -#define LARGEST_ALLOWED_RATIO_MISMATCH 600 -static int distance(struct ov2680_resolution *res, u32 w, u32 h) -{ - unsigned int w_ratio = (res->width << 13) / w; - unsigned int h_ratio; - int match; - - if (h == 0) - return -1; - h_ratio = (res->height << 13) / h; - if (h_ratio == 0) - return -1; - match = abs(((w_ratio << 13) / h_ratio) - 8192); - - if ((w_ratio < 8192) || (h_ratio < 8192) || - (match > LARGEST_ALLOWED_RATIO_MISMATCH)) - return -1; - - return w_ratio + h_ratio; -} - -/* Return the nearest higher resolution index */ -static int nearest_resolution_index(int w, int h) -{ - int i; - int idx = -1; - int dist; - int min_dist = INT_MAX; - struct ov2680_resolution *tmp_res = NULL; - - for (i = 0; i < N_RES; i++) { - tmp_res = &ov2680_res[i]; - dist = distance(tmp_res, w, h); - if (dist == -1) - continue; - if (dist < min_dist) { - min_dist = dist; - idx = i; - } - } - - return idx; -} - -static int get_resolution_index(int w, int h) -{ - int i; - - for (i = 0; i < N_RES; i++) { - if (w != ov2680_res[i].width) - continue; - if (h != ov2680_res[i].height) - continue; - - return i; - } + mutex_unlock(&dev->input_lock); - return -1; + return ret; } static int ov2680_set_fmt(struct v4l2_subdev *sd, @@ -921,8 +823,8 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, struct ov2680_device *dev = to_ov2680_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); struct camera_mipi_info *ov2680_info = NULL; - int ret = 0; - int idx = 0; + struct ov2680_resolution *res; + int vts, ret = 0; dev_dbg(&client->dev, "%s: %s: pad: %d, fmt: %p\n", __func__, @@ -939,42 +841,48 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, if (!ov2680_info) return -EINVAL; - mutex_lock(&dev->input_lock); - idx = nearest_resolution_index(fmt->width, fmt->height); - if (idx == -1) { - /* return the largest resolution */ - fmt->width = ov2680_res[N_RES - 1].width; - fmt->height = ov2680_res[N_RES - 1].height; - } else { - fmt->width = ov2680_res[idx].width; - fmt->height = ov2680_res[idx].height; - } + res = v4l2_find_nearest_size(ov2680_res_preview, + ARRAY_SIZE(ov2680_res_preview), width, + height, fmt->width, fmt->height); + if (!res) + res = &ov2680_res_preview[N_RES_PREVIEW - 1]; + + fmt->width = res->width; + fmt->height = res->height; + fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; if (format->which == V4L2_SUBDEV_FORMAT_TRY) { sd_state->pads->try_fmt = *fmt; - mutex_unlock(&dev->input_lock); return 0; } - dev->fmt_idx = get_resolution_index(fmt->width, fmt->height); - dev_dbg(&client->dev, "%s: Resolution index: %d\n", - __func__, dev->fmt_idx); - if (dev->fmt_idx == -1) { - dev_err(&client->dev, "get resolution fail\n"); - mutex_unlock(&dev->input_lock); - return -EINVAL; - } - dev_dbg(&client->dev, "%s: i=%d, w=%d, h=%d\n", - __func__, dev->fmt_idx, fmt->width, fmt->height); - // IS IT NEEDED? + dev_dbg(&client->dev, "%s: %dx%d\n", + __func__, fmt->width, fmt->height); + + mutex_lock(&dev->input_lock); + + /* s_power has not been called yet for std v4l2 clients (camorama) */ power_up(sd); - ret = ov2680_write_reg_array(client, ov2680_res[dev->fmt_idx].regs); - if (ret) + ret = ov2680_write_reg_array(client, dev->res->regs); + if (ret) { dev_err(&client->dev, "ov2680 write resolution register err: %d\n", ret); + goto err; + } + + vts = dev->res->lines_per_frame; + + /* If necessary increase the VTS to match exposure + MARGIN */ + if (dev->exposure > vts - OV2680_INTEGRATION_TIME_MARGIN) + vts = dev->exposure + OV2680_INTEGRATION_TIME_MARGIN; - ret = ov2680_get_intg_factor(client, ov2680_info, - &ov2680_res[dev->fmt_idx]); + ret = ov2680_write_reg(client, 2, OV2680_TIMING_VTS_H, vts); + if (ret) { + dev_err(&client->dev, "ov2680 write vts err: %d\n", ret); + goto err; + } + + ret = ov2680_get_intg_factor(client, ov2680_info, res); if (ret) { dev_err(&client->dev, "failed to get integration factor\n"); goto err; @@ -989,13 +897,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, if (v_flag) ov2680_v_flip(sd, v_flag); - v4l2_info(client, "\n%s idx %d\n", __func__, dev->fmt_idx); - - /* - * ret = startup(sd); - * if (ret) - * dev_err(&client->dev, "ov2680 startup err\n"); - */ + dev->res = res; err: mutex_unlock(&dev->input_lock); return ret; @@ -1014,8 +916,8 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd, if (!fmt) return -EINVAL; - fmt->width = ov2680_res[dev->fmt_idx].width; - fmt->height = ov2680_res[dev->fmt_idx].height; + fmt->width = dev->res->width; + fmt->height = dev->res->height; fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; return 0; @@ -1024,7 +926,7 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd, static int ov2680_detect(struct i2c_client *client) { struct i2c_adapter *adapter = client->adapter; - u16 high, low; + u32 high, low; int ret; u16 id; u8 revision; @@ -1072,11 +974,6 @@ static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) ret = ov2680_write_reg(client, 1, OV2680_SW_STREAM, enable ? OV2680_START_STREAMING : OV2680_STOP_STREAMING); -#if 0 - /* restore settings */ - ov2680_res = ov2680_res_preview; - N_RES = N_RES_PREVIEW; -#endif //otp valid at stream on state //if(!dev->otp_data) @@ -1101,16 +998,6 @@ static int ov2680_s_config(struct v4l2_subdev *sd, (struct camera_sensor_platform_data *)platform_data; mutex_lock(&dev->input_lock); - /* - * power off the module, then power on it in future - * as first power on by board may not fulfill the - * power on sequqence needed by the module - */ - ret = power_down(sd); - if (ret) { - dev_err(&client->dev, "ov2680 power-off err.\n"); - goto fail_power_off; - } ret = power_up(sd); if (ret) { @@ -1144,7 +1031,6 @@ fail_csi_cfg: fail_power_on: power_down(sd); dev_err(&client->dev, "sensor power-gating failed\n"); -fail_power_off: mutex_unlock(&dev->input_lock); return ret; } @@ -1155,7 +1041,7 @@ static int ov2680_g_frame_interval(struct v4l2_subdev *sd, struct ov2680_device *dev = to_ov2680_sensor(sd); interval->interval.numerator = 1; - interval->interval.denominator = ov2680_res[dev->fmt_idx].fps; + interval->interval.denominator = dev->res->fps; return 0; } @@ -1177,13 +1063,33 @@ static int ov2680_enum_frame_size(struct v4l2_subdev *sd, { int index = fse->index; - if (index >= N_RES) + if (index >= N_RES_PREVIEW) + return -EINVAL; + + fse->min_width = ov2680_res_preview[index].width; + fse->min_height = ov2680_res_preview[index].height; + fse->max_width = ov2680_res_preview[index].width; + fse->max_height = ov2680_res_preview[index].height; + + return 0; +} + +static int ov2680_enum_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval_enum *fie) +{ + struct v4l2_fract fract; + + if (fie->index >= N_RES_PREVIEW || + fie->width > ov2680_res_preview[0].width || + fie->height > ov2680_res_preview[0].height || + fie->which > V4L2_SUBDEV_FORMAT_ACTIVE) return -EINVAL; - fse->min_width = ov2680_res[index].width; - fse->min_height = ov2680_res[index].height; - fse->max_width = ov2680_res[index].width; - fse->max_height = ov2680_res[index].height; + fract.denominator = ov2680_res_preview[fie->index].fps; + fract.numerator = 1; + + fie->interval = fract; return 0; } @@ -1193,7 +1099,7 @@ static int ov2680_g_skip_frames(struct v4l2_subdev *sd, u32 *frames) struct ov2680_device *dev = to_ov2680_sensor(sd); mutex_lock(&dev->input_lock); - *frames = ov2680_res[dev->fmt_idx].skip_frames; + *frames = dev->res->skip_frames; mutex_unlock(&dev->input_lock); return 0; @@ -1216,6 +1122,7 @@ static const struct v4l2_subdev_core_ops ov2680_core_ops = { static const struct v4l2_subdev_pad_ops ov2680_pad_ops = { .enum_mbus_code = ov2680_enum_mbus_code, .enum_frame_size = ov2680_enum_frame_size, + .enum_frame_interval = ov2680_enum_frame_interval, .get_fmt = ov2680_get_fmt, .set_fmt = ov2680_set_fmt, }; @@ -1227,7 +1134,7 @@ static const struct v4l2_subdev_ops ov2680_ops = { .sensor = &ov2680_sensor_ops, }; -static int ov2680_remove(struct i2c_client *client) +static void ov2680_remove(struct i2c_client *client) { struct v4l2_subdev *sd = i2c_get_clientdata(client); struct ov2680_device *dev = to_ov2680_sensor(sd); @@ -1240,8 +1147,6 @@ static int ov2680_remove(struct i2c_client *client) media_entity_cleanup(&dev->sd.entity); v4l2_ctrl_handler_free(&dev->ctrl_handler); kfree(dev); - - return 0; } static int ov2680_probe(struct i2c_client *client) @@ -1257,7 +1162,9 @@ static int ov2680_probe(struct i2c_client *client) mutex_init(&dev->input_lock); - dev->fmt_idx = 0; + dev->res = &ov2680_res_preview[0]; + dev->exposure = dev->res->lines_per_frame - OV2680_INTEGRATION_TIME_MARGIN; + dev->gain = 250; /* 0-2047 */ v4l2_i2c_subdev_init(&dev->sd, client, &ov2680_ops); pdata = gmin_camera_platform_data(&dev->sd, @@ -1278,7 +1185,6 @@ static int ov2680_probe(struct i2c_client *client) dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; dev->pad.flags = MEDIA_PAD_FL_SOURCE; - dev->format.code = MEDIA_BUS_FMT_SBGGR10_1X10; dev->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; ret = v4l2_ctrl_handler_init(&dev->ctrl_handler, diff --git a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c index 90d0871a78a3..887b6f99f6ca 100644 --- a/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c +++ b/drivers/staging/media/atomisp/i2c/atomisp-ov2722.c @@ -557,7 +557,7 @@ static int ov2722_g_volatile_ctrl(struct v4l2_ctrl *ctrl) ret = ov2722_g_fnumber_range(&dev->sd, &ctrl->val); break; case V4L2_CID_LINK_FREQ: - val = ov2722_res[dev->fmt_idx].mipi_freq; + val = dev->res->mipi_freq; if (val == 0) return -EINVAL; @@ -782,76 +782,6 @@ static int ov2722_s_power(struct v4l2_subdev *sd, int on) return ret; } -/* - * distance - calculate the distance - * @res: resolution - * @w: width - * @h: height - * - * Get the gap between resolution and w/h. - * res->width/height smaller than w/h wouldn't be considered. - * Returns the value of gap or -1 if fail. - */ -#define LARGEST_ALLOWED_RATIO_MISMATCH 800 -static int distance(struct ov2722_resolution *res, u32 w, u32 h) -{ - unsigned int w_ratio = (res->width << 13) / w; - unsigned int h_ratio; - int match; - - if (h == 0) - return -1; - h_ratio = (res->height << 13) / h; - if (h_ratio == 0) - return -1; - match = abs(((w_ratio << 13) / h_ratio) - 8192); - - if ((w_ratio < 8192) || (h_ratio < 8192) || - (match > LARGEST_ALLOWED_RATIO_MISMATCH)) - return -1; - - return w_ratio + h_ratio; -} - -/* Return the nearest higher resolution index */ -static int nearest_resolution_index(int w, int h) -{ - int i; - int idx = -1; - int dist; - int min_dist = INT_MAX; - struct ov2722_resolution *tmp_res = NULL; - - for (i = 0; i < N_RES; i++) { - tmp_res = &ov2722_res[i]; - dist = distance(tmp_res, w, h); - if (dist == -1) - continue; - if (dist < min_dist) { - min_dist = dist; - idx = i; - } - } - - return idx; -} - -static int get_resolution_index(int w, int h) -{ - int i; - - for (i = 0; i < N_RES; i++) { - if (w != ov2722_res[i].width) - continue; - if (h != ov2722_res[i].height) - continue; - - return i; - } - - return -1; -} - /* TODO: remove it. */ static int startup(struct v4l2_subdev *sd) { @@ -866,7 +796,7 @@ static int startup(struct v4l2_subdev *sd) return ret; } - ret = ov2722_write_reg_array(client, ov2722_res[dev->fmt_idx].regs); + ret = ov2722_write_reg_array(client, dev->res->regs); if (ret) { dev_err(&client->dev, "ov2722 write register err.\n"); return ret; @@ -882,9 +812,9 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt = &format->format; struct ov2722_device *dev = to_ov2722_sensor(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov2722_resolution *res; struct camera_mipi_info *ov2722_info = NULL; int ret = 0; - int idx; if (format->pad) return -EINVAL; @@ -895,15 +825,16 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd, return -EINVAL; mutex_lock(&dev->input_lock); - idx = nearest_resolution_index(fmt->width, fmt->height); - if (idx == -1) { - /* return the largest resolution */ - fmt->width = ov2722_res[N_RES - 1].width; - fmt->height = ov2722_res[N_RES - 1].height; - } else { - fmt->width = ov2722_res[idx].width; - fmt->height = ov2722_res[idx].height; - } + res = v4l2_find_nearest_size(ov2722_res_preview, + ARRAY_SIZE(ov2722_res_preview), width, + height, fmt->width, fmt->height); + if (!res) + res = &ov2722_res_preview[N_RES - 1]; + + fmt->width = res->width; + fmt->height = res->height; + dev->res = res; + fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; if (format->which == V4L2_SUBDEV_FORMAT_TRY) { sd_state->pads->try_fmt = *fmt; @@ -911,15 +842,9 @@ static int ov2722_set_fmt(struct v4l2_subdev *sd, |