Skip to content

Commit e3b7472

Browse files
Markus Mayerffainelli
authored andcommitted
memory: brcmstb: dpfe: introduce DPFE API v3
Introduce code to handle DPFE API v3. We also change the driver to default to v3 by default and use API v2 only for select chips. Signed-off-by: Markus Mayer <mmayer@broadcom.com> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
1 parent 5ef108b commit e3b7472

1 file changed

Lines changed: 105 additions & 9 deletions

File tree

‎drivers/memory/brcmstb_dpfe.c‎

Lines changed: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#define DRAM_MR4_TH_OFFS_MASK 0x3
7777
#define DRAM_MR4_TUF_MASK 0x1
7878

79-
/* DRAM Vendor Offsets & Masks */
79+
/* DRAM Vendor Offsets & Masks (API v2) */
8080
#define DRAM_VENDOR_MR5 0x0
8181
#define DRAM_VENDOR_MR6 0x4
8282
#define DRAM_VENDOR_MR7 0x8
@@ -85,6 +85,15 @@
8585
#define DRAM_VENDOR_MASK 0xff
8686
#define DRAM_VENDOR_SHIFT 24 /* We need to look at byte 3 */
8787

88+
/* DRAM Information Offsets & Masks (API v3) */
89+
#define DRAM_DDR_INFO_MR4 0x0
90+
#define DRAM_DDR_INFO_MR5 0x4
91+
#define DRAM_DDR_INFO_MR6 0x8
92+
#define DRAM_DDR_INFO_MR7 0xc
93+
#define DRAM_DDR_INFO_MR8 0x10
94+
#define DRAM_DDR_INFO_ERROR 0x14
95+
#define DRAM_DDR_INFO_MASK 0xff
96+
8897
/* Reset register bits & masks */
8998
#define DCPU_RESET_SHIFT 0x0
9099
#define DCPU_RESET_MASK 0x1
@@ -121,7 +130,7 @@ enum dpfe_msg_fields {
121130
MSG_ARG_COUNT,
122131
MSG_ARG0,
123132
MSG_CHKSUM,
124-
MSG_FIELD_MAX /* Last entry */
133+
MSG_FIELD_MAX = 16 /* Max number of arguments */
125134
};
126135

