Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 *  Silicon Labs C2 port Linux support for Eurotech Duramar 2150
  4 *
  5 *  Copyright (c) 2008 Rodolfo Giometti <giometti@linux.it>
  6 *  Copyright (c) 2008 Eurotech S.p.A. <info@eurotech.it>
 
 
 
 
  7 */
  8
  9#include <linux/errno.h>
 10#include <linux/init.h>
 11#include <linux/kernel.h>
 12#include <linux/module.h>
 13#include <linux/delay.h>
 14#include <linux/io.h>
 15#include <linux/ioport.h>
 16#include <linux/c2port.h>
 17
 18#define DATA_PORT	0x325
 19#define DIR_PORT	0x326
 20#define    C2D		   (1 << 0)
 21#define    C2CK		   (1 << 1)
 22
 23static DEFINE_MUTEX(update_lock);
 24
 25/*
 26 * C2 port operations
 27 */
 28
 29static void duramar2150_c2port_access(struct c2port_device *dev, int status)
 30{
 31	u8 v;
 32
 33	mutex_lock(&update_lock);
 34
 35	v = inb(DIR_PORT);
 36
 37	/* 0 = input, 1 = output */
 38	if (status)
 39		outb(v | (C2D | C2CK), DIR_PORT);
 40	else
 41		/* When access is "off" is important that both lines are set
 42		 * as inputs or hi-impedance */
 43		outb(v & ~(C2D | C2CK), DIR_PORT);
 44
 45	mutex_unlock(&update_lock);
 46}
 47
 48static void duramar2150_c2port_c2d_dir(struct c2port_device *dev, int dir)
 49{
 50	u8 v;
 51
 52	mutex_lock(&update_lock);
 53
 54	v = inb(DIR_PORT);
 55
 56	if (dir)
 57		outb(v & ~C2D, DIR_PORT);
 58	else
 59		outb(v | C2D, DIR_PORT);
 60
 61	mutex_unlock(&update_lock);
 62}
 63
 64static int duramar2150_c2port_c2d_get(struct c2port_device *dev)
 65{
 66	return inb(DATA_PORT) & C2D;
 67}
 68
 69static void duramar2150_c2port_c2d_set(struct c2port_device *dev, int status)
 70{
 71	u8 v;
 72
 73	mutex_lock(&update_lock);
 74
 75	v = inb(DATA_PORT);
 76
 77	if (status)
 78		outb(v | C2D, DATA_PORT);
 79	else
 80		outb(v & ~C2D, DATA_PORT);
 81
 82	mutex_unlock(&update_lock);
 83}
 84
 85static void duramar2150_c2port_c2ck_set(struct c2port_device *dev, int status)
 86{
 87	u8 v;
 88
 89	mutex_lock(&update_lock);
 90
 91	v = inb(DATA_PORT);
 92
 93	if (status)
 94		outb(v | C2CK, DATA_PORT);
 95	else
 96		outb(v & ~C2CK, DATA_PORT);
 97
 98	mutex_unlock(&update_lock);
 99}
