flexcop-usb.c (d754ed2821fd9675d203cb73c4afcd593e28b7d0) flexcop-usb.c (b178aa6f333b07bda0548d7e45085660a112414d)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
4 * flexcop-usb.c - covers the USB part
5 * see flexcop.c for copyright information
6 */
7#define FC_LOG_PREFIX "flexcop_usb"
8#include "flexcop-usb.h"

--- 165 unchanged lines hidden (view full) ---

174#define bytes_left_to_read_on_page(paddr, buflen) \
175 ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \
176 ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)))
177
178static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,
179 flexcop_usb_request_t req, flexcop_usb_mem_page_t page_start,
180 u32 addr, int extended, u8 *buf, u32 len)
181{
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
4 * flexcop-usb.c - covers the USB part
5 * see flexcop.c for copyright information
6 */
7#define FC_LOG_PREFIX "flexcop_usb"
8#include "flexcop-usb.h"

--- 165 unchanged lines hidden (view full) ---

174#define bytes_left_to_read_on_page(paddr, buflen) \
175 ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \
176 ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)))
177
178static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,
179 flexcop_usb_request_t req, flexcop_usb_mem_page_t page_start,
180 u32 addr, int extended, u8 *buf, u32 len)
181{
182 int i, ret = 0;
182 int ret = 0;
183 u16 wMax;
184 u32 pagechunk = 0;
185
186 switch (req) {
187 case B2C2_USB_READ_V8_MEM:
188 wMax = USB_MEM_READ_MAX;
189 break;
190 case B2C2_USB_WRITE_V8_MEM:
191 wMax = USB_MEM_WRITE_MAX;
192 break;
193 case B2C2_USB_FLASH_BLOCK:
194 wMax = USB_FLASH_MAX;
195 break;
196 default:
197 return -EINVAL;
198 }
183 u16 wMax;
184 u32 pagechunk = 0;
185
186 switch (req) {
187 case B2C2_USB_READ_V8_MEM:
188 wMax = USB_MEM_READ_MAX;
189 break;
190 case B2C2_USB_WRITE_V8_MEM:
191 wMax = USB_MEM_WRITE_MAX;
192 break;
193 case B2C2_USB_FLASH_BLOCK:
194 wMax = USB_FLASH_MAX;
195 break;
196 default:
197 return -EINVAL;
198 }
199 for (i = 0; i < len;) {
199 while (len) {
200 pagechunk = min(wMax, bytes_left_to_read_on_page(addr, len));
201 deb_info("%x\n",
202 (addr & V8_MEMORY_PAGE_MASK) |
203 (V8_MEMORY_EXTENDED*extended));
204
205 ret = flexcop_usb_v8_memory_req(fc_usb, req,
206 page_start + (addr / V8_MEMORY_PAGE_SIZE),
207 (addr & V8_MEMORY_PAGE_MASK) |
208 (V8_MEMORY_EXTENDED*extended),
200 pagechunk = min(wMax, bytes_left_to_read_on_page(addr, len));
201 deb_info("%x\n",
202 (addr & V8_MEMORY_PAGE_MASK) |
203 (V8_MEMORY_EXTENDED*extended));
204
205 ret = flexcop_usb_v8_memory_req(fc_usb, req,
206 page_start + (addr / V8_MEMORY_PAGE_SIZE),
207 (addr & V8_MEMORY_PAGE_MASK) |
208 (V8_MEMORY_EXTENDED*extended),
209 &buf[i], pagechunk);
209 buf, pagechunk);
210
211 if (ret < 0)
212 return ret;
213 addr += pagechunk;
210
211 if (ret < 0)
212 return ret;
213 addr += pagechunk;
214 buf += pagechunk;
214 len -= pagechunk;
215 }
216 return 0;
217}
218
219static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended)
220{
221 return flexcop_usb_memory_req(fc->bus_specific, B2C2_USB_READ_V8_MEM,

--- 415 unchanged lines hidden ---
215 len -= pagechunk;
216 }
217 return 0;
218}
219
220static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended)
221{
222 return flexcop_usb_memory_req(fc->bus_specific, B2C2_USB_READ_V8_MEM,

--- 415 unchanged lines hidden ---