127136
enum dpfe_commands {
@@ -196,6 +205,7 @@ static ssize_t show_refresh(struct device *, struct device_attribute *, char *);
196205
static ssize_t store_refresh(struct device *, struct device_attribute *,
197206
const char *, size_t);
198207
static ssize_t show_vendor(struct device *, struct device_attribute *, char *);
208+
static ssize_t show_dram(struct device *, struct device_attribute *, char *);
199209

200210
/*
201211
* Declare our attributes early, so they can be referenced in the API data
@@ -205,6 +215,7 @@ static ssize_t show_vendor(struct device *, struct device_attribute *, char *);
205215
static DEVICE_ATTR(dpfe_info, 0444, show_info, NULL);
206216
static DEVICE_ATTR(dpfe_refresh, 0644, show_refresh, store_refresh);
207217
static DEVICE_ATTR(dpfe_vendor, 0444, show_vendor, NULL);
218+
static DEVICE_ATTR(dpfe_dram, 0444, show_dram, NULL);
208219

209220
/* API v2 sysfs attributes */
210221
static struct attribute *dpfe_v2_attrs[] = {
@@ -215,6 +226,14 @@ static struct attribute *dpfe_v2_attrs[] = {
215226
};
216227
ATTRIBUTE_GROUPS(dpfe_v2);
217228

229+
/* API v3 sysfs attributes */
230+
static struct attribute *dpfe_v3_attrs[] = {
231+
&dev_attr_dpfe_info.attr,
232+
&dev_attr_dpfe_dram.attr,
233+
NULL
234+
};
235+
ATTRIBUTE_GROUPS(dpfe_v3);
236+
218237
/* API v2 firmware commands */
219238
static const struct dpfe_api dpfe_api_v2 = {
220239
.version = 2,
@@ -245,6 +264,34 @@ static const struct dpfe_api dpfe_api_v2 = {
245264
}
246265
};
247266

267+
/* API v3 firmware commands */
268+
static const struct dpfe_api dpfe_api_v3 = {
269+
.version = 3,
270+
.fw_name = NULL, /* We expect the firmware to have been downloaded! */
271+
.sysfs_attrs = dpfe_v3_groups,
272+
.command = {
273+
[DPFE_CMD_GET_INFO] = {
274+
[MSG_HEADER] = DPFE_MSG_TYPE_COMMAND,
275+
[MSG_COMMAND] = 0x0101,
276+
[MSG_ARG_COUNT] = 1,
277+
[MSG_ARG0] = 1,
278+
[MSG_CHKSUM] = 0x104,
279+
},
280+
[DPFE_CMD_GET_REFRESH] = {
281+
[MSG_HEADER] = DPFE_MSG_TYPE_COMMAND,
282+
[MSG_COMMAND] = 0x0202,
283+
[MSG_ARG_COUNT] = 0,
284+
/*
285+
* This is a bit ugly. Without arguments, the checksum
286+
* follows right after the argument count and not at
287+
* offset MSG_CHKSUM.
288+
*/
289+
[MSG_ARG0] = 0x203,
290+
},
291+
/* There's no GET_VENDOR command in API v3. */
292+
},
293+
};
294+
248295
static bool is_dcpu_enabled(void __iomem *regs)
249296
{
250297
u32 val;
@@ -286,13 +333,13 @@ static void __enable_dcpu(void __iomem *regs)
286333
writel_relaxed(val, regs + REG_DCPU_RESET);
287334
}
288335

289-
static unsigned int get_msg_chksum(const u32 msg[])
336+
static unsigned int get_msg_chksum(const u32 msg[], unsigned int max)
290337
{
291338
unsigned int sum = 0;
292339
unsigned int i;
293340

294341
/* Don't include the last field in the checksum. */
295-
for (i = 0; i < MSG_FIELD_MAX - 1; i++)
342+
for (i = 0; i < max; i++)
296343
sum += msg[i];
297344

298345
return sum;
@@ -305,6 +352,11 @@ static void __iomem *get_msg_ptr(struct private_data *priv, u32 response,
305352
unsigned int offset;
306353
void __iomem *ptr = NULL;
307354

355+
/* There is no need to use this function for API v3 or later. */
356+
if (unlikely(priv->dpfe_api->version >= 3)) {
357+
return NULL;
358+
}
359+
308360
msg_type = (response >> DRAM_MSG_TYPE_OFFSET) & DRAM_MSG_TYPE_MASK;
309361
offset = (response >> DRAM_MSG_ADDR_OFFSET) & DRAM_MSG_ADDR_MASK;
310362

@@ -332,12 +384,25 @@ static void __iomem *get_msg_ptr(struct private_data *priv, u32 response,
332384
return ptr;
333385
}
334386

387+
static void __finalize_command(struct private_data *priv)
388+
{
389+
unsigned int release_mbox;
390+
391+
/*
392+
* It depends on the API version which MBOX register we have to write to
393+
* to signal we are done.
394+
*/
395+
release_mbox = (priv->dpfe_api->version < 3)
396+
? REG_TO_HOST_MBOX : REG_TO_DCPU_MBOX;
397+
writel_relaxed(0, priv->regs + release_mbox);
398+
}
399+
335400
static int __send_command(struct private_data *priv, unsigned int cmd,
336401
u32 result[])
337402
{
338403
const u32 *msg = priv->dpfe_api->command[cmd];
339404
void __iomem *regs = priv->regs;
340-
unsigned int i, chksum;
405+
unsigned int i, chksum, chksum_idx;
341406
int ret = 0;
342407
u32 resp;
343408

@@ -381,19 +446,20 @@ static int __send_command(struct private_data *priv, unsigned int cmd,
381446
/* Read response data */
382447
for (i = 0; i < MSG_FIELD_MAX; i++)
383448
result[i] = readl_relaxed(regs + DCPU_MSG_RAM(i));
449+
chksum_idx = result[MSG_ARG_COUNT] + MSG_ARG_COUNT + 1;
384450
}
385451

386452
/* Tell DCPU we are done */
387-
writel_relaxed(0, regs + REG_TO_HOST_MBOX);
453+
__finalize_command(priv);
388454

389455
mutex_unlock(&priv->lock);
390456

391457
if (ret)
392458
return ret;
393459

394460
/* Verify response */
395-
chksum = get_msg_chksum(result);
396-
if (chksum != result[MSG_CHKSUM])
461+
chksum = get_msg_chksum(result, chksum_idx);
462+
if (chksum != result[chksum_idx])
397463
resp = DCPU_RET_ERR_CHKSUM;
398464

399465
if (resp != DCPU_RET_SUCCESS) {
@@ -710,6 +776,30 @@ static ssize_t show_vendor(struct device *dev, struct device_attribute *devattr,
710776
return sprintf(buf, "%#x %#x %#x %#x %#x\n", mr5, mr6, mr7, mr8, err);
711777
}
712778

779+
static ssize_t show_dram(struct device *dev, struct device_attribute *devattr,
780+
char *buf)
781+
{
782+
u32 response[MSG_FIELD_MAX];
783+
struct private_data *priv;
784+
ssize_t ret;
785+
u32 mr4, mr5, mr6, mr7, mr8, err;
786+
787+
priv = dev_get_drvdata(dev);
788+
ret = generic_show(DPFE_CMD_GET_REFRESH, response, priv, buf);
789+
if (ret)
790+
return ret;
791+
792+
mr4 = response[MSG_ARG0 + 0] & DRAM_INFO_MR4_MASK;
793+
mr5 = response[MSG_ARG0 + 1] & DRAM_DDR_INFO_MASK;
794+
mr6 = response[MSG_ARG0 + 2] & DRAM_DDR_INFO_MASK;
795+
mr7 = response[MSG_ARG0 + 3] & DRAM_DDR_INFO_MASK;
796+
mr8 = response[MSG_ARG0 + 4] & DRAM_DDR_INFO_MASK;
797+
err = response[MSG_ARG0 + 5] & DRAM_DDR_INFO_MASK;
798+
799+
return sprintf(buf, "%#x %#x %#x %#x %#x %#x\n", mr4, mr5, mr6, mr7,
800+
mr8, err);
801+
}
802+
713803
static int brcmstb_dpfe_resume(struct platform_device *pdev)
714804
{
715805
struct init_data init;
@@ -787,7 +877,13 @@ static int brcmstb_dpfe_remove(struct platform_device *pdev)
787877
}
788878

789879
static const struct of_device_id brcmstb_dpfe_of_match[] = {
790-
{ .compatible = "brcm,dpfe-cpu", .data = &dpfe_api_v2 },
880+
/* Use legacy API v2 for a select number of chips */
881+
{ .compatible = "brcm,bcm7268-dpfe-cpu", .data = &dpfe_api_v2 },
882+
{ .compatible = "brcm,bcm7271-dpfe-cpu", .data = &dpfe_api_v2 },
883+
{ .compatible = "brcm,bcm7278-dpfe-cpu", .data = &dpfe_api_v2 },
884+
{ .compatible = "brcm,bcm7211-dpfe-cpu", .data = &dpfe_api_v2 },
885+
/* API v3 is the default going forward */
886+
{ .compatible = "brcm,dpfe-cpu", .data = &dpfe_api_v3 },
791887
{}
792888
};
793889
MODULE_DEVICE_TABLE(of, brcmstb_dpfe_of_match);

0 commit comments

Comments
 (0)