100
101static struct c2port_ops duramar2150_c2port_ops = {
102	.block_size	= 512,	/* bytes */
103	.blocks_num	= 30,	/* total flash size: 15360 bytes */
104
105	.access		= duramar2150_c2port_access,
106	.c2d_dir	= duramar2150_c2port_c2d_dir,
107	.c2d_get	= duramar2150_c2port_c2d_get,
108	.c2d_set	= duramar2150_c2port_c2d_set,
109	.c2ck_set	= duramar2150_c2port_c2ck_set,
110};
111
112static struct c2port_device *duramar2150_c2port_dev;
113
114/*
115 * Module stuff
116 */
117
118static int __init duramar2150_c2port_init(void)
119{
120	struct resource *res;
121	int ret = 0;
122
123	res = request_region(0x325, 2, "c2port");
124	if (!res)
125		return -EBUSY;
126
127	duramar2150_c2port_dev = c2port_device_register("uc",
128					&duramar2150_c2port_ops, NULL);
129	if (IS_ERR(duramar2150_c2port_dev)) {
130		ret = PTR_ERR(duramar2150_c2port_dev);
131		goto free_region;
132	}
133
134	return 0;
135
136free_region:
137	release_region(0x325, 2);
138	return ret;
139}
140
141static void __exit duramar2150_c2port_exit(void)
142{
143	/* Setup the GPIOs as input by default (access = 0) */
144	duramar2150_c2port_access(duramar2150_c2port_dev, 0);
145
146	c2port_device_unregister(duramar2150_c2port_dev);
147
148	release_region(0x325, 2);
149}
150
151module_init(duramar2150_c2port_init);
152module_exit(duramar2150_c2port_exit);
153
154MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
155MODULE_DESCRIPTION("Silicon Labs C2 port Linux support for Duramar 2150");
156MODULE_LICENSE("GPL");
v4.6
 
  1/*
  2 *  Silicon Labs C2 port Linux support for Eurotech Duramar 2150
  3 *
  4 *  Copyright (c) 2008 Rodolfo Giometti <giometti@linux.it>
  5 *  Copyright (c) 2008 Eurotech S.p.A. <info@eurotech.it>
  6 *
  7 * This program is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU General Public License version 2 as published by
  9 * the Free Software Foundation
 10 */
 11
 12#include <linux/errno.h>
 13#include <linux/init.h>
 14#include <linux/kernel.h>
 15#include <linux/module.h>
 16#include <linux/delay.h>
 17#include <linux/io.h>
 18#include <linux/ioport.h>
 19#include <linux/c2port.h>
 20
 21#define DATA_PORT	0x325
 22#define DIR_PORT	0x326
 23#define    C2D		   (1 << 0)
 24#define    C2CK		   (1 << 1)
 25
 26static DEFINE_MUTEX(update_lock);
 27
 28/*
 29 * C2 port operations
 30 */
 31
 32static void duramar2150_c2port_access(struct c2port_device *dev, int status)
 33{
 34	u8 v;
 35
 36	mutex_lock(&update_lock);
 37
 38	v = inb(DIR_PORT);
 39
 40	/* 0 = input, 1 = output */
 41	if (status)
 42		outb(v | (C2D | C2CK), DIR_PORT);
 43	else
 44		/* When access is "off" is important that both lines are set
 45		 * as inputs or hi-impedance */
 46		outb(v & ~(C2D | C2CK), DIR_PORT);
 47
 48	mutex_unlock(&update_lock);
 49}
 50
 51static void duramar2150_c2port_c2d_dir(struct c2port_device *dev, int dir)
 52{
 53	u8 v;
 54
 55	mutex_lock(&update_lock);
 56
 57	v = inb(DIR_PORT);
 58
 59	if (dir)
 60		outb(v & ~C2D, DIR_PORT);
 61	else
 62		outb(v | C2D, DIR_PORT);
 63
 64	mutex_unlock(&update_lock);
 65}
 66
 67static int duramar2150_c2port_c2d_get(struct c2port_device *dev)
 68{
 69	return inb(DATA_PORT) & C2D;
 70}
 71
 72static void duramar2150_c2port_c2d_set(struct c2port_device *dev, int status)
 73{
 74	u8 v;
 75
 76	mutex_lock(&update_lock);
 77
 78	v = inb(DATA_PORT);
 79
 80	if (status)
 81		outb(v | C2D, DATA_PORT);
 82	else
 83		outb(v & ~C2D, DATA_PORT);
 84
 85	mutex_unlock(&update_lock);
 86}
 87
 88static void duramar2150_c2port_c2ck_set(struct c2port_device *dev, int status)
 89{
 90	u8 v;
 91
 92	mutex_lock(&update_lock);
 93
 94	v = inb(DATA_PORT);
 95
 96	if (status)
 97		outb(v | C2CK, DATA_PORT);
 98	else
 99		outb(v & ~C2CK, DATA_PORT);
100
101	mutex_unlock(&update_lock);
102}
103
104static struct c2port_ops duramar2150_c2port_ops = {
105	.block_size	= 512,	/* bytes */
106	.blocks_num	= 30,	/* total flash size: 15360 bytes */
107
108	.access		= duramar2150_c2port_access,
109	.c2d_dir	= duramar2150_c2port_c2d_dir,
110	.c2d_get	= duramar2150_c2port_c2d_get,
111	.c2d_set	= duramar2150_c2port_c2d_set,
112	.c2ck_set	= duramar2150_c2port_c2ck_set,
113};
114
115static struct c2port_device *duramar2150_c2port_dev;
116
117/*
118 * Module stuff
119 */
120
121static int __init duramar2150_c2port_init(void)
122{
123	struct resource *res;
124	int ret = 0;
125
126	res = request_region(0x325, 2, "c2port");
127	if (!res)
128		return -EBUSY;
129
130	duramar2150_c2port_dev = c2port_device_register("uc",
131					&duramar2150_c2port_ops, NULL);
132	if (!duramar2150_c2port_dev) {
133		ret = -ENODEV;
134		goto free_region;
135	}
136
137	return 0;
138
139free_region:
140	release_region(0x325, 2);
141	return ret;
142}
143
144static void __exit duramar2150_c2port_exit(void)
145{
146	/* Setup the GPIOs as input by default (access = 0) */
147	duramar2150_c2port_access(duramar2150_c2port_dev, 0);
148
149	c2port_device_unregister(duramar2150_c2port_dev);
150
151	release_region(0x325, 2);
152}
153
154module_init(duramar2150_c2port_init);
155module_exit(duramar2150_c2port_exit);
156
157MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
158MODULE_DESCRIPTION("Silicon Labs C2 port Linux support for Duramar 2150");
159MODULE_LICENSE("GPL");