diff options
-rw-r--r-- | drivers/media/usb/em28xx/em28xx-i2c.c | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c index 44533e4574ff..c508c1297a26 100644 --- a/drivers/media/usb/em28xx/em28xx-i2c.c +++ b/drivers/media/usb/em28xx/em28xx-i2c.c | |||
@@ -50,14 +50,18 @@ do { \ | |||
50 | } while (0) | 50 | } while (0) |
51 | 51 | ||
52 | /* | 52 | /* |
53 | * em2800_i2c_send_max4() | 53 | * em2800_i2c_send_bytes() |
54 | * send up to 4 bytes to the i2c device | 54 | * send up to 4 bytes to the em2800 i2c device |
55 | */ | 55 | */ |
56 | static int em2800_i2c_send_max4(struct em28xx *dev, u8 addr, u8 *buf, u16 len) | 56 | static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) |
57 | { | 57 | { |
58 | int ret; | 58 | int ret; |
59 | int write_timeout; | 59 | int write_timeout; |
60 | u8 b2[6]; | 60 | u8 b2[6]; |
61 | |||
62 | if (len < 1 || len > 4) | ||
63 | return -EOPNOTSUPP; | ||
64 | |||
61 | BUG_ON(len < 1 || len > 4); | 65 | BUG_ON(len < 1 || len > 4); |
62 | b2[5] = 0x80 + len - 1; | 66 | b2[5] = 0x80 + len - 1; |
63 | b2[4] = addr; | 67 | b2[4] = addr; |
@@ -86,29 +90,6 @@ static int em2800_i2c_send_max4(struct em28xx *dev, u8 addr, u8 *buf, u16 len) | |||
86 | } | 90 | } |
87 | 91 | ||
88 | /* | 92 | /* |
89 | * em2800_i2c_send_bytes() | ||
90 | */ | ||
91 | static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) | ||
92 | { | ||
93 | u8 *bufPtr = buf; | ||
94 | int ret; | ||
95 | int wrcount = 0; | ||
96 | int count; | ||
97 | int maxLen = 4; | ||
98 | while (len > 0) { | ||
99 | count = (len > maxLen) ? maxLen : len; | ||
100 | ret = em2800_i2c_send_max4(dev, addr, bufPtr, count); | ||
101 | if (ret > 0) { | ||
102 | len -= count; | ||
103 | bufPtr += count; | ||
104 | wrcount += count; | ||
105 | } else | ||
106 | return (ret < 0) ? ret : -EFAULT; | ||
107 | } | ||
108 | return wrcount; | ||
109 | } | ||
110 | |||
111 | /* | ||
112 | * em2800_i2c_check_for_device() | 93 | * em2800_i2c_check_for_device() |
113 | * check if there is a i2c_device at the supplied address | 94 | * check if there is a i2c_device at the supplied address |
114 | */ | 95 | */ |
@@ -150,6 +131,10 @@ static int em2800_i2c_check_for_device(struct em28xx *dev, u8 addr) | |||
150 | static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) | 131 | static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len) |
151 | { | 132 | { |
152 | int ret; | 133 | int ret; |
134 | |||
135 | if (len < 1 || len > 4) | ||
136 | return -EOPNOTSUPP; | ||
137 | |||
153 | /* check for the device and set i2c read address */ | 138 | /* check for the device and set i2c read address */ |
154 | ret = em2800_i2c_check_for_device(dev, addr); | 139 | ret = em2800_i2c_check_for_device(dev, addr); |
155 | if (ret) { | 140 | if (ret) { |
@@ -176,6 +161,9 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf, | |||
176 | int wrcount = 0; | 161 | int wrcount = 0; |
177 | int write_timeout, ret; | 162 | int write_timeout, ret; |
178 | 163 | ||
164 | if (len < 1 || len > 64) | ||
165 | return -EOPNOTSUPP; | ||
166 | |||
179 | wrcount = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len); | 167 | wrcount = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len); |
180 | 168 | ||
181 | /* Seems to be required after a write */ | 169 | /* Seems to be required after a write */ |
@@ -197,6 +185,10 @@ static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf, | |||
197 | static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len) | 185 | static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len) |
198 | { | 186 | { |
199 | int ret; | 187 | int ret; |
188 | |||
189 | if (len < 1 || len > 64) | ||
190 | return -EOPNOTSUPP; | ||
191 | |||
200 | ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len); | 192 | ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len); |
201 | if (ret < 0) { | 193 | if (ret < 0) { |
202 | em28xx_warn("reading i2c device failed (error=%i)\n", ret); | 194 | em28xx_warn("reading i2c device failed (error=%i)\n", ret); |