Linux Audio

Check our new training course

Loading...
v4.17
  1/*
  2 * This file is subject to the terms and conditions of the GNU General Public
  3 * License.  See the file "COPYING" in the main directory of this archive
  4 * for more details.
  5 *
  6 * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved.
  7 * Copyright (C) 2013 Imagination Technologies Ltd.
  8 */
  9#include <linux/device.h>
 10#include <linux/fs.h>
 11#include <linux/err.h>
 12#include <linux/wait.h>
 13#include <linux/sched.h>
 14#include <linux/interrupt.h>
 15#include <linux/irq.h>
 16
 17#include <asm/mips_mt.h>
 18#include <asm/vpe.h>
 19#include <asm/rtlx.h>
 20
 21static int major;
 22
 23static void rtlx_dispatch(void)
 24{
 25	if (read_c0_cause() & read_c0_status() & C_SW0)
 26		do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ);
 27}
 28
 29/*
 30 * Interrupt handler may be called before rtlx_init has otherwise had
 31 * a chance to run.
 32 */
 33static irqreturn_t rtlx_interrupt(int irq, void *dev_id)
 34{
 35	unsigned int vpeflags;
 36	unsigned long flags;
 37	int i;
 38
 
 39	local_irq_save(flags);
 40	vpeflags = dvpe();
 41	set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ);
 42	irq_enable_hazard();
 43	evpe(vpeflags);
 44	local_irq_restore(flags);
 45
 46	for (i = 0; i < RTLX_CHANNELS; i++) {
 47		wake_up(&channel_wqs[i].lx_queue);
 48		wake_up(&channel_wqs[i].rt_queue);
 49	}
 50
 51	return IRQ_HANDLED;
 52}
 53
 54static struct irqaction rtlx_irq = {
 55	.handler	= rtlx_interrupt,
 56	.name		= "RTLX",
 57};
 58
 59static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ;
 60
 61void _interrupt_sp(void)
 62{
 63	unsigned long flags;
 64
 65	local_irq_save(flags);
 66	dvpe();
 67	settc(1);
 68	write_vpe_c0_cause(read_vpe_c0_cause() | C_SW0);
 69	evpe(EVPE_ENABLE);
 70	local_irq_restore(flags);
 71}
 72
 73int __init rtlx_module_init(void)
 74{
 75	struct device *dev;
 76	int i, err;
 77
 78	if (!cpu_has_mipsmt) {
 79		pr_warn("VPE loader: not a MIPS MT capable processor\n");
 80		return -ENODEV;
 81	}
 82
 83	if (aprp_cpu_index() == 0) {
 84		pr_warn("No TCs reserved for AP/SP, not initializing RTLX.\n"
 85			"Pass maxtcs=<n> argument as kernel argument\n");
 86
 87		return -ENODEV;
 88	}
 89
 90	major = register_chrdev(0, RTLX_MODULE_NAME, &rtlx_fops);
 91	if (major < 0) {
 92		pr_err("rtlx_module_init: unable to register device\n");
 93		return major;
 94	}
 95
 96	/* initialise the wait queues */
 97	for (i = 0; i < RTLX_CHANNELS; i++) {
 98		init_waitqueue_head(&channel_wqs[i].rt_queue);
 99		init_waitqueue_head(&channel_wqs[i].lx_queue);
100		atomic_set(&channel_wqs[i].in_open, 0);
101		mutex_init(&channel_wqs[i].mutex);
102
103		dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
104				    "%s%d", RTLX_MODULE_NAME, i);
105		if (IS_ERR(dev)) {
106			while (i--)
107				device_destroy(mt_class, MKDEV(major, i));
108
109			err = PTR_ERR(dev);
110			goto out_chrdev;
111		}
112	}
113
114	/* set up notifiers */
115	rtlx_notify.start = rtlx_starting;
116	rtlx_notify.stop = rtlx_stopping;
117	vpe_notify(aprp_cpu_index(), &rtlx_notify);
118
119	if (cpu_has_vint) {
120		aprp_hook = rtlx_dispatch;
121	} else {
122		pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
123		err = -ENODEV;
124		goto out_class;
125	}
126
127	rtlx_irq.dev_id = rtlx;
128	err = setup_irq(rtlx_irq_num, &rtlx_irq);
129	if (err)
130		goto out_class;
131
132	return 0;
133
134out_class:
135	for (i = 0; i < RTLX_CHANNELS; i++)
136		device_destroy(mt_class, MKDEV(major, i));
137out_chrdev:
138	unregister_chrdev(major, RTLX_MODULE_NAME);
139
140	return err;
141}
142
143void __exit rtlx_module_exit(void)
144{
145	int i;
146
147	for (i = 0; i < RTLX_CHANNELS; i++)
148		device_destroy(mt_class, MKDEV(major, i));
149
150	unregister_chrdev(major, RTLX_MODULE_NAME);
151
152	aprp_hook = NULL;
153}
v3.15
  1/*
  2 * This file is subject to the terms and conditions of the GNU General Public
  3 * License.  See the file "COPYING" in the main directory of this archive
  4 * for more details.
  5 *
  6 * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved.
  7 * Copyright (C) 2013 Imagination Technologies Ltd.
  8 */
  9#include <linux/device.h>
 10#include <linux/fs.h>
 11#include <linux/err.h>
 12#include <linux/wait.h>
 13#include <linux/sched.h>
 14#include <linux/interrupt.h>
 15#include <linux/irq.h>
 16
 17#include <asm/mips_mt.h>
 18#include <asm/vpe.h>
 19#include <asm/rtlx.h>
 20
 21static int major;
 22
 23static void rtlx_dispatch(void)
 24{
 25	if (read_c0_cause() & read_c0_status() & C_SW0)
 26		do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ);
 27}
 28
 29/*
 30 * Interrupt handler may be called before rtlx_init has otherwise had
 31 * a chance to run.
 32 */
 33static irqreturn_t rtlx_interrupt(int irq, void *dev_id)
 34{
 35	unsigned int vpeflags;
 36	unsigned long flags;
 37	int i;
 38
 39	/* Ought not to be strictly necessary for SMTC builds */
 40	local_irq_save(flags);
 41	vpeflags = dvpe();
 42	set_c0_status(0x100 << MIPS_CPU_RTLX_IRQ);
 43	irq_enable_hazard();
 44	evpe(vpeflags);
 45	local_irq_restore(flags);
 46
 47	for (i = 0; i < RTLX_CHANNELS; i++) {
 48		wake_up(&channel_wqs[i].lx_queue);
 49		wake_up(&channel_wqs[i].rt_queue);
 50	}
 51
 52	return IRQ_HANDLED;
 53}
 54
 55static struct irqaction rtlx_irq = {
 56	.handler	= rtlx_interrupt,
 57	.name		= "RTLX",
 58};
 59
 60static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ;
 61
 62void _interrupt_sp(void)
 63{
 64	unsigned long flags;
 65
 66	local_irq_save(flags);
 67	dvpe();
 68	settc(1);
 69	write_vpe_c0_cause(read_vpe_c0_cause() | C_SW0);
 70	evpe(EVPE_ENABLE);
 71	local_irq_restore(flags);
 72}
 73
 74int __init rtlx_module_init(void)
 75{
 76	struct device *dev;
 77	int i, err;
 78
 79	if (!cpu_has_mipsmt) {
 80		pr_warn("VPE loader: not a MIPS MT capable processor\n");
 81		return -ENODEV;
 82	}
 83
 84	if (aprp_cpu_index() == 0) {
 85		pr_warn("No TCs reserved for AP/SP, not initializing RTLX.\n"
 86			"Pass maxtcs=<n> argument as kernel argument\n");
 87
 88		return -ENODEV;
 89	}
 90
 91	major = register_chrdev(0, RTLX_MODULE_NAME, &rtlx_fops);
 92	if (major < 0) {
 93		pr_err("rtlx_module_init: unable to register device\n");
 94		return major;
 95	}
 96
 97	/* initialise the wait queues */
 98	for (i = 0; i < RTLX_CHANNELS; i++) {
 99		init_waitqueue_head(&channel_wqs[i].rt_queue);
100		init_waitqueue_head(&channel_wqs[i].lx_queue);
101		atomic_set(&channel_wqs[i].in_open, 0);
102		mutex_init(&channel_wqs[i].mutex);
103
104		dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
105				    "%s%d", RTLX_MODULE_NAME, i);
106		if (IS_ERR(dev)) {
 
 
 
107			err = PTR_ERR(dev);
108			goto out_chrdev;
109		}
110	}
111
112	/* set up notifiers */
113	rtlx_notify.start = rtlx_starting;
114	rtlx_notify.stop = rtlx_stopping;
115	vpe_notify(aprp_cpu_index(), &rtlx_notify);
116
117	if (cpu_has_vint) {
118		aprp_hook = rtlx_dispatch;
119	} else {
120		pr_err("APRP RTLX init on non-vectored-interrupt processor\n");
121		err = -ENODEV;
122		goto out_class;
123	}
124
125	rtlx_irq.dev_id = rtlx;
126	err = setup_irq(rtlx_irq_num, &rtlx_irq);
127	if (err)
128		goto out_class;
129
130	return 0;
131
132out_class:
133	for (i = 0; i < RTLX_CHANNELS; i++)
134		device_destroy(mt_class, MKDEV(major, i));
135out_chrdev:
136	unregister_chrdev(major, RTLX_MODULE_NAME);
137
138	return err;
139}
140
141void __exit rtlx_module_exit(void)
142{
143	int i;
144
145	for (i = 0; i < RTLX_CHANNELS; i++)
146		device_destroy(mt_class, MKDEV(major, i));
147
148	unregister_chrdev(major, RTLX_MODULE_NAME);
149
150	aprp_hook = NULL;
151}