Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | * vp27smpx - driver version 0.0.1 |
| 3 | * |
| 4 | * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> |
| 5 | * |
Kazuhiko Kawakami | da80be2 | 2007-08-18 11:39:28 -0300 | [diff] [blame] | 6 | * Based on a tvaudio patch from Takahiro Adachi <tadachi@tadachi-net.com> |
| 7 | * and Kazuhiko Kawakami <kazz-0@mail.goo.ne.jp> |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/types.h> |
| 26 | #include <linux/ioctl.h> |
| 27 | #include <asm/uaccess.h> |
| 28 | #include <linux/i2c.h> |
| 29 | #include <linux/i2c-id.h> |
| 30 | #include <linux/videodev.h> |
| 31 | #include <media/v4l2-common.h> |
| 32 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | f69d419 | 2007-12-12 07:24:27 -0300 | [diff] [blame] | 33 | #include <media/v4l2-i2c-drv.h> |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 34 | |
| 35 | MODULE_DESCRIPTION("vp27smpx driver"); |
| 36 | MODULE_AUTHOR("Hans Verkuil"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 39 | |
| 40 | /* ----------------------------------------------------------------------- */ |
| 41 | |
| 42 | struct vp27smpx_state { |
| 43 | int radio; |
| 44 | u32 audmode; |
| 45 | }; |
| 46 | |
| 47 | static void vp27smpx_set_audmode(struct i2c_client *client, u32 audmode) |
| 48 | { |
| 49 | struct vp27smpx_state *state = i2c_get_clientdata(client); |
| 50 | u8 data[3] = { 0x00, 0x00, 0x04 }; |
| 51 | |
| 52 | switch (audmode) { |
Hans Verkuil | 35df38c | 2007-12-12 07:40:54 -0300 | [diff] [blame] | 53 | case V4L2_TUNER_MODE_MONO: |
| 54 | case V4L2_TUNER_MODE_LANG1: |
| 55 | break; |
| 56 | case V4L2_TUNER_MODE_STEREO: |
| 57 | case V4L2_TUNER_MODE_LANG1_LANG2: |
| 58 | data[1] = 0x01; |
| 59 | break; |
| 60 | case V4L2_TUNER_MODE_LANG2: |
| 61 | data[1] = 0x02; |
| 62 | break; |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 63 | } |
| 64 | |
Hans Verkuil | 35df38c | 2007-12-12 07:40:54 -0300 | [diff] [blame] | 65 | if (i2c_master_send(client, data, sizeof(data)) != sizeof(data)) |
| 66 | v4l_err(client, "%s: I/O error setting audmode\n", |
| 67 | client->name); |
| 68 | else |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 69 | state->audmode = audmode; |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 70 | } |
| 71 | |
Hans Verkuil | 35df38c | 2007-12-12 07:40:54 -0300 | [diff] [blame] | 72 | static int vp27smpx_command(struct i2c_client *client, unsigned cmd, void *arg) |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 73 | { |
| 74 | struct vp27smpx_state *state = i2c_get_clientdata(client); |
| 75 | struct v4l2_tuner *vt = arg; |
| 76 | |
| 77 | switch (cmd) { |
| 78 | case AUDC_SET_RADIO: |
| 79 | state->radio = 1; |
| 80 | break; |
| 81 | |
| 82 | case VIDIOC_S_STD: |
| 83 | state->radio = 0; |
| 84 | break; |
| 85 | |
| 86 | case VIDIOC_S_TUNER: |
| 87 | if (!state->radio) |
| 88 | vp27smpx_set_audmode(client, vt->audmode); |
| 89 | break; |
| 90 | |
| 91 | case VIDIOC_G_TUNER: |
| 92 | if (state->radio) |
| 93 | break; |
| 94 | vt->audmode = state->audmode; |
| 95 | vt->capability = V4L2_TUNER_CAP_STEREO | |
| 96 | V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; |
| 97 | vt->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 98 | break; |
| 99 | |
| 100 | case VIDIOC_G_CHIP_IDENT: |
Hans Verkuil | 35df38c | 2007-12-12 07:40:54 -0300 | [diff] [blame] | 101 | return v4l2_chip_ident_i2c_client(client, arg, |
| 102 | V4L2_IDENT_VP27SMPX, 0); |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 103 | |
| 104 | case VIDIOC_LOG_STATUS: |
| 105 | v4l_info(client, "Audio Mode: %u%s\n", state->audmode, |
| 106 | state->radio ? " (Radio)" : ""); |
| 107 | break; |
| 108 | |
| 109 | default: |
| 110 | return -EINVAL; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /* ----------------------------------------------------------------------- */ |
| 116 | |
| 117 | /* i2c implementation */ |
| 118 | |
| 119 | /* |
| 120 | * Generic i2c probe |
| 121 | * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' |
| 122 | */ |
| 123 | |
Hans Verkuil | 45eea27 | 2007-09-13 11:11:44 -0300 | [diff] [blame] | 124 | static int vp27smpx_probe(struct i2c_client *client) |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 125 | { |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 126 | struct vp27smpx_state *state; |
| 127 | |
| 128 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | 45eea27 | 2007-09-13 11:11:44 -0300 | [diff] [blame] | 129 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
Hans Verkuil | 188f345 | 2007-09-16 10:47:15 -0300 | [diff] [blame] | 130 | return -EIO; |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 131 | |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 132 | snprintf(client->name, sizeof(client->name) - 1, "vp27smpx"); |
| 133 | |
Hans Verkuil | 35df38c | 2007-12-12 07:40:54 -0300 | [diff] [blame] | 134 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 135 | client->addr << 1, client->adapter->name); |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 136 | |
| 137 | state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL); |
Hans Verkuil | 35df38c | 2007-12-12 07:40:54 -0300 | [diff] [blame] | 138 | if (state == NULL) |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 139 | return -ENOMEM; |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 140 | state->audmode = V4L2_TUNER_MODE_STEREO; |
| 141 | i2c_set_clientdata(client, state); |
| 142 | |
| 143 | /* initialize vp27smpx */ |
| 144 | vp27smpx_set_audmode(client, state->audmode); |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
Hans Verkuil | 45eea27 | 2007-09-13 11:11:44 -0300 | [diff] [blame] | 148 | static int vp27smpx_remove(struct i2c_client *client) |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 149 | { |
Hans Verkuil | 45eea27 | 2007-09-13 11:11:44 -0300 | [diff] [blame] | 150 | kfree(i2c_get_clientdata(client)); |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* ----------------------------------------------------------------------- */ |
| 155 | |
Hans Verkuil | 45eea27 | 2007-09-13 11:11:44 -0300 | [diff] [blame] | 156 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 157 | .name = "vp27smpx", |
| 158 | .driverid = I2C_DRIVERID_VP27SMPX, |
| 159 | .command = vp27smpx_command, |
| 160 | .probe = vp27smpx_probe, |
| 161 | .remove = vp27smpx_remove, |
Hans Verkuil | ac24743 | 2007-07-27 06:56:50 -0300 | [diff] [blame] | 162 | }; |
| 163 | |