186d7f5d3SJohn Marino /*
286d7f5d3SJohn Marino * Copyright (c) 2003, 2004
386d7f5d3SJohn Marino * John Wehle <john@feith.com>. All rights reserved.
486d7f5d3SJohn Marino *
586d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without
686d7f5d3SJohn Marino * modification, are permitted provided that the following conditions
786d7f5d3SJohn Marino * are met:
886d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright
986d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer.
1086d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
1186d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the
1286d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution.
1386d7f5d3SJohn Marino * 3. All advertising materials mentioning features or use of this software
1486d7f5d3SJohn Marino * must display the following acknowledgement:
1586d7f5d3SJohn Marino * This product includes software developed by John Wehle.
1686d7f5d3SJohn Marino * 4. The name of the author may not be used to endorse or promote products
1786d7f5d3SJohn Marino * derived from this software without specific prior written permission.
1886d7f5d3SJohn Marino *
1986d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2086d7f5d3SJohn Marino * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2186d7f5d3SJohn Marino * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2286d7f5d3SJohn Marino * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2386d7f5d3SJohn Marino * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2486d7f5d3SJohn Marino * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2586d7f5d3SJohn Marino * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2686d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2786d7f5d3SJohn Marino * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2886d7f5d3SJohn Marino * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2986d7f5d3SJohn Marino * POSSIBILITY OF SUCH DAMAGE.
3086d7f5d3SJohn Marino */
3186d7f5d3SJohn Marino
3286d7f5d3SJohn Marino /*
3386d7f5d3SJohn Marino * Infrared remote routines for the Conexant MPEG-2 Codec driver.
3486d7f5d3SJohn Marino *
3586d7f5d3SJohn Marino * Ideally these routines should be implemented as a separate
3686d7f5d3SJohn Marino * driver which has a generic infrared remote interface so that
3786d7f5d3SJohn Marino * it's not necessary for each multimedia driver to re-invent
3886d7f5d3SJohn Marino * the wheel.
3986d7f5d3SJohn Marino */
4086d7f5d3SJohn Marino
4186d7f5d3SJohn Marino
4286d7f5d3SJohn Marino #include <sys/param.h>
4386d7f5d3SJohn Marino #include <sys/systm.h>
4486d7f5d3SJohn Marino #include <sys/conf.h>
4586d7f5d3SJohn Marino #include <sys/uio.h>
4686d7f5d3SJohn Marino #include <sys/kernel.h>
4786d7f5d3SJohn Marino #include <sys/poll.h>
4886d7f5d3SJohn Marino #include <sys/select.h>
4986d7f5d3SJohn Marino #include <sys/resource.h>
5086d7f5d3SJohn Marino #include <sys/bus.h>
5186d7f5d3SJohn Marino #include <sys/rman.h>
5286d7f5d3SJohn Marino
5386d7f5d3SJohn Marino #include <machine/clock.h>
5486d7f5d3SJohn Marino
5586d7f5d3SJohn Marino #include <dev/video/cxm/cxm.h>
5686d7f5d3SJohn Marino
5786d7f5d3SJohn Marino #include <bus/iicbus/iiconf.h>
5886d7f5d3SJohn Marino #include <bus/iicbus/iicbus.h>
5986d7f5d3SJohn Marino
6086d7f5d3SJohn Marino #include "iicbb_if.h"
6186d7f5d3SJohn Marino
6286d7f5d3SJohn Marino
6386d7f5d3SJohn Marino static int
cxm_ir_read(device_t iicbus,int i2c_addr,char * buf,int len)6486d7f5d3SJohn Marino cxm_ir_read(device_t iicbus, int i2c_addr, char *buf, int len)
6586d7f5d3SJohn Marino {
6686d7f5d3SJohn Marino int received;
6786d7f5d3SJohn Marino
6886d7f5d3SJohn Marino if (iicbus_start(iicbus, i2c_addr + 1, CXM_I2C_TIMEOUT) != 0)
6986d7f5d3SJohn Marino return -1;
7086d7f5d3SJohn Marino
7186d7f5d3SJohn Marino if (iicbus_read(iicbus, buf, len, &received, IIC_LAST_READ, 0) != 0)
7286d7f5d3SJohn Marino goto fail;
7386d7f5d3SJohn Marino
7486d7f5d3SJohn Marino iicbus_stop(iicbus);
7586d7f5d3SJohn Marino
7686d7f5d3SJohn Marino return received;
7786d7f5d3SJohn Marino
7886d7f5d3SJohn Marino fail:
7986d7f5d3SJohn Marino iicbus_stop(iicbus);
8086d7f5d3SJohn Marino return -1;
8186d7f5d3SJohn Marino }
8286d7f5d3SJohn Marino
8386d7f5d3SJohn Marino
8486d7f5d3SJohn Marino int
cxm_ir_init(struct cxm_softc * sc)8586d7f5d3SJohn Marino cxm_ir_init(struct cxm_softc *sc)
8686d7f5d3SJohn Marino {
8786d7f5d3SJohn Marino unsigned char key[1];
8886d7f5d3SJohn Marino
8986d7f5d3SJohn Marino if (cxm_ir_read(sc->iicbus, CXM_I2C_IR,
9086d7f5d3SJohn Marino key, sizeof(key)) != sizeof(key))
9186d7f5d3SJohn Marino return -1;
9286d7f5d3SJohn Marino
9386d7f5d3SJohn Marino device_printf(sc->dev, "IR Remote\n");
9486d7f5d3SJohn Marino
9586d7f5d3SJohn Marino return 0;
9686d7f5d3SJohn Marino }
9786d7f5d3SJohn Marino
9886d7f5d3SJohn Marino
9986d7f5d3SJohn Marino int
cxm_ir_key(struct cxm_softc * sc,char * buf,int len)10086d7f5d3SJohn Marino cxm_ir_key(struct cxm_softc *sc, char *buf, int len)
10186d7f5d3SJohn Marino {
10286d7f5d3SJohn Marino int result;
10386d7f5d3SJohn Marino
10486d7f5d3SJohn Marino result = cxm_ir_read(sc->iicbus, CXM_I2C_IR, buf, len);
10586d7f5d3SJohn Marino
10686d7f5d3SJohn Marino if (result >= 0)
10786d7f5d3SJohn Marino return result;
10886d7f5d3SJohn Marino
10986d7f5d3SJohn Marino /*
11086d7f5d3SJohn Marino * If the IR receiver didn't respond,
11186d7f5d3SJohn Marino * then wait 50 ms and try again.
11286d7f5d3SJohn Marino */
11386d7f5d3SJohn Marino
11486d7f5d3SJohn Marino tsleep(&sc->iicbus, 0, "IR", hz / 20);
11586d7f5d3SJohn Marino
11686d7f5d3SJohn Marino return cxm_ir_read(sc->iicbus, CXM_I2C_IR, buf, len);
11786d7f5d3SJohn Marino }
118