mfd:Add SUNIX mfd & PCIe driver
PATCH 1/1 mfd:Add SUNIX mfd & PCIe driver
From: Morris Ku <[email protected]>
Add SUNIX mfd & PCIe driver
--- sdc_mfd.c | 513 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sdc_mfd.h | 61 +++++++ sdc_pci.c | 92 ++++++++++ 3 files changed, 666 insertions(+) create mode 100644 sdc_mfd.c create mode 100644 sdc_mfd.h create mode 100644 sdc_pci.c
driver/mfd/sdc_mfd.c new file +513 -0
@@ -0,0 +1,513 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SUNIX SDC mfd driver. +* +* Copyright (C) 2021, SUNIX Co., Ltd. +* +* Based on Intel Sunrisepoint LPSS core driver written by +* - Andy Shevchenko <[email protected]> +* - Mika Westerberg <[email protected]> +* - Heikki Krogerus <[email protected]> +* - Jarkko Nikula <[email protected]> +* Copyright (C) 2015, Intel Corporation +*/ + +#include <linux/module.h> +#include <linux/pm_runtime.h> +#include <linux/pci.h> +#include <linux/property.h> +#include <linux/debugfs.h> +#include <linux/idr.h> +#include <linux/mfd/core.h> +#include "sdc_mfd.h" + +struct cib_config { +unsigned int mem_offset; +unsigned int mem_size; +unsigned char ic_brand; +unsigned char ic_model; +}; + +struct cib_uart { +unsigned int io_offset; +unsigned char io_size; +unsigned int mem_offset; +unsigned int mem_size; +unsigned short tx_fifo_size; +unsigned short rx_fifo_size; +unsigned int significand; +unsigned char exponent; +unsigned char rs232_cap; +unsigned char rs422_cap; +unsigned char rs485_cap; +unsigned char ahdc_cap; +unsigned char cs_cap; +unsigned char rs422_end_cap; +unsigned char rs485_end_cap; +}; + +struct cib_info { +unsigned char number; +unsigned char type; +unsigned char version; +unsigned char total_length; +unsigned char resource_cap; +unsigned char event_type; + +struct cib_config *config; +struct cib_uart *uart; +}; + +struct sdc_channel { +struct cib_info info; + +struct property_entry *property; +struct resource *resource; +struct mfd_cell *cell; +}; + +struct sdc_mfd { +struct sdc_platform_info info; + +unsigned char major_version; +unsigned char minor_version; +unsigned char available_chls; +unsigned char total_length; +char model_name[18 ]; + +struct sdc_channel *channels; + +struct device *dev; +int devid; + +struct dentry *debugfs; +struct debugfs_blob_wrapper debugfs_blob_model_name; +}; + +static DEFINE_IDA (sdc_devid_ida); +static struct dentry *sdc_mfd_debugfs; +static int sdc_serial_id =1 ; + +static void sdc_get_config_info (struct cib_info *info,void __iomem *membase, +unsigned short ptr) +{ +unsigned int temp; +unsigned int offsetDW =0 ; + +if (!info || !info->config) +return ; + + offsetDW =2 ; + info->config->mem_offset =readl (membase + ptr + (offsetDW *4 )); + offsetDW =3 ; + info->config->mem_size =readl (membase + ptr + (offsetDW *4 )); + offsetDW =4 ; + temp =readl (membase + ptr + (offsetDW *4 )); + info->config->ic_brand = (unsigned char )((temp &0x0000ff00 ) >>8 ); + info->config->ic_model = (unsigned char )((temp &0x00ff0000 ) >>16 ); +} + +static void sdc_get_uart_info (struct cib_info *info,void __iomem *membase, +unsigned short ptr) +{ +unsigned int temp; +unsigned int offsetDW =0 ; + +if (!info || !info->uart) +return ; + + offsetDW =2 ; + temp =readl (membase + ptr + (offsetDW *4 )); + info->uart->io_offset = (unsigned int )((temp &0x00ffffff )); + info->uart->io_size = (unsigned char )((temp &0xff000000 ) >>24 ); + offsetDW =3 ; + info->uart->mem_offset =readl (membase + ptr + (offsetDW *4 )); + offsetDW =4 ; + info->uart->mem_size =readl (membase + ptr + (offsetDW *4 )); + offsetDW =5 ; + temp =readl (membase + ptr + (offsetDW *4 )); + info->uart->tx_fifo_size = (unsigned short )((temp &0x0000ffff )); + info->uart->rx_fifo_size = (unsigned short )((temp &0xff0000 ) >>16 ); + offsetDW =6 ; + temp =readl (membase + ptr + (offsetDW *4 )); + info->uart->significand = temp &0x00ffffff ; + info->uart->exponent = + (unsigned char )((temp &0xff000000 ) >>24 ); + offsetDW =7 ; + temp =readl (membase + ptr + (offsetDW *4 )); + info->uart->rs232_cap = (temp &0x00000001 ) ?0x01 :0x00 ; + info->uart->rs422_cap = (temp &0x00000002 ) ?0x01 :0x00 ; + info->uart->rs485_cap = (temp &0x00000004 ) ?0x01 :0x00 ; + info->uart->ahdc_cap = (temp &0x00000008 ) ?0x01 :0x00 ; + info->uart->cs_cap = (temp &0x00000010 ) ?0x01 :0x00 ; + info->uart->rs422_end_cap = (temp &0x00000040 ) ?0x01 :0x00 ; + info->uart->rs485_end_cap = (temp &0x00000080 ) ?0x01 :0x00 ; +} + +static int sdc_debugfs_add (struct sdc_mfd *sdc) +{ +struct dentry *root_dir; +struct dentry *chl_dir; +char chl_name[20 ]; +struct sdc_channel *chl =NULL ; +int i; + + root_dir =debugfs_create_dir (dev_name (sdc->dev), sdc_mfd_debugfs); +if (IS_ERR (root_dir)) +return PTR_ERR (root_dir); + +debugfs_create_u32 ("devid" ,0644 , root_dir, &sdc->devid); +debugfs_create_u32 ("bus_number" ,0644 , root_dir, &sdc->info.bus_number); +debugfs_create_u32 ("device_number" ,0644 , root_dir, + &sdc->info.device_number); +debugfs_create_u32 ("irq" ,0644 , root_dir, &sdc->info.irq); +debugfs_create_u8 ("major_version" ,0644 , root_dir, &sdc->major_version); +debugfs_create_u8 ("minor_version" ,0644 , root_dir, + &sdc->minor_version); +debugfs_create_u8 ("available_chls" ,0644 , root_dir, + &sdc->available_chls); + sdc->debugfs_blob_model_name.data = sdc->model_name; + sdc->debugfs_blob_model_name.size =strlen (sdc->model_name) +1 ; +debugfs_create_blob ("model_name" ,0644 , root_dir, + &sdc->debugfs_blob_model_name); + +for (i =0 ; i < sdc->available_chls; i++) { + chl = &sdc->channels[i]; +memset (chl_name,0 ,sizeof (char ) *20 ); +sprintf (chl_name,"chl%d" , i); + chl_dir =debugfs_create_dir (chl_name, root_dir); + +if (!chl_dir) { +dev_warn (sdc->dev,"create chl %d debugfs fail\n" , i); +continue ; + } +debugfs_create_x8 ("number" ,0644 , chl_dir, &chl->info.number); +debugfs_create_x8 ("type" ,0644 , chl_dir, &chl->info.type); +debugfs_create_x8 ("version" ,0644 , chl_dir, &chl->info.version); +debugfs_create_x8 ("total_length" ,0644 , chl_dir, + &chl->info.total_length); +debugfs_create_x8 ("resource_cap" ,0644 , chl_dir, + &chl->info.resource_cap); +debugfs_create_x8 ("event_type" ,0644 , chl_dir, + &chl->info.event_type); + +switch (chl->info.type) { +case 0x00 : +if (!chl->info.config) +break ; +debugfs_create_x32 ("mem_offset" ,0644 , chl_dir, + &chl->info.config->mem_offset); +debugfs_create_x32 ("mem_size" ,0644 , chl_dir, + &chl->info.config->mem_size); +debugfs_create_x8 ("ic_brand" ,0644 , chl_dir, + &chl->info.config->ic_brand); +debugfs_create_x8 ("ic_model" ,0644 , chl_dir, + &chl->info.config->ic_model); +break ; + +case 0x01 : +if (!chl->info.uart) +break ; +debugfs_create_x32 ("io_offset" ,0644 , chl_dir, + &chl->info.uart->io_offset); +debugfs_create_x8 ("io_size" ,0644 , chl_dir, + &chl->info.uart->io_size); +debugfs_create_x32 ("mem_offset" ,0644 , chl_dir, + &chl->info.uart->mem_offset); +debugfs_create_x32 ("mem_size" ,0644 , chl_dir, + &chl->info.uart->mem_size); +debugfs_create_x16 ("tx_fifo_size" ,0644 , chl_dir, + &chl->info.uart->tx_fifo_size); +debugfs_create_x16 ("rx_fifo_size" ,0644 , chl_dir, + &chl->info.uart->rx_fifo_size); +debugfs_create_x32 ("significand" ,0644 , chl_dir, + &chl->info.uart->significand); +debugfs_create_x8 ("exponent" ,0644 , chl_dir, + &chl->info.uart->exponent); +debugfs_create_x8 ("rs232_cap" ,0644 , chl_dir, + &chl->info.uart->rs232_cap); +debugfs_create_x8 ("rs422_cap" ,0644 , chl_dir, + &chl->info.uart->rs422_cap); +debugfs_create_x8 ("rs485_cap" ,0644 , chl_dir, + &chl->info.uart->rs485_cap); +debugfs_create_x8 ("ahdc_cap" ,0644 , chl_dir, + &chl->info.uart->ahdc_cap); +debugfs_create_x8 ("cs_cap" ,0644 , chl_dir, + &chl->info.uart->cs_cap); +debugfs_create_x8 ("rs422_end_cap" ,0644 , chl_dir, + &chl->info.uart->rs422_end_cap); +debugfs_create_x8 ("rs485_end_cap" ,0644 , chl_dir, + &chl->info.uart->rs485_end_cap); +break ; + } + } + + sdc->debugfs = root_dir; +return 0 ; +} + +static void sdc_debugfs_remove (struct sdc_mfd *sdc) +{ +debugfs_remove_recursive (sdc->debugfs); +} + +int sdc_probe (struct device *dev,struct sdc_platform_info *info) +{ +int ret; +int i; +int j; +int prop_index; +struct sdc_mfd *sdc =NULL ; +unsigned int temp; +struct sdc_channel *chl =NULL ; +unsigned short next_cib_ptr =0 ; +unsigned short next_cib_ptr_backup =0 ; +unsigned long bar1_io; +void __iomem *bar2_mem; +unsigned long bar2_length; + +if (!info || !info->pdev || info->irq <=0 ) +return -EINVAL ; + + sdc =devm_kzalloc (dev,sizeof (*sdc),GFP_KERNEL ); +if (!sdc) +return -ENOMEM ; + + sdc->info.pdev = info->pdev; + sdc->info.bus_number = info->bus_number; + sdc->info.device_number = info->device_number; + sdc->info.irq = info->irq; + + bar1_io =pci_resource_start (info->pdev,1 ); + + bar2_length =pci_resource_len (info->pdev,2 ); + bar2_mem =devm_ioremap (dev,pci_resource_start (info->pdev,2 ), + bar2_length); +if (!bar2_mem) +return -ENOMEM ; + + temp =readl (bar2_mem); + sdc->major_version = (unsigned char )((temp &0x000000ff )); + sdc->minor_version = (unsigned char )((temp &0x0000ff00 ) >>8 ); + sdc->available_chls = (unsigned char )((temp &0x00ff0000 ) >>16 ); + sdc->total_length = (unsigned char )((temp &0xff000000 ) >>24 ); + + temp =readl (bar2_mem +4 ); + next_cib_ptr = next_cib_ptr_backup = + (unsigned short )((temp &0x0000ffff )); + + j =0 ; +for (i =0 ; i <4 ; i++) { + temp =readl (bar2_mem +8 + (i *4 )); + sdc->model_name[j++] = (char )((temp &0x000000ff )); + sdc->model_name[j++] = (char )((temp &0x0000ff00 ) >>8 ); + sdc->model_name[j++] = (char )((temp &0x00ff0000 ) >>16 ); + sdc->model_name[j++] = (char )((temp &0xff000000 ) >>24 ); + } + sdc->model_name[strlen (sdc->model_name)] =0x0a ; + + sdc->channels =devm_kzalloc (dev,sizeof (struct sdc_channel ) * + sdc->available_chls,GFP_KERNEL ); +if (!sdc->channels) +return -ENOMEM ; + +for (i =0 ; i < sdc->available_chls; i++) { + chl = &sdc->channels[i]; + + next_cib_ptr_backup = next_cib_ptr; + + temp =readl (bar2_mem + next_cib_ptr); + chl->info.number = (unsigned char )((temp &0x000000ff )); + chl->info.type = (unsigned char )((temp &0x0000ff00 ) >>8 ); + chl->info.version = (unsigned char )((temp &0x00ff0000 ) >>16 ); + chl->info.total_length = + (unsigned char )((temp &0xff000000 ) >>24 ); + + temp =readl (bar2_mem + next_cib_ptr +4 ); + next_cib_ptr = temp &0x0000ffff ; + chl->info.resource_cap = + (unsigned char )((temp &0x00ff0000 ) >>16 ); + chl->info.event_type = + (unsigned char )((temp &0xff000000 ) >>24 ); + +switch (chl->info.type) { +case 0x00 : + chl->info.config =devm_kzalloc (dev, +sizeof (struct cib_config ),GFP_KERNEL ); +if (!chl->info.config) +return -ENOMEM ; +sdc_get_config_info (&chl->info, bar2_mem, + next_cib_ptr_backup); +break ; + +case 0x01 : + chl->info.uart =devm_kzalloc (dev, +sizeof (struct cib_uart ),GFP_KERNEL ); +if (!chl->info.uart) +return -ENOMEM ; +sdc_get_uart_info (&chl->info, bar2_mem, + next_cib_ptr_backup); + + chl->property =devm_kzalloc (dev, +sizeof (struct property_entry ) *18 ,GFP_KERNEL ); +if (!chl->property) +return -ENOMEM ; + prop_index =0 ; + chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"bus_number" , sdc->info.bus_number); + chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"device_number" , sdc->info.device_number); + chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"irq" , sdc->info.irq); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"number" , chl->info.number); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"version" , chl->info.version); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"resource_cap" , chl->info.resource_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"event_type" , chl->info.event_type); + chl->property[prop_index++] =PROPERTY_ENTRY_U16 ( +"tx_fifo_size" , chl->info.uart->tx_fifo_size); + chl->property[prop_index++] =PROPERTY_ENTRY_U16 ( +"rx_fifo_size" , chl->info.uart->rx_fifo_size); + chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"significand" , chl->info.uart->significand); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"exponent" , chl->info.uart->exponent); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs232_cap" , chl->info.uart->rs232_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs422_cap" , chl->info.uart->rs422_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs485_cap" , chl->info.uart->rs485_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"ahdc_cap" , chl->info.uart->ahdc_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"cs_cap" , chl->info.uart->cs_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs422_end_cap" , chl->info.uart->rs422_end_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs485_end_cap" , chl->info.uart->rs485_end_cap); + + chl->resource =devm_kzalloc (dev, +sizeof (struct resource ) *2 ,GFP_KERNEL ); +if (!chl->resource) +return -ENOMEM ; + chl->resource[0 ].start = + bar1_io + chl->info.uart->io_offset; + chl->resource[0 ].end = + bar1_io + chl->info.uart->io_offset + + chl->info.uart->io_size -1 ; + chl->resource[0 ].name ="iobase" ; + chl->resource[0 ].flags =IORESOURCE_IO ; + chl->resource[0 ].desc =IORES_DESC_NONE ; + chl->resource[1 ].start =0 ; + chl->resource[1 ].end =0 ; + chl->resource[1 ].name ="irq" ; + chl->resource[1 ].flags =IORESOURCE_IRQ ; + chl->resource[1 ].desc =IORES_DESC_NONE ; + + chl->cell =devm_kzalloc (dev, +sizeof (struct mfd_cell ),GFP_KERNEL ); +if (!chl->cell) +return -ENOMEM ; + chl->cell->name ="8250_sdc" ; + chl->cell->id = sdc_serial_id++; + chl->cell->properties = chl->property; + chl->cell->num_resources =2 ; + chl->cell->resources = chl->resource; +break ; + } + } + + sdc->dev = dev; +dev_set_drvdata (dev, sdc); + + ret =ida_simple_get (&sdc_devid_ida,0 ,0 ,GFP_KERNEL ); +if (ret <0 ) +return ret; + sdc->devid = ret; + + ret =sdc_debugfs_add (sdc); +if (ret) +dev_warn (dev,"failed to create debugfs entries\n" ); + +for (i =0 ; i < sdc->available_chls; i++) { + chl = &sdc->channels[i]; + +if (chl->cell) { + ret =mfd_add_devices (dev, sdc->devid, chl->cell,1 , +NULL , sdc->info.irq,NULL ); +if (ret) + goto err_remove_sdc; + } + } + +dev_pm_set_driver_flags (dev,DPM_FLAG_SMART_SUSPEND ); +return 0 ; + +err_remove_sdc: +sdc_debugfs_remove (sdc); +ida_simple_remove (&sdc_devid_ida, sdc->devid); +return ret; +} +EXPORT_SYMBOL_GPL (sdc_probe); + +void sdc_remove (struct device *dev) +{ +struct sdc_mfd *sdc =dev_get_drvdata (dev); + +mfd_remove_devices (dev); +sdc_debugfs_remove (sdc); +ida_simple_remove (&sdc_devid_ida, sdc->devid); +} +EXPORT_SYMBOL_GPL (sdc_remove); + +static int resume_sdc_device (struct device *dev,void *data) +{ +if (!dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND )) +pm_runtime_resume (dev); + +return 0 ; +} + +int sdc_prepare (struct device *dev) +{ +device_for_each_child_reverse (dev,NULL , resume_sdc_device); +return 0 ; +} +EXPORT_SYMBOL_GPL (sdc_prepare); + +int sdc_suspend (struct device *dev) +{ +// save context +return 0 ; +} +EXPORT_SYMBOL_GPL (sdc_suspend); + +int sdc_resume (struct device *dev) +{ +// restore context +return 0 ; +} +EXPORT_SYMBOL_GPL (sdc_resume); + +static int __init sdc_init (void ) +{ + sdc_mfd_debugfs =debugfs_create_dir ("sdc_mfd" ,NULL ); +return 0 ; +} +module_init (sdc_init); + +static void __exit sdc_exit(void) +{ +ida_destroy (&sdc_devid_ida); +debugfs_remove (sdc_mfd_debugfs); +} +module_exit (sdc_exit); + +MODULE_AUTHOR ("Jason Lee <[email protected]>" ); +MODULE_DESCRIPTION ("SUNIX SDC mfd driver" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_SOFTDEP ("pre: 8250_sdc" );
sdc_mfd.h new file +61 -0
61 lines not on this page · raw message
sdc_pci.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 2 lines · Moriis Ku
From: Morris Ku <[email protected]>
Not sure why we have it here.
Quoted 1 line
Add SUNIX mfd & PCIe driver
Needs a bit more information.
Quoted 1 line
Signed-off-by Morris Ku <[email protected]>
...
Quoted 1 line
+ * Based on Intel Sunrisepoint LPSS core driver written by
Looking into the code I'm not sure how it's based on that.
Quoted 5 lines
+ * - Andy Shevchenko <[email protected]>
+ * - Mika Westerberg <[email protected]>
+ * - Heikki Krogerus <[email protected]>
+ * - Jarkko Nikula <[email protected]>
+ * Copyright (C) 2015, Intel Corporation
...
driver/mfd/sdc_mfd.c line 26
Quoted 3 lines
driver/mfd/sdc_mfd.c new file +3
-0+struct cib_config { +unsigned int mem_offset; +unsigned int mem_size;
The above is probably better when they are type of resource_size_t. If it's something that goes directly to the hardware or from it, use fixed-width types.
driver/mfd/sdc_mfd.c line 28
Quoted 2 lines
driver/mfd/sdc_mfd.c new file +2
-0+unsigned char ic_brand; +unsigned char ic_model;
u8 ?
Quoted 9 lines
driver/mfd/sdc_mfd.c new file +9
-0+}; + +struct cib_uart { +unsigned int io_offset; +unsigned char io_size; +unsigned int mem_offset; +unsigned int mem_size; +unsigned short tx_fifo_size; +unsigned short rx_fifo_size;
driver/mfd/sdc_mfd.c line 47
Quoted 10 lines
driver/mfd/sdc_mfd.c new file +10
-0+unsigned int significand; +unsigned char exponent; +unsigned char rs232_cap; +unsigned char rs422_cap; +unsigned char rs485_cap; +unsigned char ahdc_cap; +unsigned char cs_cap; +unsigned char rs422_end_cap; +unsigned char rs485_end_cap; +};
As per above
driver/mfd/sdc_mfd.c line 59
Quoted 11 lines
driver/mfd/sdc_mfd.c new file +11
-0+struct cib_info { +unsigned char number; +unsigned char type; +unsigned char version; +unsigned char total_length; +unsigned char resource_cap; +unsigned char event_type; + +struct cib_config *config; +struct cib_uart *uart; +};
As per above.
...
Quoted 1 line
+ char model_name[18];
Strange size, but okay.
...
driver/mfd/sdc_mfd.c line 105
Quoted 6 lines
driver/mfd/sdc_mfd.c new file +6
-0+ offsetDW =2 ; + info->config->mem_offset =readl (membase + ptr + (offsetDW *4 )); + offsetDW =3 ; + info->config->mem_size =readl (membase + ptr + (offsetDW *4 )); + offsetDW =4 ; + temp =readl (membase + ptr + (offsetDW *4 ));
You will benefit if you create the IO accessor helper functions, these become like
a = my_ioread(base, ptr, offset);
b = ...
...
driver/mfd/sdc_mfd.c line 107
Quoted 2 lines
driver/mfd/sdc_mfd.c new file +2
-0+ info->config->ic_brand = (unsigned char )((temp &0x0000ff00 ) >>8 ); + info->config->ic_model = (unsigned char )((temp &0x00ff0000 ) >>16 );
Use GENMASK().
Castings are not needed.
Quoted 1 line
+}
...
driver/mfd/sdc_mfd.c line 112
Quoted 3 lines
driver/mfd/sdc_mfd.c new file +3
-0+static void sdc_get_uart_info (struct cib_info *info,void __iomem *membase, +unsigned short ptr) +{
Same as above.
driver/mfd/sdc_mfd.c line 144
Quoted 7 lines
driver/mfd/sdc_mfd.c new file +7
-0+ info->uart->rs232_cap = (temp &0x00000001 ) ?0x01 :0x00 ; + info->uart->rs422_cap = (temp &0x00000002 ) ?0x01 :0x00 ; + info->uart->rs485_cap = (temp &0x00000004 ) ?0x01 :0x00 ; + info->uart->ahdc_cap = (temp &0x00000008 ) ?0x01 :0x00 ; + info->uart->cs_cap = (temp &0x00000010 ) ?0x01 :0x00 ; + info->uart->rs422_end_cap = (temp &0x00000040 ) ?0x01 :0x00 ; + info->uart->rs485_end_cap = (temp &0x00000080 ) ?0x01 :0x00 ;
It seems you are using char type for boolean variables. Also consider BIT() to be in use.
Quoted 1 line
+}
...
driver/mfd/sdc_mfd.c line 157
Quoted 4 lines
driver/mfd/sdc_mfd.c new file +3
-0+ root_dir =debugfs_create_dir (dev_name (sdc->dev), sdc_mfd_debugfs); +if (IS_ERR (root_dir)) +return PTR_ERR (root_dir);
Nope, we don't check for error codes for debugfs.
...
driver/mfd/sdc_mfd.c line 168
Quoted 7 lines
driver/mfd/sdc_mfd.c new file +6
-0+debugfs_create_u32 ("device_number" ,0644 , root_dir, + &sdc->info.device_number); +debugfs_create_u8 ("minor_version" ,0644 , root_dir, + &sdc->minor_version); +debugfs_create_u8 ("available_chls" ,0644 , root_dir, + &sdc->available_chls);
Above can sit on a single line each.
...
driver/mfd/sdc_mfd.c line 176
Quoted 4 lines
driver/mfd/sdc_mfd.c new file +3
-0+for (i =0 ; i < sdc->available_chls; i++) { + chl = &sdc->channels[i]; +memset (chl_name,0 ,sizeof (char ) *20 );
Why?
driver/mfd/sdc_mfd.c line 179
Quoted 3 lines
driver/mfd/sdc_mfd.c new file +3
-0+sprintf (chl_name,"chl%d" , i); + chl_dir =debugfs_create_dir (chl_name, root_dir); +
Redundant empty line.
driver/mfd/sdc_mfd.c line 181
Quoted 3 lines
driver/mfd/sdc_mfd.c new file +2
-0+if (!chl_dir) { +dev_warn (sdc->dev,"create chl %d debugfs fail\n" , i);
Message with no value.
Quoted 2 lines
(quoted diff) +2
-0+ continue; + }
...
Quoted 1 line
+ switch (
chl->info.type) {
The default case is missing.
Quoted 2 lines
(quoted diff) +2
-0+ } + }
...
Quoted 1 line
+
sdc->debugfs=root_dir;
Do we really need this? Debufs API can lookup for the folders with predefined names.
...
driver/mfd/sdc_mfd.c line 267
Quoted 12 lines
driver/mfd/sdc_mfd.c new file +12
-0+int ret; +int i; +int j; +int prop_index; +struct sdc_mfd *sdc =NULL ; +unsigned int temp; +struct sdc_channel *chl =NULL ; +unsigned short next_cib_ptr =0 ; +unsigned short next_cib_ptr_backup =0 ; +unsigned long bar1_io; +void __iomem *bar2_mem; +unsigned long bar2_length;
Reverse xmas tree order, please.
...
driver/mfd/sdc_mfd.c line 287
Quoted 5 lines
driver/mfd/sdc_mfd.c new file +5
-0+ bar2_length =pci_resource_len (info->pdev,2 ); + bar2_mem =devm_ioremap (dev,pci_resource_start (info->pdev,2 ), + bar2_length); +if (!bar2_mem) +return -ENOMEM ;
Why can't you use pcim_iomap_regions()?
...
driver/mfd/sdc_mfd.c line 297
Quoted 7 lines
driver/mfd/sdc_mfd.c new file +6
-0+ sdc->major_version = (unsigned char )((temp &0x000000ff )); + sdc->minor_version = (unsigned char )((temp &0x0000ff00 ) >>8 ); + sdc->available_chls = (unsigned char )((temp &0x00ff0000 ) >>16 ); + sdc->total_length = (unsigned char )((temp &0xff000000 ) >>24 ); + next_cib_ptr = next_cib_ptr_backup = + (unsigned short )((temp &0x0000ffff ));
GENMASK(), no castings.
Same for other similar places.
...
Quoted 1 line
+ sdc->model_name[strlen(sdc->model_name)] =
0x0a;
Use '\n'
...
driver/mfd/sdc_mfd.c line 310
Quoted 2 lines
driver/mfd/sdc_mfd.c new file +2
-0+ sdc->channels =devm_kzalloc (dev,sizeof (struct sdc_channel ) * + sdc->available_chls,GFP_KERNEL );
devm_kcalloc()
Quoted 2 lines
(quoted diff) +2
-0+ if (!sdc->channels) + return -ENOMEM;
...
driver/mfd/sdc_mfd.c line 336
Quoted 2 lines
driver/mfd/sdc_mfd.c new file +2
-0+ chl->info.config =devm_kzalloc (dev, +sizeof (struct cib_config ),GFP_KERNEL );
Safer pattern is sizeof(*chl->info.config).
Quoted 2 lines
(quoted diff) +2
-0+ if (!chl->info.config) + return -ENOMEM;
...
driver/mfd/sdc_mfd.c line 352
Quoted 2 lines
driver/mfd/sdc_mfd.c new file +2
-0+ chl->property =devm_kzalloc (dev, +sizeof (struct property_entry ) *18 ,GFP_KERNEL );
devm_kcalloc()
Quoted 2 lines
(quoted diff) +2
-0+ if (!chl->property) + return -ENOMEM;
...
Quoted 26 lines
driver/mfd/sdc_mfd.c new file +26
-0+ chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"bus_number" , sdc->info.bus_number); + chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"device_number" , sdc->info.device_number); + chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"irq" , sdc->info.irq); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"number" , chl->info.number); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"version" , chl->info.version); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"resource_cap" , chl->info.resource_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"event_type" , chl->info.event_type); + chl->property[prop_index++] =PROPERTY_ENTRY_U16 ( +"tx_fifo_size" , chl->info.uart->tx_fifo_size); + chl->property[prop_index++] =PROPERTY_ENTRY_U16 ( +"rx_fifo_size" , chl->info.uart->rx_fifo_size); + chl->property[prop_index++] =PROPERTY_ENTRY_U32 ( +"significand" , chl->info.uart->significand); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"exponent" , chl->info.uart->exponent); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs232_cap" , chl->info.uart->rs232_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs422_cap" , chl->info.uart->rs422_cap);
driver/mfd/sdc_mfd.c line 391
Quoted 10 lines
driver/mfd/sdc_mfd.c new file +10
-0+ chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs485_cap" , chl->info.uart->rs485_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"ahdc_cap" , chl->info.uart->ahdc_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"cs_cap" , chl->info.uart->cs_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs422_end_cap" , chl->info.uart->rs422_end_cap); + chl->property[prop_index++] =PROPERTY_ENTRY_U8 ( +"rs485_end_cap" , chl->info.uart->rs485_end_cap);
I'm not sure what's going on here. Can you add documentation somewhere to explain all these?
...
driver/mfd/sdc_mfd.c line 505
Quoted 4 lines
driver/mfd/sdc_mfd.c new file +3
-0+static void __exit sdc_exit(void) +{ +ida_destroy (&sdc_devid_ida);
If you do it on non-freeid IDA it means you have a bug in resource management (leakage) somewhere. I guess it was mistakenly used by the drivers.
Quoted 3 lines
driver/mfd/sdc_mfd.c new file +3
-0+debugfs_remove (sdc_mfd_debugfs); +} +module_exit (sdc_exit);
...
sdc_pci.c line 30
Quoted 7 lines
sdc_pci.c new file +5
-0+static int sdc_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ + flags =pci_resource_flags (pdev,0 ); +if (!(flags &IORESOURCE_MEM )) { +pr_err ("bar0 resource flag x%lx invalid\n" , flags);
So what? Besides the fact that dev_err() should be used.
Quoted 4 lines
sdc_pci.c new file +4
-0+return -ENODEV ; + } + + flags =pci_resource_flags (pdev,1 );
sdc_pci.c line 44
Quoted 10 lines
sdc_pci.c new file +10
-0+if (!(flags &IORESOURCE_IO )) { +pr_err ("bar1 resource flag x%lx invalid\n" , flags); +return -ENODEV ; + } + + flags =pci_resource_flags (pdev,2 ); +if (!(flags &IORESOURCE_MEM )) { +pr_err ("bar2 resource flag x%lx invalid\n" , flags); +return -ENODEV ; + }
All above checks seem redundant.
Quoted 3 lines
sdc_pci.c new file +3
-0+ ret =sdc_probe (&pdev->dev, &info); +if (ret) +return ret;
...
sdc_pci.c line 74
Quoted 4 lines
sdc_pci.c new file +3
-0+static const struct pci_device_id sdc_pci_ids[] = { + {PCI_VDEVICE (SUNIX ,0x2000 ) }, + { },
Comma is not needed for terminator lines.
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Moriis Ku
From: Morris Ku <[email protected]>
Add SUNIX mfd & PCIe driver
Cc Jason Lee <[email protected]>Cc Taian Chen <[email protected]>Signed-off-by Morris Ku <[email protected]>--- sdc_mfd.c | 513 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
To be frank, this is a bit of a mess.
Let's take one step back for a moment.
Please tell me how this compares to any existing driver currently present in drivers/mfd. I'm 100% sure this H/W is not different to anything we've seen before. Thus, my advice is to base it off of a piece of code that has been previously accepted and take it from there.
Quoted 6 lines
sdc_mfd.h | 61 +++++++ sdc_pci.c | 92 ++++++++++ 3 files changed, 666 insertions(+) create mode 100644 sdc_mfd.c create mode 100644 sdc_mfd.h create mode 100644 sdc_pci.c
Signature · 4 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog