Skip to content

Commit 4afef9d

Browse files
committed
ioctl for phys io
1 parent 4a0f127 commit 4afef9d

File tree

3 files changed

+51
-69
lines changed

3 files changed

+51
-69
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ ARMDSP_NFSROOT=/arm
99

1010
# for compiling arm kernel module ================================
1111

12-
KERNELDIR = /opt/ti/linux-03.20.00.11/
13-
#KERNELDIR = /opt/hawkboard/linux-omapl1/
12+
#KERNELDIR = /opt/ti/linux-03.20.00.11/
13+
KERNELDIR = /opt/hawkboard/linux-omapl1/
1414
PWD := $(shell pwd)
1515
ARCH=arm
1616
CROSS_COMPILE=arm-none-linux-gnueabi-

armdsp.c

Lines changed: 43 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ static struct armdsp_trgbuf *trgbuf;
8282
#define MDCTL_ENABLE 0x03
8383
#define MDCTL_LRESET (1<<8)
8484

85+
/*
86+
* for these, addr must be in the range IO_PHYS..(IO_PHYS+IO_SIZE)
87+
* which is 0x01c00000 and 0x02000000
88+
* or modules "EDMA3 CC" to "McBSP1 FIFO Data"
89+
*
90+
* outside this range, must use ioremap/iounmap
91+
*/
8592
#define armdsp_readphys(addr) (readl(IO_ADDRESS(addr)))
8693
#define armdsp_writephys(val,addr) (writel(val,IO_ADDRESS(addr)))
8794

@@ -168,6 +175,9 @@ armdsp_ioctl (struct inode *inode, struct file *filp,
168175
unsigned int minor = iminor (filp->f_path.dentry->d_inode);
169176
int err = 0;
170177
uint32_t val;
178+
struct armdsp_physio physarg;
179+
void __user *argp = (void __user *)arg;
180+
uint32_t __iomem *iop;
171181

172182
switch(cmd) {
173183
case ARMDSP_IOCSTOP:
@@ -213,6 +223,39 @@ armdsp_ioctl (struct inode *inode, struct file *filp,
213223
flush_cache_all ();
214224
break;
215225

226+
case ARMDSP_IOCREADP:
227+
if (copy_from_user (&physarg, argp, sizeof physarg)) {
228+
err = -EFAULT;
229+
break;
230+
}
231+
iop = ioremap (physarg.physaddr, sizeof *iop);
232+
if (! iop) {
233+
err = -EFAULT;
234+
break;
235+
}
236+
physarg.val = *iop;
237+
iounmap (iop);
238+
239+
if (copy_to_user (argp, &physarg, sizeof physarg)) {
240+
err = -EFAULT;
241+
break;
242+
}
243+
break;
244+
245+
case ARMDSP_IOCWRITEP:
246+
if (copy_from_user (&physarg, argp, sizeof physarg)) {
247+
err = -EFAULT;
248+
break;
249+
}
250+
iop = ioremap (physarg.physaddr, sizeof *iop);
251+
if (! iop) {
252+
err = -EFAULT;
253+
break;
254+
}
255+
*iop = physarg.val;
256+
iounmap (iop);
257+
break;
258+
216259
default:
217260
err = -ENOTTY;
218261
break;
@@ -275,68 +318,6 @@ armdsp_irq (int irq, void *dev_id)
275318

276319
static int armdsp_need_cdev_del;
277320

278-
static void
279-
gpio_test (void)
280-
{
281-
uint32_t mask5, mask6, mask_other;
282-
uint32_t val;
283-
284-
printk ("\n\ngpio test\n");
285-
286-
printk ("pinmux %x = %x\n", SYSCFG0_PINMUX13,
287-
armdsp_readphys (SYSCFG0_PINMUX13));
288-
289-
val = armdsp_readphys (SYSCFG0_PINMUX13);
290-
val &= ~0xffff;
291-
val |= 0x8888;
292-
armdsp_writephys (val, SYSCFG0_PINMUX13);
293-
294-
printk ("pinmux %x = %x\n", SYSCFG0_PINMUX13,
295-
armdsp_readphys (SYSCFG0_PINMUX13));
296-
297-
298-
mask5 = 1 << 12;
299-
mask6 = 1 << 13;
300-
mask_other = (1 << 11)|(1 << 10)|(1 << 9)|(1 << 8);
301-
printk ("dir67 %x\n", armdsp_readphys (GPIO_DIR67));
302-
303-
val = armdsp_readphys (GPIO_DIR67);
304-
val &= ~(mask5 | mask6 | mask_other);
305-
armdsp_writephys (val, GPIO_DIR67);
306-
307-
printk ("dir67 %x\n", armdsp_readphys (GPIO_DIR67));
308-
309-
printk ("out67 %x\n", armdsp_readphys (GPIO_OUT_DATA67));
310-
311-
val = armdsp_readphys (GPIO_OUT_DATA67);
312-
if (1) {
313-
val |= mask5 | mask6;
314-
} else {
315-
val &= ~(mask5 | mask6);
316-
}
317-
armdsp_writephys (val, GPIO_OUT_DATA67);
318-
printk ("out67 %x\n", armdsp_readphys (GPIO_OUT_DATA67));
319-
320-
321-
val = armdsp_readphys (SYSCFG0_PINMUX11);
322-
val &= ~0xffffff00;
323-
val |= 0x88888800;
324-
armdsp_writephys (val, SYSCFG0_PINMUX11);
325-
326-
val = armdsp_readphys (SYSCFG0_PINMUX12);
327-
val &= ~0x0000ffff;
328-
val |= 0x00008888;
329-
armdsp_writephys (val, SYSCFG0_PINMUX12);
330-
331-
val = armdsp_readphys (SYSCFG0_PINMUX13);
332-
val &= ~0xffffff00;
333-
val |= 0x88888800;
334-
armdsp_writephys (val, SYSCFG0_PINMUX13);
335-
336-
}
337-
338-
339-
340321
static int __init
341322
armdsp_init (void)
342323
{
@@ -385,11 +366,6 @@ armdsp_init (void)
385366
dp->have_irq = 1;
386367
}
387368

388-
389-
printk ("pinmux %x = %x\n", SYSCFG0_PINMUX13, readl (SYSCFG0_PINMUX13));
390-
391-
gpio_test ();
392-
393369
return (0);
394370

395371
cleanup:

armdsp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ struct armdsp_trgbuf {
3131
#define ARMDSP_TRGBUF_OWNER_DSP 0
3232
#define ARMDSP_TRGBUF_OWNER_ARM 1
3333

34+
struct armdsp_physio {
35+
uint32_t physaddr;
36+
uint32_t val;
37+
};
3438

3539
#define ARMDSP_IOC_MAGIC 'a'
3640
#define ARMDSP_IOCSTOP _IO(ARMDSP_IOC_MAGIC, 47)
3741
#define ARMDSP_IOCSTART _IO(ARMDSP_IOC_MAGIC, 48)
3842
#define ARMDSP_IOCWMB _IO(ARMDSP_IOC_MAGIC, 49)
3943
#define ARMDSP_IOCRMB _IO(ARMDSP_IOC_MAGIC, 50)
44+
#define ARMDSP_IOCREADP _IOWR(ARMDSP_IOC_MAGIC, 51, struct armdsp_physio)
45+
#define ARMDSP_IOCWRITEP _IOW(ARMDSP_IOC_MAGIC, 52, struct armdsp_physio)
4046

4147
#ifndef __KERNEL__
4248
char *armdsp_init (int cold_boot);

0 commit comments

Comments
 (0)